refactor
This commit is contained in:
@@ -39,7 +39,7 @@ impl RealmAuthServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen_login_code(&self) -> u16 {
|
fn gen_login_code(&self) -> u16 {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let mut login_code: u16 = 0;
|
let mut login_code: u16 = 0;
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ impl RealmAuthServer {
|
|||||||
login_code
|
login_code
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn is_username_taken(&self, username: &str) -> Result<bool, ErrorCode> {
|
async fn is_username_taken(&self, username: &str) -> Result<bool, ErrorCode> {
|
||||||
let result = query!("SELECT NOT EXISTS (SELECT 1 FROM user WHERE username = ?) AS does_exist", username).fetch_one(&self.db_pool).await;
|
let result = query!("SELECT NOT EXISTS (SELECT 1 FROM user WHERE username = ?) AS does_exist", username).fetch_one(&self.db_pool).await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
@@ -62,7 +62,7 @@ impl RealmAuthServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn is_email_taken(&self, email: &str) -> Result<bool, ErrorCode> {
|
async fn is_email_taken(&self, email: &str) -> Result<bool, ErrorCode> {
|
||||||
let result = query!("SELECT NOT EXISTS (SELECT 1 FROM user WHERE email = ?) AS does_exist", email).fetch_one(&self.db_pool).await;
|
let result = query!("SELECT NOT EXISTS (SELECT 1 FROM user WHERE email = ?) AS does_exist", email).fetch_one(&self.db_pool).await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
@@ -71,7 +71,7 @@ impl RealmAuthServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn is_authorized(&self, username: &str, token: &str) -> Result<bool, ErrorCode> {
|
async fn is_authorized(&self, username: &str, token: &str) -> Result<bool, ErrorCode> {
|
||||||
let result = query!("SELECT tokens FROM user WHERE username = ?", username).fetch_one(&self.db_pool).await;
|
let result = query!("SELECT tokens FROM user WHERE username = ?", username).fetch_one(&self.db_pool).await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
@@ -91,7 +91,7 @@ impl RealmAuthServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_login_message(&self, username: &str, email: &str, login_code: u16) -> Result<(), ErrorCode> {
|
async fn send_login_message(&self, username: &str, email: &str, login_code: u16) -> Result<(), ErrorCode> {
|
||||||
let message = MessageBuilder::new()
|
let message = MessageBuilder::new()
|
||||||
.from((self.auth_email.auth_name.clone(), self.auth_email.auth_username.clone()))
|
.from((self.auth_email.auth_name.clone(), self.auth_email.auth_username.clone()))
|
||||||
.to(vec![
|
.to(vec![
|
||||||
@@ -125,7 +125,7 @@ impl RealmAuthServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn is_login_code_valid(&self, username: &str, login_code: u16) -> Result<bool, ErrorCode> {
|
async fn is_login_code_valid(&self, username: &str, login_code: u16) -> Result<bool, ErrorCode> {
|
||||||
let result = query!("SELECT login_code FROM user WHERE username = ?;", username).fetch_one(&self.db_pool).await;
|
let result = query!("SELECT login_code FROM user WHERE username = ?;", username).fetch_one(&self.db_pool).await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
@@ -139,7 +139,7 @@ impl RealmAuthServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_username_valid(&self, username: &str) -> bool {
|
fn is_username_valid(&self, username: &str) -> bool {
|
||||||
if !username.starts_with('@') || !username.contains(':') {
|
if !username.starts_with('@') || !username.contains(':') {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ impl RealmAuthServer {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn reset_login_code(&self, username: &str) -> Result<(), ErrorCode> {
|
async fn reset_login_code(&self, username: &str) -> Result<(), ErrorCode> {
|
||||||
let result = query!("UPDATE user SET login_code = NULL WHERE username = ?", username).execute(&self.db_pool).await;
|
let result = query!("UPDATE user SET login_code = NULL WHERE username = ?", username).execute(&self.db_pool).await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use crate::types::MessageData::*;
|
|||||||
pub trait RealmChat {
|
pub trait RealmChat {
|
||||||
async fn test(name: String) -> String;
|
async fn test(name: String) -> String;
|
||||||
|
|
||||||
//TODO: Any user authorized as themselves
|
//NOTE: Any user authorized as themselves
|
||||||
async fn send_message(stoken: String, message: Message) -> Result<Message, ErrorCode>;
|
async fn send_message(stoken: String, message: Message) -> Result<Message, ErrorCode>;
|
||||||
async fn start_typing(stoken: String, userid: String, roomid: String) -> ErrorCode;
|
async fn start_typing(stoken: String, userid: String, roomid: String) -> ErrorCode;
|
||||||
async fn stop_typing(stoken: String, userid: String, roomid: String) -> ErrorCode;
|
async fn stop_typing(stoken: String, userid: String, roomid: String) -> ErrorCode;
|
||||||
@@ -83,7 +83,9 @@ impl FromRow<'_, SqliteRow> for Message {
|
|||||||
},
|
},
|
||||||
data: match row.try_get("msg_type")? {
|
data: match row.try_get("msg_type")? {
|
||||||
"text" => Text(row.try_get("msg_text")?),
|
"text" => Text(row.try_get("msg_text")?),
|
||||||
"attachment" => todo!(),
|
"attachment" => Attachment(Attachment {
|
||||||
|
|
||||||
|
}),
|
||||||
"reply" => Reply(Reply {
|
"reply" => Reply(Reply {
|
||||||
referencing_id: row.try_get("referencing_id")?,
|
referencing_id: row.try_get("referencing_id")?,
|
||||||
text: row.try_get("msg_text")?,
|
text: row.try_get("msg_text")?,
|
||||||
|
|||||||
Reference in New Issue
Block a user