|
|
@ -84,9 +84,10 @@ fn register(data: JsonUpcase<RegisterData>, conn: DbConn) -> EmptyResult {
|
|
|
|
user.public_key = Some(keys.PublicKey);
|
|
|
|
user.public_key = Some(keys.PublicKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
user.save(&conn);
|
|
|
|
match user.save(&conn) {
|
|
|
|
|
|
|
|
Ok(()) => Ok(()),
|
|
|
|
Ok(())
|
|
|
|
Err(_) => err!("Failed to save user")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[get("/accounts/profile")]
|
|
|
|
#[get("/accounts/profile")]
|
|
|
@ -119,9 +120,10 @@ fn post_profile(data: JsonUpcase<ProfileData>, headers: Headers, conn: DbConn) -
|
|
|
|
Some(ref h) if h.is_empty() => None,
|
|
|
|
Some(ref h) if h.is_empty() => None,
|
|
|
|
_ => data.MasterPasswordHint,
|
|
|
|
_ => data.MasterPasswordHint,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
user.save(&conn);
|
|
|
|
match user.save(&conn) {
|
|
|
|
|
|
|
|
Ok(()) => Ok(Json(user.to_json(&conn))),
|
|
|
|
Ok(Json(user.to_json(&conn)))
|
|
|
|
Err(_) => err!("Failed to save user profile")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[get("/users/<uuid>/public-key")]
|
|
|
|
#[get("/users/<uuid>/public-key")]
|
|
|
@ -147,11 +149,14 @@ fn post_keys(data: JsonUpcase<KeysData>, headers: Headers, conn: DbConn) -> Json
|
|
|
|
user.private_key = Some(data.EncryptedPrivateKey);
|
|
|
|
user.private_key = Some(data.EncryptedPrivateKey);
|
|
|
|
user.public_key = Some(data.PublicKey);
|
|
|
|
user.public_key = Some(data.PublicKey);
|
|
|
|
|
|
|
|
|
|
|
|
user.save(&conn);
|
|
|
|
match user.save(&conn) {
|
|
|
|
|
|
|
|
Ok(()) => Ok(Json(user.to_json(&conn))),
|
|
|
|
Ok(Json(user.to_json(&conn)))
|
|
|
|
Err(_) => err!("Failed to save the user's keys")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
struct ChangePassData {
|
|
|
|
struct ChangePassData {
|
|
|
@ -171,9 +176,10 @@ fn post_password(data: JsonUpcase<ChangePassData>, headers: Headers, conn: DbCon
|
|
|
|
|
|
|
|
|
|
|
|
user.set_password(&data.NewMasterPasswordHash);
|
|
|
|
user.set_password(&data.NewMasterPasswordHash);
|
|
|
|
user.key = data.Key;
|
|
|
|
user.key = data.Key;
|
|
|
|
user.save(&conn);
|
|
|
|
match user.save(&conn) {
|
|
|
|
|
|
|
|
Ok(()) => Ok(()),
|
|
|
|
Ok(())
|
|
|
|
Err(_) => err!("Failed to save password")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[derive(Deserialize)]
|
|
|
@ -200,9 +206,10 @@ fn post_kdf(data: JsonUpcase<ChangeKdfData>, headers: Headers, conn: DbConn) ->
|
|
|
|
user.client_kdf_type = data.Kdf;
|
|
|
|
user.client_kdf_type = data.Kdf;
|
|
|
|
user.set_password(&data.NewMasterPasswordHash);
|
|
|
|
user.set_password(&data.NewMasterPasswordHash);
|
|
|
|
user.key = data.Key;
|
|
|
|
user.key = data.Key;
|
|
|
|
user.save(&conn);
|
|
|
|
match user.save(&conn) {
|
|
|
|
|
|
|
|
Ok(()) => Ok(()),
|
|
|
|
Ok(())
|
|
|
|
Err(_) => err!("Failed to save password settings")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[post("/accounts/security-stamp", data = "<data>")]
|
|
|
|
#[post("/accounts/security-stamp", data = "<data>")]
|
|
|
@ -215,9 +222,10 @@ fn post_sstamp(data: JsonUpcase<PasswordData>, headers: Headers, conn: DbConn) -
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
user.reset_security_stamp();
|
|
|
|
user.reset_security_stamp();
|
|
|
|
user.save(&conn);
|
|
|
|
match user.save(&conn) {
|
|
|
|
|
|
|
|
Ok(()) => Ok(()),
|
|
|
|
Ok(())
|
|
|
|
Err(_) => err!("Failed to reset security stamp")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[derive(Deserialize)]
|
|
|
@ -272,9 +280,10 @@ fn post_email(data: JsonUpcase<ChangeEmailData>, headers: Headers, conn: DbConn)
|
|
|
|
user.set_password(&data.NewMasterPasswordHash);
|
|
|
|
user.set_password(&data.NewMasterPasswordHash);
|
|
|
|
user.key = data.Key;
|
|
|
|
user.key = data.Key;
|
|
|
|
|
|
|
|
|
|
|
|
user.save(&conn);
|
|
|
|
match user.save(&conn) {
|
|
|
|
|
|
|
|
Ok(()) => Ok(()),
|
|
|
|
Ok(())
|
|
|
|
Err(_) => err!("Failed to save email address")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[post("/accounts/delete", data = "<data>")]
|
|
|
|
#[post("/accounts/delete", data = "<data>")]
|
|
|
|