//Updaterar infon för en user public void updateUserInfo(anvandare user, string userID) { //Create a connection SqlConnection conn = new SqlConnection(connStr); //The procedure I want to call SqlCommand cmd = new SqlCommand("usp_updateUserInfo", conn); //Command type I want to execute cmd.CommandType = CommandType.StoredProcedure; try { conn.Open(); cmd.Parameters.AddWithValue("@personID", userID); cmd.Parameters.AddWithValue("@fornamn", user.FirstName); cmd.Parameters.AddWithValue("@efternamn", user.LastName); cmd.Parameters.AddWithValue("@mail", user.Epost); cmd.Parameters.AddWithValue("@personnr", user.ssn); cmd.Parameters.AddWithValue("@nyhetsbrev", user.newsletter); cmd.Parameters.AddWithValue("@tarfaktura", user.faktura); cmd.ExecuteScalar(); } catch { throw; } finally { cmd.Dispose(); conn.Close(); conn.Dispose(); } }
//Byter ut lösenordet för en användare public string RestorePassword(anvandare a) { // Create a connection SqlConnection conn = new SqlConnection(connStr); // Name of the Procedure I want to call SqlCommand cmd = new SqlCommand("usp_RestorePassword", conn); // Type of commad I want to execute cmd.CommandType = CommandType.StoredProcedure; try { // Open the connection to the database conn.Open(); // Insert the Parameter to the procedure cmd.Parameters.AddWithValue("@mail", a.Epost); cmd.Parameters.AddWithValue("@losenord", a.Password); // Execute the procedure and return an integer return(cmd.ExecuteScalar().ToString()); } catch { // If error throw; } finally { // Close and dispose all connections to the databse cmd.Dispose(); conn.Close(); conn.Dispose(); } }
//Hämtar användarens info och skriver ut den private void GetUserData() { BusinessDAL bDAL = new BusinessDAL(); anvandare user = new anvandare(); user = bDAL.getUserData(Session["userid"].ToString()); tbxFornamn.Text = user.FirstName; tbxEfternamn.Text = user.LastName; tbxMail.Text = user.Epost; tbxSSN.Text = user.ssn; if (user.faktura == "False") { cbxFaktura.Checked = false; } else { cbxFaktura.Checked = true; } if (user.newsletter == "False") { cbxNewsLetter.Checked = false; } else { cbxNewsLetter.Checked = true; } }
//Byter lösenord för den givna användaren protected void btnBytLosen_Click(object sender, EventArgs e) { BusinessDAL bd = new BusinessDAL(); anvandare anv = new anvandare(); string newPassword; anv.Epost = tbEpost.Text.ToString(); anv.Password = tbpw.Text.ToString(); newPassword = bd.RestorePassword(anv); Response.Redirect("login.aspx"); }
//Lägger in en ny användare i databasen ifall allt går igenom validering protected void btnRegistrera_Click(object sender, EventArgs e) { string newUserId; BusinessDAL bd = new BusinessDAL(); anvandare anv = new anvandare(); anv.FirstName = tb_FaMname.Text.ToString(); anv.LastName = tb_lname.Text.ToString(); anv.Epost = tb_email.Text.ToString(); anv.ssn = tb_ssn.Text.ToString(); anv.Password = tb_pw.Text.ToString(); anv.newsletter = cb_newsletter.Text.ToString(); if (cvPassword.IsValid && cb_avtal.Checked) { newUserId = bd.CreateUser(anv); Response.Redirect("login.aspx"); } }
//Hämtar info för en användare public anvandare getUserData(string userID) { anvandare user = new anvandare(); //Create a connection SqlConnection conn = new SqlConnection(connStr); //The procedure I want to call SqlCommand cmd = new SqlCommand("usp_getUserInfo", conn); //Command type I want to execute cmd.CommandType = CommandType.StoredProcedure; try { conn.Open(); cmd.Parameters.AddWithValue("@personid", userID); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { user.FirstName = reader["fornamn"].ToString(); user.LastName = reader["efternamn"].ToString(); user.ssn = reader["personnr"].ToString(); user.Epost = reader["mail"].ToString(); user.faktura = reader["tarFaktura"].ToString(); user.newsletter = reader["nyhetsbrev"].ToString(); } return(user); } catch { throw; } finally { cmd.Dispose(); conn.Close(); conn.Dispose(); } }
protected void btnSaveInfo_Click(object sender, EventArgs e) { btnEditinfo.Visible = true; btnCancelEdit.Visible = false; btnSaveinfo.Visible = false; tbxFornamn.Enabled = false; tbxEfternamn.Enabled = false; tbxMail.Enabled = false; tbxSSN.Enabled = false; cbxFaktura.Enabled = false; cbxNewsLetter.Enabled = false; BusinessDAL bDAL = new BusinessDAL(); anvandare updatedUser = new anvandare(); updatedUser.Epost = tbxMail.Text; updatedUser.FirstName = tbxFornamn.Text; updatedUser.LastName = tbxEfternamn.Text; updatedUser.ssn = tbxSSN.Text; if (cbxNewsLetter.Checked) { updatedUser.newsletter = "1"; } else { updatedUser.newsletter = "0"; } if (cbxFaktura.Checked) { updatedUser.faktura = "1"; } else { updatedUser.faktura = "0"; } bDAL.updateUserInfo(updatedUser, Session["userid"].ToString()); GetUserData(); }
//Authenticatar dina inloggningsuppgifter protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { BusinessDAL bd = new BusinessDAL(); anvandare a = new anvandare(); string sUserId = ""; a.Epost = Login1.UserName.ToString(); a.Password = Login1.Password.ToString(); sUserId = bd.LogIn(a); if (sUserId.Length > 1) { Session.Add("userId", sUserId); e.Authenticated = true; Session["userid"].ToString(); Response.Redirect("min_profil.aspx"); } else { e.Authenticated = false; Response.Redirect("login.aspx"); Page.Controls.Add(new LiteralControl("<p>New<br />Line</p>")); } }