[Database] Add 'creation_datetime' to User + some little things
This commit is contained in:
parent
91ab379718
commit
7a09e2360e
14 changed files with 179 additions and 131 deletions
|
|
@ -34,9 +34,9 @@ pub async fn sign_up_get(
|
|||
user,
|
||||
tr,
|
||||
email: String::new(),
|
||||
message: String::new(),
|
||||
message_email: String::new(),
|
||||
message_password: String::new(),
|
||||
message: "",
|
||||
message_email: "",
|
||||
message_password: "",
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -71,26 +71,27 @@ pub async fn sign_up_post(
|
|||
user: Option<model::User>,
|
||||
tr: translation::Tr,
|
||||
) -> Result<Response> {
|
||||
let invalid_password_mess = &tr.tp(
|
||||
Sentence::InvalidPassword,
|
||||
&[Box::new(common::consts::MIN_PASSWORD_SIZE)],
|
||||
);
|
||||
Ok(SignUpFormTemplate {
|
||||
user,
|
||||
email: form_data.email.clone(),
|
||||
message_email: match error {
|
||||
SignUpError::InvalidEmail => tr.t(Sentence::InvalidEmail),
|
||||
_ => String::new(),
|
||||
_ => "",
|
||||
},
|
||||
message_password: match error {
|
||||
SignUpError::PasswordsNotEqual => tr.t(Sentence::PasswordDontMatch),
|
||||
SignUpError::InvalidPassword => tr.tp(
|
||||
Sentence::InvalidPassword,
|
||||
&[Box::new(common::consts::MIN_PASSWORD_SIZE)],
|
||||
),
|
||||
_ => String::new(),
|
||||
SignUpError::InvalidPassword => invalid_password_mess,
|
||||
_ => "",
|
||||
},
|
||||
message: match error {
|
||||
SignUpError::UserAlreadyExists => tr.t(Sentence::EmailAlreadyTaken),
|
||||
SignUpError::DatabaseError => "Database error".to_string(),
|
||||
SignUpError::DatabaseError => tr.t(Sentence::DatabaseError),
|
||||
SignUpError::UnableSendEmail => tr.t(Sentence::UnableToSendEmail),
|
||||
_ => String::new(),
|
||||
_ => "",
|
||||
},
|
||||
tr,
|
||||
}
|
||||
|
|
@ -235,8 +236,8 @@ pub async fn sign_in_get(
|
|||
Ok(SignInFormTemplate {
|
||||
user,
|
||||
tr,
|
||||
email: String::new(),
|
||||
message: String::new(),
|
||||
email: "",
|
||||
message: "",
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -271,7 +272,7 @@ pub async fn sign_in_post(
|
|||
jar,
|
||||
SignInFormTemplate {
|
||||
user,
|
||||
email: form_data.email,
|
||||
email: &form_data.email,
|
||||
message: tr.t(Sentence::AccountMustBeValidatedFirst),
|
||||
tr,
|
||||
}
|
||||
|
|
@ -281,7 +282,7 @@ pub async fn sign_in_post(
|
|||
jar,
|
||||
SignInFormTemplate {
|
||||
user,
|
||||
email: form_data.email,
|
||||
email: &form_data.email,
|
||||
message: tr.t(Sentence::WrongEmailOrPassword),
|
||||
tr,
|
||||
}
|
||||
|
|
@ -326,9 +327,9 @@ pub async fn ask_reset_password_get(
|
|||
Ok(AskResetPasswordTemplate {
|
||||
user,
|
||||
tr,
|
||||
email: String::new(),
|
||||
message: String::new(),
|
||||
message_email: String::new(),
|
||||
email: "",
|
||||
message: "",
|
||||
message_email: "",
|
||||
}
|
||||
.into_response())
|
||||
}
|
||||
|
|
@ -364,10 +365,10 @@ pub async fn ask_reset_password_post(
|
|||
) -> Result<Response> {
|
||||
Ok(AskResetPasswordTemplate {
|
||||
user,
|
||||
email: email.to_string(),
|
||||
email,
|
||||
message_email: match error {
|
||||
AskResetPasswordError::InvalidEmail => tr.t(Sentence::InvalidEmail),
|
||||
_ => String::new(),
|
||||
_ => "",
|
||||
},
|
||||
message: match error {
|
||||
AskResetPasswordError::EmailAlreadyReset => {
|
||||
|
|
@ -376,7 +377,7 @@ pub async fn ask_reset_password_post(
|
|||
AskResetPasswordError::EmailUnknown => tr.t(Sentence::EmailUnknown),
|
||||
AskResetPasswordError::UnableSendEmail => tr.t(Sentence::UnableToSendResetEmail),
|
||||
AskResetPasswordError::DatabaseError => tr.t(Sentence::DatabaseError),
|
||||
_ => String::new(),
|
||||
_ => "",
|
||||
},
|
||||
tr,
|
||||
}
|
||||
|
|
@ -470,9 +471,9 @@ pub async fn reset_password_get(
|
|||
Ok(ResetPasswordTemplate {
|
||||
user,
|
||||
tr,
|
||||
reset_token: reset_token.to_string(),
|
||||
message: String::new(),
|
||||
message_password: String::new(),
|
||||
reset_token,
|
||||
message: "",
|
||||
message_password: "",
|
||||
}
|
||||
.into_response())
|
||||
} else {
|
||||
|
|
@ -510,21 +511,22 @@ pub async fn reset_password_post(
|
|||
user: Option<model::User>,
|
||||
tr: translation::Tr,
|
||||
) -> Result<Response> {
|
||||
let reset_password_mess = &tr.tp(
|
||||
Sentence::InvalidPassword,
|
||||
&[Box::new(common::consts::MIN_PASSWORD_SIZE)],
|
||||
);
|
||||
Ok(ResetPasswordTemplate {
|
||||
user,
|
||||
reset_token: form_data.reset_token.clone(),
|
||||
reset_token: &form_data.reset_token,
|
||||
message_password: match error {
|
||||
ResetPasswordError::PasswordsNotEqual => tr.t(Sentence::PasswordDontMatch),
|
||||
ResetPasswordError::InvalidPassword => tr.tp(
|
||||
Sentence::InvalidPassword,
|
||||
&[Box::new(common::consts::MIN_PASSWORD_SIZE)],
|
||||
),
|
||||
_ => String::new(),
|
||||
ResetPasswordError::InvalidPassword => reset_password_mess,
|
||||
_ => "",
|
||||
},
|
||||
message: match error {
|
||||
ResetPasswordError::TokenExpired => tr.t(Sentence::AskResetTokenExpired),
|
||||
ResetPasswordError::DatabaseError => tr.t(Sentence::DatabaseError),
|
||||
_ => String::new(),
|
||||
_ => "",
|
||||
},
|
||||
tr,
|
||||
}
|
||||
|
|
@ -571,12 +573,12 @@ pub async fn edit_user_get(
|
|||
) -> Response {
|
||||
if let Some(user) = user {
|
||||
ProfileTemplate {
|
||||
username: user.name.clone(),
|
||||
email: user.email.clone(),
|
||||
message: String::new(),
|
||||
message_email: String::new(),
|
||||
message_password: String::new(),
|
||||
user: Some(user),
|
||||
username: &user.name,
|
||||
email: &user.email,
|
||||
message: "",
|
||||
message_email: "",
|
||||
message_password: "",
|
||||
user: Some(user.clone()),
|
||||
tr,
|
||||
}
|
||||
.into_response()
|
||||
|
|
@ -592,6 +594,7 @@ pub struct EditUserForm {
|
|||
password_1: String,
|
||||
password_2: String,
|
||||
}
|
||||
|
||||
enum ProfileUpdateError {
|
||||
InvalidEmail,
|
||||
EmailAlreadyTaken,
|
||||
|
|
@ -618,27 +621,28 @@ pub async fn edit_user_post(
|
|||
user: model::User,
|
||||
tr: translation::Tr,
|
||||
) -> Result<Response> {
|
||||
let invalid_password_mess = &tr.tp(
|
||||
Sentence::InvalidPassword,
|
||||
&[Box::new(common::consts::MIN_PASSWORD_SIZE)],
|
||||
);
|
||||
Ok(ProfileTemplate {
|
||||
user: Some(user),
|
||||
username: form_data.name.clone(),
|
||||
email: form_data.email.clone(),
|
||||
username: &form_data.name,
|
||||
email: &form_data.email,
|
||||
message_email: match error {
|
||||
ProfileUpdateError::InvalidEmail => tr.t(Sentence::InvalidEmail),
|
||||
ProfileUpdateError::EmailAlreadyTaken => tr.t(Sentence::EmailAlreadyTaken),
|
||||
_ => String::new(),
|
||||
_ => "",
|
||||
},
|
||||
message_password: match error {
|
||||
ProfileUpdateError::PasswordsNotEqual => tr.t(Sentence::PasswordDontMatch),
|
||||
ProfileUpdateError::InvalidPassword => tr.tp(
|
||||
Sentence::InvalidPassword,
|
||||
&[Box::new(common::consts::MIN_PASSWORD_SIZE)],
|
||||
),
|
||||
_ => String::new(),
|
||||
ProfileUpdateError::InvalidPassword => invalid_password_mess,
|
||||
_ => "",
|
||||
},
|
||||
message: match error {
|
||||
ProfileUpdateError::DatabaseError => tr.t(Sentence::DatabaseError),
|
||||
ProfileUpdateError::UnableSendEmail => tr.t(Sentence::UnableToSendEmail),
|
||||
_ => String::new(),
|
||||
_ => "",
|
||||
},
|
||||
tr,
|
||||
}
|
||||
|
|
@ -666,7 +670,7 @@ pub async fn edit_user_post(
|
|||
};
|
||||
|
||||
let email_trimmed = form_data.email.trim();
|
||||
let message: String;
|
||||
let message: &str;
|
||||
|
||||
match connection
|
||||
.update_user(
|
||||
|
|
@ -725,11 +729,11 @@ pub async fn edit_user_post(
|
|||
|
||||
Ok(ProfileTemplate {
|
||||
user,
|
||||
username: form_data.name,
|
||||
email: form_data.email,
|
||||
username: &form_data.name,
|
||||
email: &form_data.email,
|
||||
message,
|
||||
message_email: String::new(),
|
||||
message_password: String::new(),
|
||||
message_email: "",
|
||||
message_password: "",
|
||||
tr,
|
||||
}
|
||||
.into_response())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue