protected void btnUpdateLog_Click(object sender, EventArgs e) { if (Page.IsValid) { Account account = db.Accounts.SingleOrDefault(acc => acc.AccountID == accID); account.PassWord = StringUltils.MD5(txtPassNew.Text); db.SaveChanges(); ScriptManager.RegisterStartupScript(this, this.GetType(), "sweet", "sweetAlert('Success', 'Thay đổi mật khẩu thành công!', 'success');", true); } }
protected void cvPassOld_ServerValidate(object source, ServerValidateEventArgs args) { string po = StringUltils.MD5(txtPassOld.Text); Account account = db.Accounts.Where(acc => acc.AccountID == accID && acc.PassWord == po).SingleOrDefault(); if (account != null) { args.IsValid = true; } else { args.IsValid = false; } }
protected void btnSignup_Click(object sender, EventArgs e) { if (Page.IsValid) { Account account = new Account { UserName = txtEmailSu.Text, PassWord = StringUltils.MD5(txtPasswordSu.Text), RoleID = 3, Enabled = true }; String gioiTinh = ""; if (int.Parse(cbbSex.SelectedValue) == 1) { gioiTinh = "Nam"; } if (int.Parse(cbbSex.SelectedValue) == 2) { gioiTinh = "Nữ"; } Customer customer = new Customer { FullName = txtNameSu.Text, AccountID = account.AccountID, Email = txtEmailSu.Text, BirthDay = DateTime.ParseExact(txtBirthDay.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture), Address = txtDiaChi.Text, Sex = gioiTinh, Account = account }; using (DBEcommerceEntities db = new DBEcommerceEntities()) { db.Customers.Add(customer); db.SaveChanges(); } Response.Redirect("~/board.aspx?msg=1"); } }
protected void btnLogin_Click(object sender, EventArgs e) { using (DBEcommerceEntities db = new DBEcommerceEntities()) { string pass = StringUltils.MD5(txtPasswordLog.Text); var checkAccExist = db.Accounts.Where(acc => acc.UserName == txtEmailLog.Text).FirstOrDefault(); if (checkAccExist != null) { var account = db.Accounts.Where(acc => acc.UserName == txtEmailLog.Text && acc.PassWord == pass).FirstOrDefault(); if (account != null) { var checkEnable = db.Accounts.Where(acc => acc.UserName == txtEmailLog.Text && acc.PassWord == pass && acc.Enabled == true).FirstOrDefault(); if (checkEnable != null) { int role = checkEnable.Role.RoleID; if (role == 1) // admin { var employ = db.Employees.Where(emp => emp.AccountID == account.AccountID).FirstOrDefault(); Session["IsLogin"] = 1; Session["CurAd"] = "admin"; Session["CurEmp"] = employ; Response.Redirect("~/Admin/Report.aspx"); } else if (role == 2) // nhân viên { var employ = db.Employees.Where(emp => emp.AccountID == account.AccountID).FirstOrDefault(); if (employ != null) { Session["IsLogin"] = 1; Session["CurEmp"] = employ; Response.Redirect("~/Admin/Report.aspx"); } } else // khách hàng { var customer = db.Customers.Where(cus => cus.AccountID == account.AccountID).FirstOrDefault(); if (customer != null) // là khách hàng { Session["IsLogin"] = 1; Session["CurCus"] = customer; } } Session["Cart"] = new helpers.cCart(); if (cbKeep.Checked) { Response.Cookies["accID"].Value = checkEnable.AccountID.ToString(); Response.Cookies["accID"].Expires = DateTime.Now.AddDays(7); } string retUrl = Request.QueryString["retUrl"]; if (string.IsNullOrEmpty(retUrl)) { retUrl = "~/Default.aspx"; } Response.Redirect(retUrl); } else { lblMessLog.Text = "Tài khoản đã bị khóa"; } } else { lblMessLog.Text = "Mật khẩu không đúng"; } } else { lblMessLog.Text = "Tên tài khoản không tồn tại"; } } }