Skip to content

Commit

Permalink
Clean up some compile errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanMcCormickJr committed Dec 12, 2024
1 parent 593e96c commit ad42894
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 12 additions & 11 deletions src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#![forbid(unsafe_code)]

use bville_recycle::rocket;
use regex::Regex;

pub struct Username {
Expand All @@ -12,7 +11,7 @@ pub struct Username {

impl Username {
pub fn new(username: String) -> Result<Username, &'static str> {
if username.chars().all(|c| c.is_alphanumeric() || c == '_') {
if username.chars().all(|c: char| c.is_alphanumeric() || c == '_') {
if username.len() <= 32 {
Ok(Username { username })
} else {
Expand All @@ -31,9 +30,9 @@ pub struct Email {

impl Email {
pub fn new(email: String) -> Result<Self, String> {
let email_regex = Regex::new(r"^[a-zA-Z\u0080-\uFFFF0-9._%+-]+@[a-zA-Z\u0080-\uFFFF0-9.-]+\.[a-zA-Z\u0080-\uFFFF]{1,}$").unwrap();
let email_regex: Regex = Regex::new(r"^[a-zA-Z\u0080-\uFFFF0-9._%+-]+@[a-zA-Z\u0080-\uFFFF0-9.-]+\.[a-zA-Z\u0080-\uFFFF]{1,}$").unwrap();

if email_regex.is_match(email) {
if email_regex.is_match(&email) {
Ok(Self {
email: email.to_string(),
})
Expand All @@ -51,16 +50,18 @@ pub struct Password {
impl Password {
pub fn new(password: String) -> Result<Self, &'static str> {
if password.len() >= 16 {
if password.contains() {

if password.chars().any(|c: char| c.is_uppercase()) &&
password.chars().any(|c: char| c.is_lowercase()) &&
password.chars().any(|c: char| c.is_digit(10)) &&
password.chars().any(|c: char| !c.is_alphanumeric()) {
return Ok(Self {
password: password.to_string(),
});
} else {
Err("Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character")
return Err("Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character");
}
Ok(Self {
password: password.to_string(),
})
} else {
Err("Password must be at least 16 characters long")
return Err("Password must be at least 16 characters long")
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions tests/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#![forbid(unsafe_code)]

use bville_recycle::rocket;

#[tokio::test]
async fn test_create_user() {

Expand Down

0 comments on commit ad42894

Please sign in to comment.