public async Task <Order> GetNew(AbzHash abzHash, int invoice) { Order order = new Order(); order.CustId = (int)abzHash.CustID; order.ContractId = abzHash.ContractID; order.email = abzHash.Email; order.insDate = DateTime.Now; if (invoice == 0) { order.DateExec = DateTime.Now.AddDays(1); order.Dat = DateTime.Now.AddDays(1); } else { order.DateExec = DateTime.Now; order.Dat = DateTime.Now; } order.AdresId = 1; order.Invoice = invoice; db.Orders.Add(order); await db.SaveChangesAsync(); return(order); }
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); int CustID; string auth = GetCookie("Auth"); if (!String.IsNullOrWhiteSpace(auth)) { dba = new ApplicationDbContext(); abzHash = dba.AbzHashs.Find(auth); if (abzHash.CustID != null) { CustID = (int)abzHash.CustID; } else { string usr = User.Identity.Name; CustID = db.UserAdmins.FirstOrDefault(u => u.Email == usr).CustID; abzHash.CustID = CustID; UpdateHash(abzHash); } Cust = db.Custs.FirstOrDefault(c => c.CustId == CustID); //ViewBag.cst = Cust.SmalName; //BalanceRepository bl = new BalanceRepository(); //ViewBag.sm = bl.GetBalance(CustID, (int)abzHash.ContractID); //Contract contract = db.Contracts.Find((int)abzHash.ContractID); //if (contract != null) // ViewBag.Cntr = "Договор № " + contract.Num; } }
public ActionResult Login(string returnUrl) { string auth = GetCookie("Auth"); if (!String.IsNullOrWhiteSpace(auth)) { ApplicationDbContext dba = new ApplicationDbContext(); AbzHash abzHash = dba.AbzHashs.Find(auth); if ((abzHash != null) & (abzHash.IP == HttpContext.Request.UserHostAddress)) { string Email = MyCrypto.DeShifrovka(abzHash.Email); string Password = MyCrypto.DeShifrovka(abzHash.Password); var result = SignInManager.PasswordSignIn(Email, Password, true, shouldLockout: false); return(RedirectToLocal(returnUrl)); } } //string Email = MyCrypto.DeShifrovka(GetCookie("MyAuth")); //string Password = MyCrypto.DeShifrovka(GetCookie("MyPWD")); //if (!String.IsNullOrWhiteSpace(Email) && !String.IsNullOrWhiteSpace(Password)) //{ // //FormsAuthentication.SetAuthCookie(cuc, true); // var result = SignInManager.PasswordSignIn(Email, Password, true, shouldLockout: false); // return RedirectToLocal(returnUrl); //} ViewBag.ReturnUrl = returnUrl; return(View()); }
public void UpdateHash(AbzHash hash) { dba = new ApplicationDbContext(); dba.AbzHashs.Add(hash); dba.Entry(abzHash).State = EntityState.Modified; dba.SaveChanges(); }
public void SetDafault(AbzHash hash) { CustRepository repo = new CustRepository(); string usr = hash.Email; hash.CustID = db.UserAdmins.FirstOrDefault(u => u.Email == usr).CustID; hash.ContractID = repo.GetContract((int)hash.CustID).ContractID; db.AbzHashes.Add(hash); db.SaveChanges(); }
//[UserAttribute] //[MyAuthAttribute] public ActionResult LoginPartial() { ViewBag.Login = "******"; string auth = GetCookie("Auth"); if (!String.IsNullOrWhiteSpace(auth)) { AbzContext db = new AbzContext(); AbzHash abzHash = db.AbzHashes.Find(auth); ViewBag.Login = abzHash.Email; } return(PartialView()); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { string auth = GetCookie("Auth", httpContext); if (!String.IsNullOrWhiteSpace(auth)) { AbzContext db = new AbzContext(); AbzHash abzHash = db.AbzHashes.Find(auth); if (abzHash != null) { return(true); } } return(false); }
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; } }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // Сбои при входе не приводят к блокированию учетной записи // Чтобы ошибки при вводе пароля инициировали блокирование учетной записи, замените на shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: //string cookieValue = MyCrypto.Shifrovka(model.Email); //SetCookie("MyAuth", cookieValue); //cookieValue = MyCrypto.Shifrovka(model.Password); //SetCookie("MyPWD", cookieValue); //Создание AbzHash. Хранение по новому 03.07.2019 ApplicationDbContext db = new ApplicationDbContext(); AbzHash abzHash = new AbzHash(); abzHash.AbzHashID = Guid.NewGuid().ToString(); SetCookie("Auth", abzHash.AbzHashID); abzHash.Email = MyCrypto.Shifrovka(model.Email); abzHash.Password = MyCrypto.Shifrovka(model.Password); abzHash.TerminationDate = DateTime.Now.AddDays(2); string ip = HttpContext.Request.UserHostAddress; abzHash.IP = ip; db.AbzHashs.Add(abzHash); db.SaveChanges(); return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Неудачная попытка входа."); return(View(model)); } }
//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 <OrderView> GetNew(AbzHash abzHash, int invoice) //public async Task<Order> GetNew(AbzHash abzHash,int invoice) { Order order = new Order(); order.CustId = (int)abzHash.CustID; order.ContractId = abzHash.ContractID; order.email = MyCrypto.DeShifrovka(abzHash.Email); order.insDate = DateTime.Now; order.DateExec = DateTime.Now.AddDays(1); order.Dat = DateTime.Now.AddDays(1); order.AdresId = 1; order.Invoice = invoice; db.Orders.Add(order); await db.SaveChangesAsync(); return(await GetChange(order.OrderId)); //return order; }
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 Cust GetCust(string auth) { int CustID; AbzHash abzHash = GetHash(auth); if (abzHash != null) { if (abzHash.CustID != null) { CustID = (int)abzHash.CustID; } else { CustRepository repo = new CustRepository(); string usr = abzHash.Email; CustID = db.UserAdmins.FirstOrDefault(u => u.Email == usr).CustID; abzHash.CustID = CustID; abzHash.ContractID = repo.GetContract(CustID).ContractID; UpdateHash(abzHash); } return(db.Custs.Find(CustID)); } return(null); }
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)); }
public void UpdateHash(AbzHash hash) { db.Entry(hash).State = EntityState.Modified; db.SaveChanges(); }