|
|
@ -7,7 +7,7 @@ use crate::db::DbConn; |
|
|
|
use crate::CONFIG; |
|
|
|
|
|
|
|
use crate::api::{EmptyResult, JsonResult, JsonUpcase, Notify, NumberOrString, PasswordData, UpdateType}; |
|
|
|
use crate::auth::{decode_invite_jwt, generate_invite_claims, encode_jwt, AdminHeaders, Headers, InviteJWTClaims, OwnerHeaders}; |
|
|
|
use crate::auth::{decode_invite_jwt, AdminHeaders, Headers, InviteJWTClaims, OwnerHeaders}; |
|
|
|
|
|
|
|
use crate::mail; |
|
|
|
|
|
|
@ -506,15 +506,16 @@ fn send_invite(org_id: String, data: JsonUpcase<InviteData>, headers: AdminHeade |
|
|
|
Some(org) => org.name, |
|
|
|
None => err!("Error looking up organization"), |
|
|
|
}; |
|
|
|
let claims = generate_invite_claims( |
|
|
|
user.uuid.to_string(), |
|
|
|
user.email.clone(), |
|
|
|
org_id.clone(), |
|
|
|
Some(new_user.uuid.clone()), |
|
|
|
|
|
|
|
mail::send_invite( |
|
|
|
&email,
|
|
|
|
&user.uuid,
|
|
|
|
Some(org_id.clone()),
|
|
|
|
Some(new_user.uuid),
|
|
|
|
&org_name,
|
|
|
|
Some(headers.user.email.clone()),
|
|
|
|
); |
|
|
|
let invite_token = encode_jwt(&claims); |
|
|
|
mail::send_invite(&email, &org_id, &new_user.uuid, &invite_token, &org_name, mail_config)?; |
|
|
|
mail_config |
|
|
|
)?; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -550,21 +551,14 @@ fn reinvite_user(org_id: String, user_org: String, headers: AdminHeaders, conn: |
|
|
|
None => err!("Error looking up organization."), |
|
|
|
}; |
|
|
|
|
|
|
|
let claims = generate_invite_claims( |
|
|
|
user.uuid.to_string(), |
|
|
|
user.email.clone(), |
|
|
|
org_id.clone(), |
|
|
|
Some(user_org.uuid.clone()), |
|
|
|
Some(headers.user.email.clone()), |
|
|
|
); |
|
|
|
let invite_token = encode_jwt(&claims); |
|
|
|
if let Some(ref mail_config) = CONFIG.mail { |
|
|
|
mail::send_invite( |
|
|
|
&user.email, |
|
|
|
&org_id, |
|
|
|
&user_org.uuid, |
|
|
|
&invite_token, |
|
|
|
&user.uuid, |
|
|
|
Some(org_id), |
|
|
|
Some(user_org.uuid), |
|
|
|
&org_name, |
|
|
|
Some(headers.user.email), |
|
|
|
mail_config, |
|
|
|
)?; |
|
|
|
} |
|
|
@ -588,10 +582,10 @@ fn accept_invite(_org_id: String, _org_user_id: String, data: JsonUpcase<AcceptD |
|
|
|
match User::find_by_mail(&claims.email, &conn) { |
|
|
|
Some(_) => { |
|
|
|
Invitation::take(&claims.email, &conn); |
|
|
|
if claims.user_org_id.is_some() { |
|
|
|
if claims.user_org_id.is_some() && claims.org_id.is_some() { |
|
|
|
// If this isn't the virtual_org, mark userorg as accepted
|
|
|
|
let mut user_org = |
|
|
|
match UserOrganization::find_by_uuid_and_org(&claims.user_org_id.unwrap(), &claims.org_id, &conn) { |
|
|
|
match UserOrganization::find_by_uuid_and_org(&claims.user_org_id.unwrap(), &claims.org_id.clone().unwrap(), &conn) { |
|
|
|
Some(user_org) => user_org, |
|
|
|
None => err!("Error accepting the invitation"), |
|
|
|
}; |
|
|
@ -605,9 +599,12 @@ fn accept_invite(_org_id: String, _org_user_id: String, data: JsonUpcase<AcceptD |
|
|
|
} |
|
|
|
|
|
|
|
if let Some(ref mail_config) = CONFIG.mail { |
|
|
|
let org_name = match Organization::find_by_uuid(&claims.org_id, &conn) { |
|
|
|
let mut org_name = String::from("bitwarden_rs"); |
|
|
|
if let Some(org_id) = &claims.org_id { |
|
|
|
org_name = match Organization::find_by_uuid(&org_id, &conn) { |
|
|
|
Some(org) => org.name, |
|
|
|
None => String::from("bitwarden_rs"), |
|
|
|
None => err!("Organization not found.") |
|
|
|
}; |
|
|
|
}; |
|
|
|
if let Some(invited_by_email) = &claims.invited_by_email { |
|
|
|
// User was invited to an organization, so they must be confirmed manually after acceptance
|
|
|
|