changelog and Config::email &str input

This commit is contained in:
Aravinth Manivannan 2021-04-13 23:11:34 +05:30
parent 99c1769430
commit 11b490b78c
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
6 changed files with 34 additions and 20 deletions

20
CHANGELOG.md Normal file
View file

@ -0,0 +1,20 @@
## 0.2.1
### Changed:
-`Config::email` now takes a `&str` instead of `Option<&str>`
## 0.2.0
### Added
- minimum and maximum password length
## 0.1.0
### Added:
- password configuration
- UsernameCaseMapped filter
- Abusive words filter
- filter for words that might cause security issues

View file

@ -26,4 +26,4 @@ validator = { version = "0.13.0", features = ["derive"]}
lazy_static = "1.4.0"
regex = { version = "1.3.9", features = [ "perf-inline", "perf-dfa", "perf-literal", "perf-cache", "perf"]}
rand = "0.8.0"
derive_builder = "0.9"
derive_builder = "0.10"

View file

@ -23,7 +23,7 @@ fn main() {
let hash = config.password(password).unwrap();
// email validation
config.email(Some("batman@we.net")).unwrap();
config.email("batman@we.net").unwrap();
// process username
let username = config.username("Realaravinth").unwrap(); // process username

View file

@ -10,7 +10,7 @@ fn main() {
let password = "ironmansucks";
// email validation
config.email(Some("batman@we.net")).unwrap();
config.email("batman@we.net").unwrap();
// process username
let username = config.username("Realaravinth").unwrap(); // process username

View file

@ -56,9 +56,9 @@ impl Default for PasswordPolicy {
}
#[derive(Validate)]
struct Email {
struct Email<'a> {
#[validate(email)]
pub email: String,
pub email: &'a str,
}
impl Default for Config {
@ -84,14 +84,11 @@ impl Config {
}
/// Checks if input is an email
pub fn email(&self, email: Option<&str>) -> CredsResult<()> {
if let Some(email) = email {
let email = Email {
email: email.trim().to_owned(),
};
email.validate()?;
}
Ok(())
pub fn email(&self, email: &str) -> CredsResult<()> {
let email = Email {
email: email.trim(),
};
Ok(email.validate()?)
}
fn validate_username(&self, username: &str) -> CredsResult<()> {
@ -179,10 +176,7 @@ mod tests {
.build()
.unwrap();
assert_eq!(
config.email(Some("sdfasdf".into())),
Err(CredsError::NotAnEmail)
);
assert_eq!(config.email("sdfasdf".into()), Err(CredsError::NotAnEmail));
}
#[test]
@ -190,7 +184,7 @@ mod tests {
let password = "somepassword";
let config = Config::default();
config.email(Some("batman@we.net")).unwrap();
config.email("batman@we.net").unwrap();
let username = config.username("Realaravinth").unwrap();
let hash = config.password(password).unwrap();

View file

@ -16,7 +16,7 @@
//! let hash = config.password(password).unwrap();
//!
//! // email validation
//! config.email(Some("batman@we.net")).unwrap();
//! config.email("batman@we.net").unwrap();
//!
//! // process username
//! let username = config.username("Realaravinth").unwrap(); // process username
@ -48,7 +48,7 @@
//! let hash = config.password(password).unwrap();
//!
//! // email validation
//! config.email(Some("batman@we.net")).unwrap();
//! config.email("batman@we.net").unwrap();
//!
//! // process username
//! let username = config.username("Realaravinth").unwrap(); // process username