Commit 7a78675e authored by Daniel García Moreno's avatar Daniel García Moreno

api: SetToken command

This command is useful to set the token stored in the client and we
don't need to make the login every time

See #138
parent 3451fb9e
......@@ -101,6 +101,10 @@ impl Backend {
let r = register::guest(self, server);
bkerror!(r, tx, BKResponse::GuestLoginError);
}
Ok(BKCommand::SetToken(token, uid, server)) => {
let r = register::set_token(self, token, uid, server);
bkerror!(r, tx, BKResponse::LoginError);
}
// User module
......
......@@ -98,6 +98,17 @@ pub fn login(bk: &Backend, user: String, password: String, server: String) -> Re
Ok(())
}
pub fn set_token(bk: &Backend, token: String, uid: String, server: String) -> Result<(), Error> {
let s = server.clone();
bk.data.lock().unwrap().server_url = s;
bk.data.lock().unwrap().access_token = token.clone();
bk.data.lock().unwrap().user_id = uid.clone();
bk.data.lock().unwrap().since = String::new();
bk.tx.send(BKResponse::Token(uid, token)).unwrap();
Ok(())
}
pub fn logout(bk: &Backend) -> Result<(), Error> {
let url = bk.url("logout", vec![])?;
let attrs = json!({});
......
......@@ -15,6 +15,7 @@ use cache::CacheMap;
#[derive(Debug)]
pub enum BKCommand {
Login(String, String, String),
SetToken(String, String, String),
Logout,
#[allow(dead_code)]
Register(String, String, String),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment