Skip to content

Implement interactive chat mode with user authentication #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

chojuninengu
Copy link
Collaborator

@chojuninengu chojuninengu commented Apr 7, 2025

This PR implements an interactive chat mode with user authentication, addressing issue #1.

Changes include:

  • Added user authentication (register/login)
  • Implemented interactive chat mode
  • Added proper message formatting with usernames
  • Fixed connection handling for authenticated users

To test:

  1. Start the server: cargo run --bin server 127.0.0.1:8080
  2. Join a chat: cargo run --bin client 127.0.0.1:8080 chat -g general -u your_username

@Dericko681
Copy link
Collaborator

@chojuninengu great job but a quick question; Does this code compile locally?
Screenshot from 2025-04-07 13-34-37

tips: resolve all conflicts with the main
Screenshot from 2025-04-07 13-36-44

@chojuninengu
Copy link
Collaborator Author

@Dericko681 , it does compile locally

@Dericko681
Copy link
Collaborator

@chojuninengu Oh great, I just figured out, update the start server command in the description of this PR to cargo run --bin server 127.0.0.1:8080

Dericko681
Dericko681 previously approved these changes Apr 7, 2025
@chojuninengu
Copy link
Collaborator Author

@Dericko681 , thanks for that update
i just did now,

@ndefokou
Copy link
Collaborator

ndefokou commented Apr 7, 2025

Hello @chojuninengu, great work! However, please add the Cargo.lock file to the .gitignore — it shouldn't be committed to the repository.
Also, kindly resolve the merge conflicts on your branch.

@chojuninengu
Copy link
Collaborator Author

@ndefokou , thanks for the remark, i just resolved it

@sinke237
Copy link
Collaborator

sinke237 commented Apr 7, 2025

@chojuninengu just to leave a remark that if the pipeline is failing, you want to fix it before requiring a review.
Secondly, why merge main into your branch. there is a develop branch? this is the root for all feature branches
The main branch will be used to release the stable versions of the code.
Best practices:

  1. Create feature branch from develop
  2. rebase to develop in cases of conflict

@chojuninengu chojuninengu force-pushed the feature/interactive-chat branch from 509db5f to c4a9fdc Compare April 7, 2025 16:25
@chojuninengu chojuninengu force-pushed the feature/interactive-chat branch from c4a9fdc to 8f91f07 Compare April 7, 2025 16:34
@chojuninengu chojuninengu requested a review from Dericko681 April 7, 2025 20:24
@chojuninengu
Copy link
Collaborator Author

@Christiantyemele , please can you see into this issue, cuz this is the only thing that is holding my for now

image

Copy link
Collaborator

@Dericko681 Dericko681 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @chojuninengu you are doing an amazing job here but you can't modify unrelated files .github/workflows/ci.yml in this same PR. There is an open issue #34 which is debating how to fix the issue with failing CI/CD

@chojuninengu chojuninengu requested a review from Dericko681 April 7, 2025 21:28
Comment on lines +35 to +42
Chat {
/// Name of the group to chat in
#[arg(short, long)]
group: String,
/// Username to use
#[arg(short, long)]
username: String,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't understand the function of this field, elaborate. cause from what i try to understand you want creating a join a group to be seperate task that is i create a group with a password then share the password to those i want them to join the group in that case then this your Chat field here is not clear in its naming convenction and the values it holds too. cause i don't see the different between Post and Chat when reading their names

// First register/login the user
let register_command = FromClient::Register {
username: Arc::new(username.clone()),
password: Arc::new("password".to_string()), // TODO: Add proper password handling
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is too big for you to handle plz just create a ticket in other not to forget

Comment on lines +63 to +64
let join_command = FromClient::Join {
group_name: Arc::new(group.clone()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the essence of creating a group with a password if i don't join using that password, unless it's for future implementation ?

Comment on lines +111 to +119
let command = FromClient::Post {
group_name: Arc::new(group.clone()),
message: Arc::new(input.to_string()),
};

utils::send_as_json(&mut socket, &command).await?;
socket.flush().await?;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You see what i was saying here you call Post in Chat but still have a seperate handler for posting so what is the difference in the two ?

}
}

pub async fn register(&self, username: Arc<String>) -> anyhow::Result<User> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't see the use of putting username here in an Arc

Comment on lines +25 to +32
let user = User {
username: username.clone(),
id: Arc::new(Uuid::new_v4().to_string()),
};

users.insert(username.clone(), user.clone());
Ok(user)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seriously, you have a hashmap storing key username and value username, id this does makes sense for the use case, what i mean here is there is a better way of doing this, and i have not even seen where you making use of this id

Comment on lines +34 to +35
pub async fn login(&self, username: Arc<String>) -> anyhow::Result<User> {
let users = self.users.lock().await;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now i understand password verification will be done later

Comment on lines +56 to +60
pub async fn is_active(&self, username: &Arc<String>) -> bool {
let active_users = self.active_users.lock().await;
active_users.contains_key(username)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used and i can figure out where its even gonna be used, why do want to have users and active_users ?

let outbound = Arc::new(Outbound::new(socket.clone()));
let mut connection = Connection::new();
Copy link
Collaborator

@Christiantyemele Christiantyemele Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you doing this like why do want to keep track of the user in this way, mean while the user manager does that already

@Christiantyemele
Copy link
Collaborator

@chojuninengu indicate if you need help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants