aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-07-31 16:48:52 +0200
committerHarald Eilertsen <haraldei@anduin.net>2018-07-31 16:48:52 +0200
commit6a5f1bd90e46c2bea7be73b512d5202954900cad (patch)
treeb035ffcea7429b3c391ba69937c3c39c536b5e17 /src
parentaadb5b5a08a3d12211bf5c5286d0b35fe80c79d5 (diff)
downloadrocket-blog-6a5f1bd90e46c2bea7be73b512d5202954900cad.tar.gz
rocket-blog-6a5f1bd90e46c2bea7be73b512d5202954900cad.tar.bz2
rocket-blog-6a5f1bd90e46c2bea7be73b512d5202954900cad.zip
Move methods to get display values into user model.
Diffstat (limited to 'src')
-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()
+ }
}