- add: login via token
- update: login request packet uses token login instead of user & pass
This commit is contained in:
@@ -40,19 +40,27 @@ pub(crate) async fn handle_login_req(stream: &mut TcpStream, packet: Packet, aut
|
||||
debug!("{:?}", data);
|
||||
|
||||
let mut auth_client = auth_client.lock().await;
|
||||
match auth_client.login(&data.username.0, &data.password.password).await {
|
||||
match auth_client.login_token(&data.token.0).await {
|
||||
Ok(response) => {
|
||||
debug!("successfully logged in");
|
||||
let data = SrvLoginReply { result: srv_login_reply::Result::Ok, right: 0, type_: 0, servers_info: Vec::new() };
|
||||
let response_packet = Packet::new(PacketType::PaklcLoginReply, &data)?;
|
||||
send_packet(stream, &response_packet).await?;
|
||||
if response.valid == false {
|
||||
info!("Login failed: Invalid credentials");
|
||||
|
||||
let data = SrvLoginReply { result: srv_login_reply::Result::UnknownAccount, right: 0, type_: 0, servers_info: Vec::new() };
|
||||
let response_packet = Packet::new(PacketType::PaklcLoginReply, &data)?;
|
||||
send_packet(stream, &response_packet).await?;
|
||||
} else {
|
||||
debug!("Successfully logged in");
|
||||
let data = SrvLoginReply { result: srv_login_reply::Result::Ok, right: 0, type_: 0, servers_info: Vec::new() };
|
||||
let response_packet = Packet::new(PacketType::PaklcLoginReply, &data)?;
|
||||
send_packet(stream, &response_packet).await?;
|
||||
}
|
||||
}
|
||||
Err(status) => {
|
||||
if let Some(tonic_status) = status.downcast_ref::<Status>() {
|
||||
match tonic_status.code() {
|
||||
Code::Unauthenticated => {
|
||||
info!("Login failed: Invalid credentials");
|
||||
|
||||
|
||||
let data = SrvLoginReply { result: srv_login_reply::Result::UnknownAccount, right: 0, type_: 0, servers_info: Vec::new() };
|
||||
let response_packet = Packet::new(PacketType::PaklcLoginReply, &data)?;
|
||||
send_packet(stream, &response_packet).await?;
|
||||
|
||||
Reference in New Issue
Block a user