Add API method for changing password
This commit is contained in:
parent
6de2b572a4
commit
57c5ab3c4e
3 changed files with 47 additions and 0 deletions
|
@ -157,6 +157,29 @@ paths:
|
||||||
$ref: '#/components/schemas/AccountWithSource'
|
$ref: '#/components/schemas/AccountWithSource'
|
||||||
400:
|
400:
|
||||||
description: Invalid user data.
|
description: Invalid user data.
|
||||||
|
/api/v1/accounts/change_password:
|
||||||
|
post:
|
||||||
|
summary: Set or change user's password.
|
||||||
|
security:
|
||||||
|
- tokenAuth: []
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
new_password:
|
||||||
|
description: New password.
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: Successful operation.
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/AccountWithSource'
|
||||||
|
400:
|
||||||
|
description: Invalid request data.
|
||||||
/api/v1/accounts/signed_update:
|
/api/v1/accounts/signed_update:
|
||||||
get:
|
get:
|
||||||
summary: Build Update(Person) activity for signing (experimental).
|
summary: Build Update(Person) activity for signing (experimental).
|
||||||
|
|
|
@ -262,6 +262,11 @@ impl AccountUpdateData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct PasswordChangeRequest {
|
||||||
|
pub new_password: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct UnsignedUpdate {
|
pub struct UnsignedUpdate {
|
||||||
pub internal_activity_id: Uuid,
|
pub internal_activity_id: Uuid,
|
||||||
|
|
|
@ -69,6 +69,7 @@ use crate::models::users::queries::{
|
||||||
is_valid_invite_code,
|
is_valid_invite_code,
|
||||||
create_user,
|
create_user,
|
||||||
get_user_by_did,
|
get_user_by_did,
|
||||||
|
set_user_password,
|
||||||
};
|
};
|
||||||
use crate::models::users::types::UserCreateData;
|
use crate::models::users::types::UserCreateData;
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
|
@ -93,6 +94,7 @@ use super::types::{
|
||||||
IdentityClaim,
|
IdentityClaim,
|
||||||
IdentityClaimQueryParams,
|
IdentityClaimQueryParams,
|
||||||
IdentityProofData,
|
IdentityProofData,
|
||||||
|
PasswordChangeRequest,
|
||||||
RelationshipQueryParams,
|
RelationshipQueryParams,
|
||||||
SearchAcctQueryParams,
|
SearchAcctQueryParams,
|
||||||
SearchDidQueryParams,
|
SearchDidQueryParams,
|
||||||
|
@ -227,6 +229,22 @@ async fn update_credentials(
|
||||||
Ok(HttpResponse::Ok().json(account))
|
Ok(HttpResponse::Ok().json(account))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[post("/change_password")]
|
||||||
|
async fn change_password_view(
|
||||||
|
auth: BearerAuth,
|
||||||
|
config: web::Data<Config>,
|
||||||
|
db_pool: web::Data<Pool>,
|
||||||
|
request_data: web::Json<PasswordChangeRequest>,
|
||||||
|
) -> Result<HttpResponse, HttpError> {
|
||||||
|
let db_client = &**get_database_client(&db_pool).await?;
|
||||||
|
let current_user = get_current_user(db_client, auth.token()).await?;
|
||||||
|
let password_hash = hash_password(&request_data.new_password)
|
||||||
|
.map_err(|_| HttpError::InternalError)?;
|
||||||
|
set_user_password(db_client, ¤t_user.id, password_hash).await?;
|
||||||
|
let account = Account::from_user(current_user, &config.instance_url());
|
||||||
|
Ok(HttpResponse::Ok().json(account))
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/signed_update")]
|
#[get("/signed_update")]
|
||||||
async fn get_unsigned_update(
|
async fn get_unsigned_update(
|
||||||
auth: BearerAuth,
|
auth: BearerAuth,
|
||||||
|
@ -703,6 +721,7 @@ pub fn account_api_scope() -> Scope {
|
||||||
.service(create_account)
|
.service(create_account)
|
||||||
.service(verify_credentials)
|
.service(verify_credentials)
|
||||||
.service(update_credentials)
|
.service(update_credentials)
|
||||||
|
.service(change_password_view)
|
||||||
.service(get_unsigned_update)
|
.service(get_unsigned_update)
|
||||||
.service(send_signed_update)
|
.service(send_signed_update)
|
||||||
.service(get_identity_claim)
|
.service(get_identity_claim)
|
||||||
|
|
Loading…
Reference in a new issue