ic_core_module/
core_account_command.rs1use intel_cache_lib::ic_types::ic_execute_mod::IcExecute;
2use intel_cache_lib::ic_types::IcConnection;
3use intel_cache_lib::ic_types::IcPacket;
4use intel_cache_lib::lib_backend::rename_account;
5use intel_cache_lib::lib_backend::change_password;
6use intel_cache_lib::lib_backend::logout;
7use intel_cache_lib::lib_backend::validate_user;
8use intel_cache_lib::ic_types::IcLoginDetails;
9
10pub struct CoreAccount {}
11impl CoreAccount {
12 #[no_mangle]
13 pub fn ca_new() -> CoreAccount {
14 CoreAccount { }
15 }
16
17 #[no_mangle]
18 pub fn ca_to_exe() -> Box<dyn IcExecute<Connection = IcConnection>> {
19 Box::new(CoreAccount::ca_new())
20 }
21}
22
23impl IcExecute for CoreAccount {
24 type Connection = IcConnection;
25
26 fn exec(&mut self,con: &mut Self::Connection,cmd: Option<Vec<String>>,_data: Option<Vec<u8>>,_cached: bool) -> IcPacket {
27 match &cmd {
28 Some(cmd) => {
29 if cmd[cmd.len() - 1..][0] == con.login.as_ref().unwrap_or(&IcLoginDetails {username: "ANONYMOUS".to_string(),id: "NONE".to_string(),cookie: "NONE".to_string()}).cookie {
30 let mut rename = false;
31 let mut chpwd = false;
32 let mut lo = false;
33 let mut validate = false;
34 match cmd[1].as_ref() {
35 "RENAME" => rename = true,
36 "CHPASSWD" => chpwd = true,
37 "LOGOUT" => lo = true,
38 "VALIDATE" => validate = true,
39 _=> return IcPacket::new(Some(cmd[1].clone()),None),
40 };
41 if rename {
42 match rename_account(con,&cmd[2]) {
43 Ok(v) => return IcPacket::new(Some(v),None),
44 Err(_e) => return IcPacket::new(Some("Err.".to_string()),None),
45 };
46 } else if chpwd {
47 match change_password(con,&cmd[2]) {
48 Ok(v) => return IcPacket::new(Some(v),None),
49 Err(_e) => return IcPacket::new(Some("Err.".to_string()),None),
50 };
51 } else if lo {
52 match logout(con) {
53 Ok(v) => return IcPacket::new(Some(v),None),
54 Err(_e) => return IcPacket::new(Some("Err.".to_string()),None),
55 };
56 } else if validate {
57 match validate_user(con,&cmd[cmd.len() - 1..][0]) {
58 Ok(v) => return IcPacket::new(Some(v),None),
59 Err(_e) => return IcPacket::new(Some("Err.".to_string()),None),
60 }
61 } else { return IcPacket::new_empty(); }
62 } else { return IcPacket::new_empty(); }
63 }
64 None => return IcPacket::new_empty(),
65 }
66 }
67
68 fn login_required(&mut self) -> bool {
69 false
70 }
71}