public bool IsEmailExist(string emailID) { using (Db_MawjoudEntities1 _Db = new Db_MawjoudEntities1()) { var v = _Db.Members.Where(a => a.Email == emailID).FirstOrDefault(); return(v != null); } }
public ActionResult Login(LoginViewModel login, string ReturnUrl = "") { string message = ""; using (Db_MawjoudEntities1 dc = new Db_MawjoudEntities1()) { var v = dc.Members.Where(a => a.Email == login.Email).FirstOrDefault(); if (v != null) { if (v.IsEmailVerified != true) { ViewBag.Message = "Please verify your email first"; return(View()); } if (string.Compare(login.Password, v.Password) == 0) { int timeout = login.RememberMe ? 525600 : 20; // 525600 min = 1 year var ticket = new FormsAuthenticationTicket(login.Email, login.RememberMe, timeout); string encrypted = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted); cookie.Expires = DateTime.Now.AddMinutes(timeout); cookie.HttpOnly = true; Response.Cookies.Add(cookie); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(RedirectToAction("about", "account")); } } else { message = "Mot de passe est incorrect"; } } else { message = "Mot de passe ou email invalide "; } } ViewBag.Message = message; return(View()); }
public ActionResult VerifyAccount(string id) { bool Status = false; using (Db_MawjoudEntities1 dc = new Db_MawjoudEntities1()) { dc.Configuration.ValidateOnSaveEnabled = false; // This line I have added here to avoid // Confirm password does not match issue on save changes var v = dc.Members.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault(); if (v != null) { v.IsEmailVerified = true; dc.SaveChanges(); Status = true; } else { ViewBag.Message = "Invalid Request"; } } ViewBag.Status = Status; return(View()); }
public GenericRepository(Db_MawjoudEntities1 DBEntity) { _DBEntity = DBEntity; _dbSet = _DBEntity.Set <Tbl_Entity>(); }
public ActionResult Register([Bind(Exclude = "IsEmailVerified,ActivationCode")] RegisterViewModel model) { bool Status = false; string message = ""; Members user = new Members(); user.MemberId = model.MemberId; user.Membercity = model.Membercity; user.LastName = model.LastName; user.IsEmailVerified = model.IsEmailVerified; user.IsActive = model.IsActive; user.FirstName = model.FristName; user.Email = model.Email; user.CreatedOn = model.CreatedOn; user.Memberphoto = model.Memberphoto; user.ModifiedOn = model.ModifiedOn; user.Password = model.Password; //Model validation if (ModelState.IsValid) { //Email is already exist #region var isExist = IsEmailExist(model.Email); if (isExist) { ModelState.AddModelError("EmailExist", "Email already exist"); return(View(model)); } #endregion #region Generate Activation code user.ActivationCode = Guid.NewGuid(); #endregion #region Password Hashing model.Password = Crypto.Hash(model.Password); model.ConfirmPassword = Crypto.Hash(model.ConfirmPassword); #endregion user.IsEmailVerified = false; #region Save to Database using (Db_MawjoudEntities1 dc = new Db_MawjoudEntities1()) { dc.Members.Add(user); dc.SaveChanges(); //Send Email to User SendVerificationLinkEmail(user.Email, user.ActivationCode.ToString()); message = "Registration successfully done. Account activation link " + " has been sent to your email id:" + user.Email; Status = true; } #endregion } else { message = "Invalid request"; } //Email is already Exist //Generate Activation Code //Password HAshing //Save data to Database //Send Email to user ViewBag.Message = message; ViewBag.Status = Status; return(View(model)); }