Commit 8614ea22 authored by Daniel Brüning's avatar Daniel Brüning
Browse files

Added the functionality to enter street, zip and city on the profile page

parent 72dab875
......@@ -109,13 +109,19 @@ impl MedalConnection for Connection {
logincode = ?4,
firstname = ?5,
lastname = ?6,
grade = ?7 WHERE id = ?",
street = ?7,
zip = ?8,
city = ?9,
grade = ?10 WHERE id = ?",
&[&session.username,
&session.password,
&session.salt,
&session.logincode,
&session.firstname,
&session.lastname,
&session.street,
&session.zip,
&session.city,
&session.grade,
&session.id])
.unwrap();
......
......@@ -461,6 +461,9 @@ pub fn show_profile<T: MedalConnection>(conn: &T, session_token: String, user_id
None => {
data.insert("firstname".to_string(), to_json(&session.firstname));
data.insert("lastname".to_string(), to_json(&session.lastname));
data.insert("street".to_string(), to_json(&session.street));
data.insert("zip".to_string(), to_json(&session.zip));
data.insert("city".to_string(), to_json(&session.city));
data.insert(format!("sel{}", session.grade), to_json(&"selected"));
data.insert("logincode".to_string(), to_json(&session.logincode));
......@@ -490,6 +493,9 @@ pub fn show_profile<T: MedalConnection>(conn: &T, session_token: String, user_id
data.insert("firstname".to_string(), to_json(&user.firstname));
data.insert("lastname".to_string(), to_json(&user.lastname));
data.insert("street".to_string(), to_json(&session.street));
data.insert("zip".to_string(), to_json(&session.zip));
data.insert("city".to_string(), to_json(&session.city));
data.insert(format!("sel{}", user.grade), to_json(&"selected"));
data.insert("logincode".to_string(), to_json(&user.logincode));
......@@ -528,7 +534,9 @@ impl std::convert::Into<String> for ProfileStatus {
}
pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: String, user_id: Option<u32>, csrf_token: String,
firstname: String, lastname: String, password: String,
firstname: String, lastname: String,
street: String, zip: String, city: String,
password: String,
password_repeat: String, grade: u8)
-> MedalResult<ProfileStatus>
{
......@@ -543,6 +551,9 @@ pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: String, user_id
if session.firstname.as_ref() == Some(&firstname)
&& session.lastname.as_ref() == Some(&lastname)
&& session.street.as_ref() == Some(&street)
&& session.zip.as_ref() == Some(&zip)
&& session.city.as_ref() == Some(&city)
&& session.grade == grade
&& password == ""
&& password_repeat == ""
......@@ -570,6 +581,9 @@ pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: String, user_id
None => {
session.firstname = Some(firstname);
session.lastname = Some(lastname);
session.street = Some(street);
session.zip = Some(zip);
session.city = Some(city);
session.grade = grade;
if let Some((password, salt)) = password_salt {
......@@ -589,6 +603,9 @@ pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: String, user_id
user.firstname = Some(firstname);
user.lastname = Some(lastname);
user.street = Some(street);
user.zip = Some(zip);
user.city = Some(city);
user.grade = grade;
if let Some((password, salt)) = password_salt {
......
......@@ -494,11 +494,14 @@ fn profile(req: &mut Request) -> IronResult<Response> {
fn profile_post(req: &mut Request) -> IronResult<Response> {
let session_token = req.expect_session_token()?;
let (csrf_token, firstname, lastname, pwd, pwd_repeat, grade) = {
let (csrf_token, firstname, lastname, street, zip, city, pwd, pwd_repeat, grade) = {
let formdata = itry!(req.get_ref::<UrlEncodedBody>());
(iexpect!(formdata.get("csrftoken"))[0].to_owned(),
iexpect!(formdata.get("firstname"))[0].to_owned(),
iexpect!(formdata.get("lastname"))[0].to_owned(),
iexpect!(formdata.get("street"))[0].to_owned(),
iexpect!(formdata.get("zip"))[0].to_owned(),
iexpect!(formdata.get("city"))[0].to_owned(),
iexpect!(formdata.get("password"))[0].to_owned(),
iexpect!(formdata.get("password_repeat"))[0].to_owned(),
iexpect!(formdata.get("grade"))[0].parse::<u8>().unwrap_or(0))
......@@ -512,6 +515,9 @@ fn profile_post(req: &mut Request) -> IronResult<Response> {
csrf_token,
firstname,
lastname,
street,
zip,
city,
pwd,
pwd_repeat,
grade].aug(req)?;
......@@ -535,11 +541,14 @@ fn user(req: &mut Request) -> IronResult<Response> {
fn user_post(req: &mut Request) -> IronResult<Response> {
let user_id = req.expect_int::<u32>("userid")?;
let session_token = req.expect_session_token()?;
let (csrf_token, firstname, lastname, pwd, pwd_repeat, grade) = {
let (csrf_token, firstname, lastname, street, zip, city, pwd, pwd_repeat, grade) = {
let formdata = itry!(req.get_ref::<UrlEncodedBody>());
(iexpect!(formdata.get("csrftoken"))[0].to_owned(),
iexpect!(formdata.get("firstname"))[0].to_owned(),
iexpect!(formdata.get("lastname"))[0].to_owned(),
iexpect!(formdata.get("street"))[0].to_owned(),
iexpect!(formdata.get("zip"))[0].to_owned(),
iexpect!(formdata.get("city"))[0].to_owned(),
iexpect!(formdata.get("password"))[0].to_owned(),
iexpect!(formdata.get("password_repeat"))[0].to_owned(),
iexpect!(formdata.get("grade"))[0].parse::<u8>().unwrap_or(0))
......@@ -553,6 +562,9 @@ fn user_post(req: &mut Request) -> IronResult<Response> {
csrf_token,
firstname,
lastname,
street,
zip,
city,
pwd,
pwd_repeat,
grade].aug(req)?;
......
......@@ -20,6 +20,15 @@
<tr>
<td>Nachname:</td><td><input name="lastname" value="{{ lastname }}"></td>
</tr>
<tr>
<td>Straße und Hausnummer:</td><td><input name="street" value="{{ street }}"></td>
</tr>
<tr>
<td>Postleitzahl:</td><td><input name="zip" value="{{ zip }}"></td>
</tr>
<tr>
<td>Stadt:</td><td><input name="city" value="{{ city }}"></td>
</tr>
<tr>
<td>Jahrgangsstufe:</td><td>
<select name="grade">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment