// update user data after changing some info public void UpdateUserData(AccountModel model) { MySqlConnection connection = model.mSqlConnection.connection; MySqlCommand cmd; connection.Open(); try { cmd = connection.CreateCommand(); cmd.CommandText = "UPDATE Users "+ "SET firstName=@firstname, lastName=@lastName,dayOfBirth=@dayOfBirth,monthOfBirth=@monthOfBirth,yearOfBirth=@yearOfBirth," + "phone=@phone ,country=@country, city=@city " + "WHERE username LIKE @username"; cmd.Parameters.AddWithValue("username",model.username); cmd.Parameters.AddWithValue("firstName", model.firstName); cmd.Parameters.AddWithValue("lastName", model.lastName); cmd.Parameters.AddWithValue("country", model.country); cmd.Parameters.AddWithValue("city", model.city); cmd.Parameters.AddWithValue("dayOfBirth", model.dayOfBirth); cmd.Parameters.AddWithValue("monthOfBirth", model.monthOfBirth); cmd.Parameters.AddWithValue("yearOfBirth", model.yearOfBirth); cmd.Parameters.AddWithValue("phone", model.phone); cmd.ExecuteNonQuery(); } catch(Exception) { throw; } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } }
public ActionResult SignUpContinue(AccountModel model) { Session.Add("username",model.username); var data = new ViewDataDictionary { { "username", model.username} }; // make DB connection // fetch 'users' table // put user data in the table string userCreationResult = CreateNewUser(model); if (userCreationResult == "success") { ViewData.Add("data", data); return View(); }else { return RedirectToAction("Index","Home", userCreationResult); } }
public ActionResult Register(AccountModel model) { //check data // upload user data into DB UpdateUserData(model); // make redirect to personal page with map return RedirectToAction("Map","Map"); // if failed, redisplay "signUpContinue" page }
public string CreateNewUser(AccountModel model) { string result; model.mSqlConnection = new ConnectionModel(); MySqlConnection connection = model.mSqlConnection.makeConnection(); MySqlCommand cmd; try { connection.Open(); } catch (Exception e) { throw e; } result = userIsNew(connection, model.email, model.username); if (result!= "userIsNew") // if username or email is taken return result; try { cmd = connection.CreateCommand(); cmd.CommandText = "INSERT INTO Users(email,username) VALUES(@email,@username)"; cmd.Parameters.AddWithValue("email", model.email); cmd.Parameters.AddWithValue("username", model.username); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } try { cmd = connection.CreateCommand(); cmd.CommandText = "INSERT INTO Usernames(email,username) VALUES(@email,@username)"; cmd.Parameters.AddWithValue("email", model.email); cmd.Parameters.AddWithValue("username", model.username); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } try // create password hash and insert it in DB { cmd = connection.CreateCommand(); cmd.CommandText = "INSERT INTO Passwords(username,password) VALUES(@username, @password)"; cmd.Parameters.AddWithValue("username", model.username); cmd.Parameters.AddWithValue("password", GetMD5Hash(model.password)); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } return "success"; }