fix email confirmation
This commit is contained in:
parent
e1e84c3363
commit
d5668e085f
@ -232,6 +232,12 @@ pub fn set(tx: &mut Transaction, account: Uuid, email: &String) -> Result<(Uuid,
|
||||
RETURNING id;
|
||||
";
|
||||
|
||||
let select_query = "
|
||||
SELECT *
|
||||
FROM emails
|
||||
WHERE account = $1;
|
||||
";
|
||||
|
||||
let update_query = "
|
||||
UPDATE emails
|
||||
SET email = $1, confirm_token = $2, confirmed = false, recover_token = $3
|
||||
@ -239,18 +245,11 @@ pub fn set(tx: &mut Transaction, account: Uuid, email: &String) -> Result<(Uuid,
|
||||
RETURNING id;
|
||||
";
|
||||
|
||||
let result = match tx.query(insert_query, &[&id, &account, &email, &confirm_token, &recover_token]) {
|
||||
Ok(r) => r,
|
||||
// email update probably
|
||||
Err(_) => {
|
||||
match tx.query(update_query, &[&email, &confirm_token, &recover_token, &account]) {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
warn!("{:?}", e);
|
||||
return Err(err_msg("no email set"));
|
||||
},
|
||||
}
|
||||
}
|
||||
let existing = tx.query(select_query, &[&id])?;
|
||||
|
||||
let result = match existing.iter().next() {
|
||||
Some(_) => tx.query(insert_query, &[&id, &account, &email, &confirm_token, &recover_token])?,
|
||||
None => tx.query(update_query, &[&email, &confirm_token, &recover_token, &account])?,
|
||||
};
|
||||
|
||||
match result.iter().next() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user