mirror of
https://github.com/ViViDboarder/bitwarden_rs.git
synced 2024-11-16 18:26:37 +00:00
Modify User::new to be keyless and paswordless
This commit is contained in:
parent
ec05f14f5a
commit
c1cd4d9a6b
@ -38,8 +38,6 @@ fn register(data: JsonUpcase<RegisterData>, conn: DbConn) -> EmptyResult {
|
|||||||
user_org.status = UserOrgStatus::Accepted as i32;
|
user_org.status = UserOrgStatus::Accepted as i32;
|
||||||
user_org.save(&conn);
|
user_org.save(&conn);
|
||||||
};
|
};
|
||||||
user.set_password(&data.MasterPasswordHash);
|
|
||||||
user.key = data.Key;
|
|
||||||
user
|
user
|
||||||
} else {
|
} else {
|
||||||
if CONFIG.signups_allowed {
|
if CONFIG.signups_allowed {
|
||||||
@ -51,13 +49,16 @@ fn register(data: JsonUpcase<RegisterData>, conn: DbConn) -> EmptyResult {
|
|||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
if CONFIG.signups_allowed || Invitation::take(&data.Email, &conn) {
|
if CONFIG.signups_allowed || Invitation::take(&data.Email, &conn) {
|
||||||
User::new(data.Email, data.Key, data.MasterPasswordHash)
|
User::new(data.Email)
|
||||||
} else {
|
} else {
|
||||||
err!("Registration not allowed")
|
err!("Registration not allowed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
user.set_password(&data.MasterPasswordHash);
|
||||||
|
user.key = data.Key;
|
||||||
|
|
||||||
// Add extra fields if present
|
// Add extra fields if present
|
||||||
if let Some(name) = data.Name {
|
if let Some(name) = data.Name {
|
||||||
user.name = name;
|
user.name = name;
|
||||||
|
@ -380,7 +380,7 @@ fn send_invite(org_id: String, data: JsonUpcase<InviteData>, headers: AdminHeade
|
|||||||
let mut invitation = Invitation::new(email.clone());
|
let mut invitation = Invitation::new(email.clone());
|
||||||
match invitation.save(&conn) {
|
match invitation.save(&conn) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
let mut user = User::new_invited(email.clone());
|
let mut user = User::new(email.clone());
|
||||||
if user.save(&conn) {
|
if user.save(&conn) {
|
||||||
user_org_status = UserOrgStatus::Invited as i32;
|
user_org_status = UserOrgStatus::Invited as i32;
|
||||||
user
|
user
|
||||||
|
@ -39,13 +39,12 @@ pub struct User {
|
|||||||
|
|
||||||
/// Local methods
|
/// Local methods
|
||||||
impl User {
|
impl User {
|
||||||
pub fn new(mail: String, key: String, password: String) -> Self {
|
pub fn new(mail: String) -> Self {
|
||||||
let now = Utc::now().naive_utc();
|
let now = Utc::now().naive_utc();
|
||||||
let email = mail.to_lowercase();
|
let email = mail.to_lowercase();
|
||||||
|
|
||||||
let iterations = CONFIG.password_iterations;
|
let iterations = CONFIG.password_iterations;
|
||||||
let salt = crypto::get_random_64();
|
let salt = crypto::get_random_64();
|
||||||
let password_hash = crypto::hash_password(password.as_bytes(), &salt, iterations as u32);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
uuid: Uuid::new_v4().to_string(),
|
uuid: Uuid::new_v4().to_string(),
|
||||||
@ -53,9 +52,9 @@ impl User {
|
|||||||
updated_at: now,
|
updated_at: now,
|
||||||
name: email.clone(),
|
name: email.clone(),
|
||||||
email,
|
email,
|
||||||
key,
|
key: String::new(),
|
||||||
|
|
||||||
password_hash,
|
password_hash: Vec::new(),
|
||||||
salt,
|
salt,
|
||||||
password_iterations: iterations,
|
password_iterations: iterations,
|
||||||
|
|
||||||
@ -73,10 +72,6 @@ impl User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_invited(mail: String) -> Self {
|
|
||||||
Self::new(mail,"".to_string(),"".to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn check_valid_password(&self, password: &str) -> bool {
|
pub fn check_valid_password(&self, password: &str) -> bool {
|
||||||
crypto::verify_password_hash(password.as_bytes(),
|
crypto::verify_password_hash(password.as_bytes(),
|
||||||
&self.salt,
|
&self.salt,
|
||||||
|
Loading…
Reference in New Issue
Block a user