diff options
-rw-r--r-- | src/models/user.rs | 36 | ||||
-rw-r--r-- | templates/new_user.html | 4 |
2 files changed, 29 insertions, 11 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() + } } diff --git a/templates/new_user.html b/templates/new_user.html index 29aa20f..c64d9ad 100644 --- a/templates/new_user.html +++ b/templates/new_user.html @@ -7,12 +7,12 @@ <div class="field"> <label>Real Name:</label> - <input type="text" name="realname" value="{{ realname() }}"> + <input type="text" name="realname" value="{{ user.realname() }}"> </div> <div class="field"> <label>Email:</label> - <input type="text" name="email" value="{{ email() }}"> + <input type="text" name="email" value="{{ user.email() }}"> </div> <div class="field"> |