-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add endpoint for changing password
Feat: Add endpoint for registering a new user Chore: Slightly clean up CombinedAuthorizationProviderError conversions
- Loading branch information
1 parent
d198ba2
commit 5fad4c0
Showing
11 changed files
with
217 additions
and
28 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
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,51 @@ | ||
use crate::authorization::combined::CombinedAuthorizationProvider; | ||
use crate::authorization::AuthorizationProvider; | ||
use crate::response_types::Empty; | ||
use crate::routes::auth::Auth; | ||
use crate::routes::error::{WebErrorKind, WebResult}; | ||
use crate::routes::{auth_error_to_web_error, WConfig, WDatabase}; | ||
use actix_web::web; | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
pub struct Request { | ||
/// The old password | ||
old_password: String, | ||
/// The new password | ||
new_password: String, | ||
} | ||
|
||
/// Change the password of the authorized user | ||
/// | ||
/// # Errors | ||
/// | ||
/// - If the provider does not support changing passwords | ||
/// - If the provi`ded `old_password` does not match the stored password | ||
/// - If the change operation fails | ||
pub async fn change_password( | ||
auth: Auth, | ||
payload: web::Json<Request>, | ||
config: WConfig, | ||
database: WDatabase, | ||
) -> WebResult<Empty> { | ||
let provider = CombinedAuthorizationProvider::new(&config, &database); | ||
if !provider.supports_password_change() { | ||
return Err(WebErrorKind::Unsupported.into()); | ||
} | ||
|
||
// Check the old password is correct | ||
auth_error_to_web_error( | ||
provider | ||
.validate_credentials(&auth.user.email, &payload.old_password, None) | ||
.await, | ||
)?; | ||
|
||
// Set new password | ||
auth_error_to_web_error( | ||
provider | ||
.set_password(&auth.user.user_id, &payload.new_password) | ||
.await, | ||
)?; | ||
|
||
Ok(Empty) | ||
} |
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
Oops, something went wrong.