email state
This commit is contained in:
+30
-9
@@ -16,13 +16,13 @@ use lettre::smtp::error::Error as MailError;
|
||||
use lettre::smtp::extension::ClientId;
|
||||
use lettre::smtp::response::Response;
|
||||
use lettre::{SendableEmail, SmtpClient, SmtpTransport, Transport};
|
||||
use lettre_email::Email;
|
||||
use lettre_email::Email as LettreEmail;
|
||||
|
||||
use account::Account;
|
||||
use pg::Db;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UserEmail {
|
||||
#[derive(Debug,Clone,Serialize)]
|
||||
pub struct Email {
|
||||
pub id: Uuid,
|
||||
pub email: String,
|
||||
pub account: Uuid,
|
||||
@@ -50,7 +50,7 @@ http://mnml.gg/api/account/recover?recover_token={:}
|
||||
glhf
|
||||
--mnml", name, token);
|
||||
|
||||
Email::builder()
|
||||
LettreEmail::builder()
|
||||
.from("machines@mnml.gg")
|
||||
.to(email.clone())
|
||||
.subject("account recovery")
|
||||
@@ -68,7 +68,7 @@ http://mnml.gg/api/account/email/confirm?confirm_token={:}
|
||||
glhf
|
||||
--mnml", name, token);
|
||||
|
||||
Email::builder()
|
||||
LettreEmail::builder()
|
||||
.from("machines@mnml.gg")
|
||||
.to(email.clone())
|
||||
.subject("email confirmation")
|
||||
@@ -109,7 +109,7 @@ pub fn confirm_email(tx: &mut Transaction, account: &Account, confirm_token: Str
|
||||
return Ok((email, account));
|
||||
}
|
||||
|
||||
pub fn select(db: &Db, email: &String) -> Result<UserEmail, Error> {
|
||||
pub fn select(db: &Db, email: &String) -> Result<Email, Error> {
|
||||
let query = "
|
||||
SELECT id, email, account, confirmed
|
||||
FROM emails
|
||||
@@ -127,7 +127,28 @@ pub fn select(db: &Db, email: &String) -> Result<UserEmail, Error> {
|
||||
let account: Uuid = row.get(2);
|
||||
let confirmed: bool = row.get(3);
|
||||
|
||||
return Ok(UserEmail { id, email, account, confirmed });
|
||||
return Ok(Email { id, email, account, confirmed });
|
||||
}
|
||||
|
||||
pub fn select_account(db: &Db, account: Uuid) -> Result<Email, Error> {
|
||||
let query = "
|
||||
SELECT id, email, account, confirmed
|
||||
FROM emails
|
||||
WHERE account = $1;
|
||||
";
|
||||
|
||||
let result = db
|
||||
.query(query, &[&account])?;
|
||||
|
||||
let row = result.iter().next()
|
||||
.ok_or(err_msg("email found"))?;
|
||||
|
||||
let id: Uuid = row.get(0);
|
||||
let email: String = row.get(1);
|
||||
let account: Uuid = row.get(2);
|
||||
let confirmed: bool = row.get(3);
|
||||
|
||||
return Ok(Email { id, email, account, confirmed });
|
||||
}
|
||||
|
||||
pub fn set_recovery(tx: &mut Transaction, email: &String) -> Result<String, Error> {
|
||||
@@ -158,7 +179,7 @@ pub fn set_recovery(tx: &mut Transaction, email: &String) -> Result<String, Erro
|
||||
return Ok(recover_token);
|
||||
}
|
||||
|
||||
pub fn get_recovery(tx: &mut Transaction, recover_token: &String) -> Result<UserEmail, Error> {
|
||||
pub fn get_recovery(tx: &mut Transaction, recover_token: &String) -> Result<Email, Error> {
|
||||
// set a new token when recovering to prevent multiple access
|
||||
let mut rng = thread_rng();
|
||||
let new_token: String = iter::repeat(())
|
||||
@@ -186,7 +207,7 @@ pub fn get_recovery(tx: &mut Transaction, recover_token: &String) -> Result<User
|
||||
let account: Uuid = row.get(2);
|
||||
let confirmed: bool = row.get(3);
|
||||
|
||||
return Ok(UserEmail { id, email, account, confirmed });
|
||||
return Ok(Email { id, email, account, confirmed });
|
||||
}
|
||||
|
||||
pub fn set(tx: &mut Transaction, account: Uuid, email: &String) -> Result<(Uuid, String), Error> {
|
||||
|
||||
+13
-1
@@ -22,13 +22,15 @@ use game::{Game, game_state, game_skill, game_ready};
|
||||
use instance::{Instance, instance_state, instance_practice, instance_ready};
|
||||
use item::{Item, ItemInfoCtr, item_info};
|
||||
use mtx;
|
||||
use mail;
|
||||
use mail::Email;
|
||||
use pg::{Db};
|
||||
use pg::{PgPool};
|
||||
use skill::{Skill, dev_resolve, Resolutions};
|
||||
use vbox::{vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_reclaim, vbox_unequip};
|
||||
use http::{AUTH_CLEAR, TOKEN_HEADER};
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
#[derive(Debug,Clone,Serialize)]
|
||||
pub enum RpcMessage {
|
||||
AccountState(Account),
|
||||
AccountConstructs(Vec<Construct>),
|
||||
@@ -36,6 +38,7 @@ pub enum RpcMessage {
|
||||
AccountInstances(Vec<Instance>),
|
||||
AccountShop(mtx::Shop),
|
||||
ConstructSpawn(Construct),
|
||||
EmailState(Email),
|
||||
GameState(Game),
|
||||
ItemInfo(ItemInfoCtr),
|
||||
|
||||
@@ -225,6 +228,15 @@ impl Handler for Connection {
|
||||
let db = self.pool.get().unwrap();
|
||||
let mut tx = db.transaction().unwrap();
|
||||
|
||||
// email state
|
||||
match mail::select_account(&db, a.id) {
|
||||
Ok(e) => {
|
||||
self.ws.send(RpcMessage::EmailState(e.clone())).unwrap();
|
||||
self.events.send(Event::Subscribe(self.id, e.id)).unwrap();
|
||||
},
|
||||
Err(_) => (),
|
||||
};
|
||||
|
||||
// send account constructs
|
||||
let account_constructs = account::constructs(&mut tx, a).unwrap();
|
||||
self.ws.send(RpcMessage::AccountConstructs(account_constructs)).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user