aboutsummaryrefslogtreecommitdiffstats
path: root/src/models
diff options
context:
space:
mode:
Diffstat (limited to 'src/models')
-rw-r--r--src/models/user.rs36
1 files changed, 27 insertions, 9 deletions
diff --git a/src/models/user.rs b/src/models/user.rs
index 5b92f6d..537dfe6 100644
--- a/src/models/user.rs
+++ b/src/models/user.rs
@@ -12,15 +12,6 @@ pub struct User {
pub password: String
}
-#[derive(Default, FromForm, Insertable)]
-#[table_name="users"]
-pub struct NewUser {
- pub username: String,
- pub realname: Option<String>,
- pub email: Option<String>,
- pub password: String,
-}
-
impl User {
pub fn by_id(user_id: i32, conn: utils::DbConn) -> QueryResult<User> {
use schema::users::dsl::*;
@@ -41,4 +32,31 @@ impl User {
.values(new_user)
.get_result(&*conn)
}
+
+ pub fn realname(&self) -> String {
+ self.realname.as_ref().unwrap_or(&String::new()).clone()
+ }
+
+ pub fn email(&self) -> String {
+ self.email.as_ref().unwrap_or(&String::new()).clone()
+ }
+}
+
+#[derive(Default, FromForm, Insertable)]
+#[table_name="users"]
+pub struct NewUser {
+ pub username: String,
+ pub realname: Option<String>,
+ pub email: Option<String>,
+ pub password: String,
+}
+
+impl NewUser {
+ pub fn realname(&self) -> String {
+ self.realname.as_ref().unwrap_or(&String::new()).clone()
+ }
+
+ pub fn email(&self) -> String {
+ self.email.as_ref().unwrap_or(&String::new()).clone()
+ }
}