mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-09-11 11:15:58 +03:00
Update admin page to work with new invitation flow
This commit is contained in:
72
src/mail.rs
72
src/mail.rs
@@ -5,6 +5,7 @@ use lettre_email::EmailBuilder;
|
||||
use native_tls::{Protocol, TlsConnector};
|
||||
|
||||
use crate::MailConfig;
|
||||
use crate::CONFIG;
|
||||
|
||||
use crate::api::EmptyResult;
|
||||
use crate::error::Error;
|
||||
@@ -52,21 +53,66 @@ pub fn send_password_hint(address: &str, hint: Option<String>, config: &MailConf
|
||||
)
|
||||
};
|
||||
|
||||
let email = EmailBuilder::new()
|
||||
.to(address)
|
||||
.from((config.smtp_from.clone(), "Bitwarden-rs"))
|
||||
.subject(subject)
|
||||
.body(body)
|
||||
.build()
|
||||
.map_err(|e| Error::new("Error building hint email", e.to_string()))?;
|
||||
|
||||
mailer(config)
|
||||
.send(email.into())
|
||||
.map_err(|e| Error::new("Error sending hint email", e.to_string()))
|
||||
.and(Ok(()))
|
||||
send_email(&address, &subject, &body, &config)
|
||||
}
|
||||
|
||||
pub fn send_email(address: &str, subject: &str, body: &str, config: &MailConfig) -> EmptyResult {
|
||||
pub fn send_invite(
|
||||
address: &str,
|
||||
org_id: &str,
|
||||
org_user_id: &str,
|
||||
token: &str,
|
||||
org_name: &str,
|
||||
config: &MailConfig,
|
||||
) -> EmptyResult {
|
||||
let (subject, body) = {
|
||||
(format!("Join {}", &org_name),
|
||||
format!(
|
||||
"<html>
|
||||
<p>You have been invited to join the <b>{}</b> organization.<br><br>
|
||||
<a href=\"{}/#/accept-organization/?organizationId={}&organizationUserId={}&email={}&organizationName={}&token={}\">Click here to join</a></p>
|
||||
<p>If you do not wish to join this organization, you can safely ignore this email.</p>
|
||||
</html>",
|
||||
org_name, CONFIG.domain, org_id, org_user_id, address, org_name, token
|
||||
))
|
||||
};
|
||||
|
||||
send_email(&address, &subject, &body, &config)
|
||||
}
|
||||
|
||||
pub fn send_invite_accepted(
|
||||
new_user_email: &str,
|
||||
address: &str,
|
||||
org_name: &str,
|
||||
config: &MailConfig,
|
||||
) -> EmptyResult {
|
||||
let (subject, body) = {
|
||||
("Invitation accepted",
|
||||
format!(
|
||||
"<html>
|
||||
<p>Your invitation to <b>{}</b> to join <b>{}</b> was accepted. Please log in to the bitwarden_rs server and confirm them from the organization management page.</p>
|
||||
</html>", new_user_email, org_name))
|
||||
};
|
||||
|
||||
send_email(&address, &subject, &body, &config)
|
||||
}
|
||||
|
||||
pub fn send_invite_confirmed(
|
||||
address: &str,
|
||||
org_name: &str,
|
||||
config: &MailConfig,
|
||||
) -> EmptyResult {
|
||||
let (subject, body) = {
|
||||
(format!("Invitation to {} confirmed", org_name),
|
||||
format!(
|
||||
"<html>
|
||||
<p>Your invitation to join <b>{}</b> was accepted. It will now appear under the Organizations the next time you log into the web vault.</p>
|
||||
</html>", org_name))
|
||||
};
|
||||
|
||||
send_email(&address, &subject, &body, &config)
|
||||
}
|
||||
|
||||
fn send_email(address: &str, subject: &str, body: &str, config: &MailConfig) -> EmptyResult {
|
||||
let email = EmailBuilder::new()
|
||||
.to(address)
|
||||
.from((config.smtp_from.clone(), "Bitwarden-rs"))
|
||||
|
Reference in New Issue
Block a user