//public async Task<ActionResult> Login(Usr model, string returnUrl) public async Task <ActionResult> Login(Usr model, string rememberme) { AbzContext db = new AbzContext(); AbzHashRepo hashRepo = new AbzHashRepo(); if (!ModelState.IsValid) { return(View(model)); } Usr usr = db.Users.FirstOrDefault(u => u.Email == model.Email && u.Password == model.Password); if (usr == null) { return(View(model)); } if (rememberme == "true") { SetCookie("RememberMe", "true", 365); SetCookie("RememberUser", model.Email, 365); SetCookie("RememberPw", model.Password, 365); } else { SetCookie("RememberMe", "false", 365); DeleteCookie("RememberUser"); DeleteCookie("RememberPw"); } //Зарегить юзера, со значениями по умолчанию AbzHash abzHash = new AbzHash(); abzHash.AbzHashID = Guid.NewGuid().ToString(); abzHash.Email = model.Email; //abzHash.Password = MyCrypto.Shifrovka(model.Password); abzHash.UserId = usr.UserId; abzHash.TerminationDate = DateTime.Now.AddDays(2); string ip = HttpContext.Request.UserHostAddress; abzHash.IP = ip; hashRepo.SetDafault(abzHash); SetCookie("Auth", abzHash.AbzHashID); SetCookie("AuthUser", abzHash.Email); //return RedirectToLocal(returnUrl); return(RedirectToAction("Index", "Home")); }
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); ViewBag.AuthSuccess = false; db = new AbzContext(); hashRepo = new AbzHashRepo(); abzHash = hashRepo.GetHash(GetCookie("Auth").ToString()); if (abzHash != null) { Cust = db.Custs.Find((int)abzHash.CustID); CustID = (int)abzHash.CustID; UserID = abzHash.UserId; ViewBag.AuthSuccess = true; } }
public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } AbzHashRepo hashRepo = new AbzHashRepo(); string auth = GetCookie("Auth"); AbzHash abzHash = hashRepo.GetHash(auth); AbzContext db = new AbzContext(); Usr usr = db.Users.FirstOrDefault(u => u.Email == abzHash.Email); if ((usr != null) && (usr.Password == model.OldPassword)) { usr.Password = model.NewPassword; db.Entry(usr).State = EntityState.Modified; db.SaveChanges(); await EmailSend.EMailRegAsync(abzHash.Email, model.NewPassword); } return(RedirectToAction("Index", "Home")); }