forked from PeachCloud/peach-workspace
43 lines
1.4 KiB
Rust
43 lines
1.4 KiB
Rust
use log::debug;
|
|
use peach_lib::password_utils;
|
|
use rouille::Response;
|
|
|
|
use crate::utils::flash::FlashResponse;
|
|
|
|
// ROUTE: /auth/temporary (POST)
|
|
|
|
/// Send a temporary password as a Scuttlebutt private message to the admin(s).
|
|
///
|
|
/// This route is used by a user who is not logged in and is specifically for
|
|
/// users who have forgotten their password. A successful request results
|
|
/// in a Scuttlebutt private message being sent to the account of the device
|
|
/// admin.
|
|
///
|
|
/// Redirects to the Send Password Reset page a flash message describing the
|
|
/// outcome of the action (may be successful or unsuccessful).
|
|
pub fn handle_form() -> Response {
|
|
// save submitted admin id to file
|
|
let (flash_name, flash_msg) = match password_utils::send_password_reset() {
|
|
Ok(_) => {
|
|
debug!("Sent temporary password to device admin(s)");
|
|
(
|
|
"flash_name=success".to_string(),
|
|
"flash_msg=A temporary password has been sent to the admin(s) of this device"
|
|
.to_string(),
|
|
)
|
|
}
|
|
Err(err) => {
|
|
debug!(
|
|
"Received an error while trying to send temporary password to device admin(s): {}",
|
|
err
|
|
);
|
|
(
|
|
"error".to_string(),
|
|
format!("Failed to send temporary password: {}", err),
|
|
)
|
|
}
|
|
};
|
|
|
|
Response::redirect_303("/auth/forgot").add_flash(flash_name, flash_msg)
|
|
}
|