Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
1,273 additions
and
100 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE email_token_credentials; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE email_token_credentials ( | ||
id INTEGER PRIMARY KEY, | ||
expires_at INTEGER NOT NULL, | ||
username TEXT NOT NULL, | ||
email TEXT NOT NULL, | ||
nonce TEXT NOT NULL, | ||
UNIQUE (username), | ||
UNIQUE (nonce), | ||
FOREIGN KEY (username) REFERENCES users(username) | ||
); |
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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use super::*; | ||
|
||
use crate::core::error::{Error, ParameterError}; | ||
|
||
pub fn confirm_email_and_reset_password<D: Db>( | ||
db: &D, | ||
username: &str, | ||
email: &str, | ||
new_password: Password, | ||
) -> Result<()> { | ||
info!("Resetting password for user ({})", username); | ||
let mut user = db.get_user(username)?; | ||
debug_assert_eq!(user.username, username); | ||
if user.email != email { | ||
warn!( | ||
"Invalid e-mail address for user ({}): expected = {}, actual = {}", | ||
user.username, user.email, email, | ||
); | ||
return Err(Error::Parameter(ParameterError::Email)); | ||
} | ||
user.email_confirmed = true; | ||
user.password = new_password; | ||
db.update_user(&user)?; | ||
Ok(()) | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::core::prelude::*; | ||
|
||
use chrono::{Duration, Utc}; | ||
|
||
pub fn refresh_email_token_credentials<D: Db>( | ||
db: &D, | ||
username: String, | ||
email: String, | ||
) -> Result<EmailTokenCredentials> { | ||
let token = EmailToken { | ||
email, | ||
nonce: Nonce::new(), | ||
}; | ||
let credentials = EmailTokenCredentials { | ||
expires_at: Timestamp::from(Utc::now() + Duration::days(1)), | ||
username, | ||
token, | ||
}; | ||
Ok(db.replace_email_token_credentials(credentials)?) | ||
} | ||
|
||
pub fn consume_email_token_credentials<D: Db>( | ||
db: &D, | ||
email_or_username: &str, | ||
token: &EmailToken, | ||
) -> Result<EmailTokenCredentials> { | ||
let credentials = db.consume_email_token_credentials(email_or_username, token)?; | ||
if credentials.expires_at < Timestamp::now() { | ||
return Err(Error::Parameter(ParameterError::TokenExpired)); | ||
} | ||
Ok(credentials) | ||
} | ||
|
||
pub fn discard_expired_email_token_credentials<D: Db>(db: &D) -> Result<usize> { | ||
let expired_before = Timestamp::now(); | ||
Ok(db.discard_expired_email_token_credentials(expired_before)?) | ||
} |
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
Oops, something went wrong.