Confirm password
This commit is contained in:
parent
6975c36222
commit
d8ecd274ff
|
@ -12,6 +12,8 @@ pub struct UserSignUp {
|
|||
pub username: String,
|
||||
#[validate(length(min = 8, max = 128), custom = "validate_password")]
|
||||
pub password: String,
|
||||
#[validate(must_match = "password")]
|
||||
pub password_confirmation: String,
|
||||
}
|
||||
|
||||
fn validate_username(value: &String) -> Result<(), ValidationError> {
|
||||
|
|
|
@ -9,6 +9,7 @@ mod forms {
|
|||
let form = forms::UserSignUp {
|
||||
username: "kotovalexarian".to_string(),
|
||||
password: "q1w2e3r4t5y6".to_string(),
|
||||
password_confirmation: "q1w2e3r4t5y6".to_string(),
|
||||
};
|
||||
|
||||
assert!(matches!(form.validate(), Ok(_)));
|
||||
|
@ -19,6 +20,7 @@ mod forms {
|
|||
let form = forms::UserSignUp {
|
||||
username: "".to_string(),
|
||||
password: "q1w2e3r4t5y6".to_string(),
|
||||
password_confirmation: "q1w2e3r4t5y6".to_string(),
|
||||
};
|
||||
|
||||
assert!(matches!(form.validate(), Err(_)));
|
||||
|
@ -29,6 +31,7 @@ mod forms {
|
|||
let form = forms::UserSignUp {
|
||||
username: " ".to_string(),
|
||||
password: "q1w2e3r4t5y6".to_string(),
|
||||
password_confirmation: "q1w2e3r4t5y6".to_string(),
|
||||
};
|
||||
|
||||
assert!(matches!(form.validate(), Err(_)));
|
||||
|
@ -39,6 +42,7 @@ mod forms {
|
|||
let form = forms::UserSignUp {
|
||||
username: "foo".to_string(),
|
||||
password: "q1w2e3r4t5y6".to_string(),
|
||||
password_confirmation: "q1w2e3r4t5y6".to_string(),
|
||||
};
|
||||
|
||||
assert!(matches!(form.validate(), Err(_)));
|
||||
|
@ -49,6 +53,7 @@ mod forms {
|
|||
let form = forms::UserSignUp {
|
||||
username: "kotovalexarian".to_string(),
|
||||
password: "".to_string(),
|
||||
password_confirmation: "".to_string(),
|
||||
};
|
||||
|
||||
assert!(matches!(form.validate(), Err(_)));
|
||||
|
@ -59,6 +64,7 @@ mod forms {
|
|||
let form = forms::UserSignUp {
|
||||
username: "kotovalexarian".to_string(),
|
||||
password: " ".to_string(),
|
||||
password_confirmation: " ".to_string(),
|
||||
};
|
||||
|
||||
assert!(matches!(form.validate(), Err(_)));
|
||||
|
@ -69,6 +75,18 @@ mod forms {
|
|||
let form = forms::UserSignUp {
|
||||
username: "kotovalexarian".to_string(),
|
||||
password: "1234567".to_string(),
|
||||
password_confirmation: "1234567".to_string(),
|
||||
};
|
||||
|
||||
assert!(matches!(form.validate(), Err(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn user_sign_up_with_invalid_password_confirmation() {
|
||||
let form = forms::UserSignUp {
|
||||
username: "kotovalexarian".to_string(),
|
||||
password: "q1w2e3r4t5y6".to_string(),
|
||||
password_confirmation: "q1w2e3r4t5y6aaa".to_string(),
|
||||
};
|
||||
|
||||
assert!(matches!(form.validate(), Err(_)));
|
||||
|
|
|
@ -8,7 +8,7 @@ mod requests {
|
|||
|
||||
fn client() -> Client {
|
||||
let config = config::Config::default().unwrap();
|
||||
let rocket = web::rocket(config);
|
||||
let rocket = web::rocket(config).unwrap();
|
||||
Client::new(rocket).unwrap()
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,11 @@
|
|||
<input id="password" name="password" type="password" class="form-control" placeholder="Password"/>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password_confirmation">Password confirmation</label>
|
||||
<input id="password_confirmation" name="password_confirmation" type="password" class="form-control" placeholder="Password confirmation"/>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">
|
||||
Sign Up
|
||||
</button>
|
||||
|
|
Reference in New Issue