private bool isMemberExist(string username) { Tbl_Member_Password isExist = AccountContent.Tbl_Member_Passwords.Where(c => c.userid == username).FirstOrDefault(); if (isExist != null) { return(true); } return(false); }
public ActionResult Changepass(FormCollection collection) { string passwordo = collection["passwordo"].ToString(); string password = collection["password"].ToString(); string passwordx = collection["passwordx"].ToString(); if (passwordo == "" || password == "" || passwordx == "") { TempData["erorprofile"] = "Vui lòng nhập đủ thông tin."; return(View("Changepass")); } if (password != passwordx) { TempData["erorprofile"] = "Mật khẩu mới phải nhập trùng nhau."; return(View("Changepass")); } else if (passwordx.Length < 6) { TempData["erorprofile"] = "Mật khẩu mới phải lớn hơn 6 kí tự."; return(View("Changepass")); } passwordo = Common.GetMD5(collection["passwordo"].ToString()); password = Common.GetMD5(collection["password"].ToString()); passwordx = Common.GetMD5(collection["passwordx"].ToString()); _9d_user item = AccountContent._9d_users.Where(c => c.user_name == Session["login"].ToString()).FirstOrDefault(); if (item.password != passwordo) { TempData["erorprofile"] = "Bạn đã nhập sai mật khẩu cũ, vui lòng nhập lại."; return(View("Changepass")); } item.password = passwordx; try { AccountContent.SubmitChanges(); Tbl_Member_Password it = AccountContent.Tbl_Member_Passwords.Where(c => c.userid == Session["login"].ToString()).FirstOrDefault(); it.userpassword = passwordx; TempData["erorprofile"] = null; TempData["successprofile"] = "Chúc mừng, mật khẩu của bạn đã được cập nhật."; AccountContent.SubmitChanges(); return(View("Changepass")); } catch (Exception) { throw; } return(View("Changepass")); }
public ActionResult Signup(FormCollection collection) { string username = collection["name"].ToString(); string password = collection["password"].ToString(); string passwordx = collection["passwordx"].ToString(); string email = collection["email"].ToString(); string telephone = collection["sodienthoai"].ToString(); string sex = collection["option"].ToString(); string address = collection["address"].ToString(); if (username.Trim() == string.Empty || password.Trim() == string.Empty || telephone.Trim() == string.Empty || passwordx.Trim() == string.Empty || email.Trim() == string.Empty || address.Trim() == string.Empty) { TempData["errorsignup"] = "Vui lòng nhập đầy đủ thông tin đăng ký, password phải lớn hơn 6 ký tự."; return(RedirectToAction("Signup", "Account")); } if (username.Trim().Length < 5) { TempData["errorsignup"] = "Vui lòng nhập tài khoản đăng nhập phải lớn hơn 6 kí tự."; return(RedirectToAction("Signup", "Account")); } if (password.Trim().Length < 5) { TempData["errorsignup"] = "Vui lòng nhập password phải lớn hơn 6 kí tự."; return(RedirectToAction("Signup", "Account")); } if (password != passwordx) { TempData["errorsignup"] = "Vui lòng nhập mật khẩu và xác nhận mật khẩu phải trùng nhau."; return(RedirectToAction("Signup", "Account")); } if (!isMemberExist(username)) { Tbl_Member_Password adduser = new Tbl_Member_Password(); adduser.userid = username; adduser.userpassword = Common.GetMD5(password); AccountContent.Tbl_Member_Passwords.InsertOnSubmit(adduser); try { AccountContent.SubmitChanges(); } catch (Exception) { TempData["errorsignup"] = "Có lỗi sảy ra vui lòng đăng ký lại."; return(RedirectToAction("Signup", "Account")); } _9d_user user = new _9d_user(); user.user_name = username.Trim(); user.password = Common.GetMD5(password); user.email = email.Trim(); user.created_at = DateTime.Now; user.telephone = telephone; user.balance = 0; user.address = address.Trim(); user.created_by = "Admin"; user.delete_flag = false; user.isActivate = true; user.ActivateCode = "FSGJTB45BDERT"; user.level = 1; user.totalpost = 0; AccountContent._9d_users.InsertOnSubmit(user); try { AccountContent.SubmitChanges(); string a = ""; } catch (Exception) { return(RedirectToAction("Signup", "Account")); } TempData["errorlogin"] = null; TempData["registerSuccess"] = "Đăng ký thành công, bạn hãy đăng nhập để vào trang chủ tham gia các sự kiện đặc biệt."; return(RedirectToAction("Index", "Account")); } else { TempData["errorsignup"] = "Tài khoản đã tồn tại, vui lòng đăng ký tài khoản mới."; return(RedirectToAction("Signup", "Account")); } }