commit 9144905b406ab6f789a455c884385b35e73bf72d
parent 4dd1a854bcf5b3c010dd6577fb84882532894634
Author: Jackson G. Kaindume <seestem@merely.tech>
Date: Sun, 21 Aug 2022 13:43:52 +0200
rename accounts.rs to account.rs
Diffstat:
2 files changed, 37 insertions(+), 19 deletions(-)
diff --git a/src/account.rs b/src/account.rs
@@ -0,0 +1,37 @@
+use crate::validate::{Validate, ValidationError};
+
+/// An account
+pub struct Account {
+ /// The username of the user, also used as an unique identifier
+ pub username: String,
+ /// The email address the user
+ pub email: String,
+ /// The password of the user
+ pub password: String,
+}
+
+impl Account {
+ pub fn new(username: &str, email: &str, password: &str) -> Result<Self, ValidationError> {
+ if !Validate::username(username) {
+ return Err(ValidationError::Username);
+ }
+
+ if !Validate::email(email) {
+ return Err(ValidationError::Email);
+ }
+
+ // TODO: email verification code
+
+ if !Validate::password(password) {
+ return Err(ValidationError::Email);
+ }
+
+ // TODO: database registration code
+
+ Ok(Account {
+ username: username.to_string(),
+ email: email.to_string(),
+ password: password.to_string(),
+ })
+ }
+}
diff --git a/src/accounts.rs b/src/accounts.rs
@@ -1,19 +0,0 @@
-use crate::validator::Validator;
-
-/// An account that consists on of username, emails and password
-pub struct UsernameEmailPassword {
- /// The username of the user, also used as an unique identifier
- pub username: String,
- /// The email address the user
- email: String,
- /// The password of the user
- pub password: String,
-}
-
-impl UsernameEmailPassword {
- pub fn new(username: &str, email: &str, password: &str) -> Result<(), ()> {
- if Validator::username(username) {}
-
- Ok(())
- }
-}