ensure requirements are met when changing password

master
rasul 5 years ago
parent bdf8f86ba5
commit 6e8e99e329

@ -1,5 +1,6 @@
use mio::Token;
use crate::check;
use crate::command::CommandSetPlayer;
use crate::database::Db;
use crate::password::Password;
@ -11,13 +12,17 @@ impl CommandSetPlayer {
pub fn dispatch_password(&self, args: String, token: Token, db: &mut Db) -> SendQueue {
let player = try_option_send_error!(token, db.get_connected_player(token));
if args.is_empty() {
return (token, "Password can't be empty").into();
}
let password = try_send_error!(token, Password::new(args));
match check::player_password(args) {
check::PlayerCheck::Ok(checked_pass) => {
let password = try_send_error!(token, Password::new(checked_pass));
let _ = try_send_error!(token, db.save_password(player.id, &password));
SendQueue::ok(token)
}
check::PlayerCheck::Err(err_vec) => {
let mut s: String = err_vec.join("\n");
s.push_str("\n");
(token, s).into()
}
}
}
}

Loading…
Cancel
Save