mirror of
				https://github.com/dani-garcia/vaultwarden.git
				synced 2025-10-27 16:30:02 +02:00 
			
		
		
		
	Special messages when user has no password hint
This commit is contained in:
		| @@ -273,17 +273,16 @@ fn password_hint(data: JsonUpcase<PasswordHintData>, conn: DbConn) -> EmptyResul | ||||
|     } | ||||
|  | ||||
|     let user = user.unwrap(); | ||||
|     let hint = match user.password_hint { | ||||
|         Some(hint) => hint, | ||||
|         None => return Ok(()), | ||||
|     }; | ||||
|  | ||||
|     if let Some(ref mail_config) = CONFIG.mail { | ||||
|         if let Err(e) = mail::send_password_hint(&user.email, &hint, mail_config) { | ||||
|         if let Err(e) = mail::send_password_hint(&user.email, user.password_hint, mail_config) { | ||||
|             err!(format!("There have been a problem sending the email: {}", e)); | ||||
|         } | ||||
|     } else if CONFIG.show_password_hint { | ||||
|         err!(format!("Your password hint is: {}", &hint)); | ||||
|         if let Some(hint) = user.password_hint { | ||||
|             err!(format!("Your password hint is: {}", &hint)); | ||||
|         } else { | ||||
|             err!(format!("Sorry, you have no password hint...")); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     Ok(()) | ||||
|   | ||||
							
								
								
									
										21
									
								
								src/mail.rs
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								src/mail.rs
									
									
									
									
									
								
							| @@ -36,17 +36,23 @@ fn mailer(config: &MailConfig) -> SmtpTransport { | ||||
|         .build() | ||||
| } | ||||
|  | ||||
| pub fn send_password_hint(address: &str, hint: &str, config: &MailConfig) -> Result<(), String> { | ||||
|     let body = format!( | ||||
|         "You (or someone) recently requested your master password hint.\n\n\ | ||||
|          Your hint is:  \"{}\"\n\n\ | ||||
|          If you did not request your master password hint you can safely ignore this email.\n", | ||||
|         hint);  | ||||
| pub fn send_password_hint(address: &str, hint: Option<String>, config: &MailConfig) -> Result<(), String> { | ||||
|     let (subject, body) = if let Some(hint) = hint { | ||||
|         ("Your master password hint", | ||||
|          format!( | ||||
|             "You (or someone) recently requested your master password hint.\n\n\ | ||||
|              Your hint is:  \"{}\"\n\n\ | ||||
|              If you did not request your master password hint you can safely ignore this email.\n", | ||||
|             hint)) | ||||
|     } else { | ||||
|         ("Sorry, you have no password hint...", | ||||
|          "Sorry, you have not specified any password hint...\n".to_string()) | ||||
|     }; | ||||
|  | ||||
|     let email = EmailBuilder::new() | ||||
|         .to(address) | ||||
|         .from((config.smtp_from.to_owned(), "Bitwarden-rs")) | ||||
|         .subject("Your Master Password Hint") | ||||
|         .subject(subject) | ||||
|         .body(body) | ||||
|         .build().unwrap(); | ||||
|  | ||||
| @@ -55,4 +61,3 @@ pub fn send_password_hint(address: &str, hint: &str, config: &MailConfig) -> Res | ||||
|         Err(e) => Err(e.description().to_string()), | ||||
|     } | ||||
| } | ||||
|          | ||||
|   | ||||
		Reference in New Issue
	
	Block a user