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;
|
RETURNING id;
|
||||||
";
|
";
|
||||||
|
|
||||||
|
let select_query = "
|
||||||
|
SELECT *
|
||||||
|
FROM emails
|
||||||
|
WHERE account = $1;
|
||||||
|
";
|
||||||
|
|
||||||
let update_query = "
|
let update_query = "
|
||||||
UPDATE emails
|
UPDATE emails
|
||||||
SET email = $1, confirm_token = $2, confirmed = false, recover_token = $3
|
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;
|
RETURNING id;
|
||||||
";
|
";
|
||||||
|
|
||||||
let result = match tx.query(insert_query, &[&id, &account, &email, &confirm_token, &recover_token]) {
|
let existing = tx.query(select_query, &[&id])?;
|
||||||
Ok(r) => r,
|
|
||||||
// email update probably
|
let result = match existing.iter().next() {
|
||||||
Err(_) => {
|
Some(_) => tx.query(insert_query, &[&id, &account, &email, &confirm_token, &recover_token])?,
|
||||||
match tx.query(update_query, &[&email, &confirm_token, &recover_token, &account]) {
|
None => tx.query(update_query, &[&email, &confirm_token, &recover_token, &account])?,
|
||||||
Ok(r) => r,
|
|
||||||
Err(e) => {
|
|
||||||
warn!("{:?}", e);
|
|
||||||
return Err(err_msg("no email set"));
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match result.iter().next() {
|
match result.iter().next() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user