public void OnAuthentication(AuthenticationContext filterContext) { string auth = GetCookie("Auth", filterContext); AbzHash abzHash = hashRepo.GetHash(auth); if (abzHash == null) { Succes = true; filterContext.Result = new HttpUnauthorizedResult(); } else { Succes = false; } }
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")); }
public ActionResult Index(int SelectedCustId = -1, int SelectedContractId = -1) { string auth = GetCookie("Auth"); AbzHash abzHash = hashRepo.GetHash(auth); string usr = abzHash.Email; if ((SelectedCustId > 0) && ((int)abzHash.CustID != SelectedCustId)) { abzHash.CustID = SelectedCustId; contract = repo.GetContract((int)abzHash.CustID); if (contract == null) { ContractID = 0; } else { ContractID = contract.ContractID; } abzHash.ContractID = ContractID; hashRepo.UpdateHash(abzHash); } else { if ((SelectedContractId > 0) && ((int)abzHash.ContractID != SelectedContractId)) { abzHash.ContractID = SelectedContractId; hashRepo.UpdateHash(abzHash); } } contract = repo.GetContract((int)abzHash.CustID); if (contract == null) { ContractID = 0; } else { ContractID = contract.ContractID; } Cust cust = db.Custs.Find((int)abzHash.CustID); contracts = repo.GetContracts((int)abzHash.CustID); ViewData["Contract"] = new SelectList(contracts, "ContractID", "Num", ContractID); IEnumerable <OrgView> orgView = repo.GetCust(usr); ViewData["Cust"] = new SelectList(orgView, "ID", "Txt", abzHash.CustID); ViewBag.MenuItem = "recv"; ViewBag.User = usr; BalanceRepository bl = new BalanceRepository(); ViewBag.customer = cust.SmalName; ViewBag.balance = bl.GetBalance(CustID, (int)abzHash.ContractID).ToString(); ViewBag.contractn = ""; Contract contractcc = db.Contracts.Find((int)abzHash.ContractID); if (contractcc != null) { ViewBag.contractn = "Договор № " + contractcc.Num; } SetCookie("custid", CustID.ToString()); SetCookie("contractid", abzHash.ContractID.ToString()); SetCookie("customer", ViewBag.customer); SetCookie("balance", ViewBag.balance); SetCookie("contract", ViewBag.contractn); return(View("Index", cust)); }