-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to login with only a token (#427)
* Add login with token
- Loading branch information
1 parent
58284ae
commit 7e4f73b
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,41 @@ | ||
use std::sync::{Arc, RwLock}; | ||
|
||
pub use login::*; | ||
pub use register::*; | ||
|
||
use crate::{ | ||
errors::ChorusResult, | ||
gateway::Gateway, | ||
instance::{ChorusUser, Instance}, | ||
types::{GatewayIdentifyPayload, User}, | ||
}; | ||
|
||
pub mod login; | ||
pub mod register; | ||
|
||
impl Instance { | ||
/// Logs into an existing account on the spacebar server, using only a token. | ||
pub async fn login_with_token(&mut self, token: String) -> ChorusResult<ChorusUser> { | ||
let object_result = self.get_user(token.clone(), None).await; | ||
if let Err(e) = object_result { | ||
return Result::Err(e); | ||
} | ||
|
||
let user_settings = User::get_settings(&token, &self.urls.api, &mut self.clone()) | ||
.await | ||
.unwrap(); | ||
let mut identify = GatewayIdentifyPayload::common(); | ||
let gateway = Gateway::new(self.urls.wss.clone()).await.unwrap(); | ||
identify.token = token.clone(); | ||
gateway.send_identify(identify).await; | ||
let user = ChorusUser::new( | ||
Arc::new(RwLock::new(self.clone())), | ||
token.clone(), | ||
self.clone_limits_if_some(), | ||
Arc::new(RwLock::new(user_settings)), | ||
Arc::new(RwLock::new(object_result.unwrap())), | ||
gateway, | ||
); | ||
Ok(user) | ||
} | ||
} |