-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a3ca58
commit 593e96c
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// src/users.rs | ||
|
||
#![forbid(unsafe_code)] | ||
|
||
use bville_recycle::rocket; | ||
use regex::Regex; | ||
|
||
pub struct Username { | ||
// Username may only contain uppercase letters, lowercase letters, numbers, and underscores | ||
pub username: String, | ||
} | ||
|
||
impl Username { | ||
pub fn new(username: String) -> Result<Username, &'static str> { | ||
if username.chars().all(|c| c.is_alphanumeric() || c == '_') { | ||
if username.len() <= 32 { | ||
Ok(Username { username }) | ||
} else { | ||
Err("Username must be 32 characters or less") | ||
} | ||
} else { | ||
Err("Username may only contain uppercase letters, lowercase letters, numbers, and underscores") | ||
} | ||
} | ||
} | ||
|
||
pub struct Email { | ||
// Email must be a valid email address | ||
pub email: String, | ||
} | ||
|
||
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(); | ||
|
||
if email_regex.is_match(email) { | ||
Ok(Self { | ||
email: email.to_string(), | ||
}) | ||
} else { | ||
Err(format!("'{}' is not a valid email address", email)) | ||
} | ||
} | ||
} | ||
|
||
pub struct Password { | ||
// Password must be at least 16 characters long | ||
pub password: String, | ||
} | ||
|
||
impl Password { | ||
pub fn new(password: String) -> Result<Self, &'static str> { | ||
if password.len() >= 16 { | ||
if password.contains() { | ||
|
||
} else { | ||
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") | ||
} | ||
} | ||
} | ||
|
||
pub struct User { | ||
pub id: u32, | ||
pub username: Username, | ||
pub email: Email, | ||
pub password: Password, | ||
pub second_factor: Vec<u8>, | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,9 @@ | |
|
||
#![forbid(unsafe_code)] | ||
|
||
use bville_recycle::rocket; | ||
|
||
#[tokio::test] | ||
async fn test_create_user() { | ||
|
||
} |