public IHttpResponse Login(PostLoginViewModel model) { string hashedPassword = this.hashService.Hash(model.Password); if (!(this.DbContext.Users.Any(user => (user.Username == model.Username.Trim()) && user.Password == hashedPassword))) { return(this.BadRequestError("Invalid user information!")); } else { model.Role = this.DbContext.Users.First(u => u.Username == model.Username.Trim()).Role; HttpCookie cookie = new HttpCookie(AuthenticationCookieKey, this.UserCookieService.EncryptString(model.Username)); this.Request.Cookies.Add(cookie); this.Response.Cookies.Add(cookie); if (model.Role == Role.Admin) { return(this.Redirect("/")); } else { return(this.Redirect("/")); } } }
public IHttpResponse Login(PostLoginViewModel model) { string hashedPassword = this.hashService.Hash(model.Password); if (!(this.DbContext.Users.Any(user => (user.Email == model.Email.Trim()) && user.Password == hashedPassword)) || model.Email.Trim().Length < 3 || model.Password.Trim().Length < 3) { return(this.BadRequestErrorWithView("Invalid user information!")); } else { var user = this.DbContext.Users.First(u => u.Email == model.Email); //Adding cookie var mvcUser = new MvcUserInfo { Username = user.FullName, Role = user.Role.ToString() }; var cookieContent = this.UserCookieService.GetUserCookie(mvcUser); HttpCookie cookie = new HttpCookie(AuthenticationCookieKey, cookieContent); this.Request.Cookies.Add(cookie); this.Response.Cookies.Add(cookie); } return(this.Redirect("/")); }
public ActionResult PostLoginSubmit(PostLoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { model.BranchList = _branchRepository.GetAllBranch(); model.YearList = _yearRepository.GetAllFinancialYears(); return(View("PostLogin", model)); } Session["CurrentBranch"] = model.Branch_Id; Session["FinancialYear"] = model.FinancialYear; return(RedirectToLocal(returnUrl)); }
private ActionResult RedirectToPostLoginUrl(string returnUrl, LoginViewModel loginViewModel) { PostLoginViewModel model = new PostLoginViewModel(); model.UserName = loginViewModel.UserName; model.Password = loginViewModel.Password; model.BranchList = _branchRepository.GetAllBranch(); if (model.BranchList != null && model.BranchList.Count > 0) { ViewBag.DefaultBranchId = model.BranchList.FirstOrDefault().Branch_Id; } model.YearList = _yearRepository.GetAllFinancialYears(); if (model.YearList != null && model.YearList.Count > 0) { ViewBag.DefaultYear = model.YearList.LastOrDefault().Year; } return(View("PostLogin", model)); }
public async Task <IActionResult> Login([FromBody] PostLoginViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false, false); if (!result.Succeeded) { ModelState.AddModelError(string.Empty, "Wrong username or password"); return(BadRequest(ModelState)); } var user = await _userManager.FindByNameAsync(model.Email); return(new OkResult()); }
public void WhenUserClocksOutAndConfirms_ThenClockOutTimeIsRecordedAndUserIsLoggedOut() { var target = new PostLoginViewModel(_dataService, _mockMessageBus.Object, _mockSecurityContext.Object, Time, POSDevices); Time.SkipForwardBy(TimeSpan.FromMinutes(5)); target.HandleClockOut(); Assert.IsTrue(target.ClockOutVisible); target.ConfirmClockOut(); Assert.IsFalse(target.ClockOutVisible); //TODO: verify that the correct EmployeeTimeClock record was updated var timeClocks = _dataService.EmployeeTimeClocks.Where(tc => tc.EmployeeId == _mockSecurityContext.Object.CurrentUser.Id).ToList(); Assert.AreEqual(1, timeClocks.Count); Assert.IsNotNull(timeClocks[0].ClockOutTimeUTC); Assert.IsTrue(timeClocks[0].ClockOutTimeUTC > timeClocks[0].ClockInTimeUTC); Assert.IsTrue(timeClocks[0].ClockOutTimeUTC - timeClocks[0].ClockInTimeUTC > new TimeSpan(0, 4, 50)); _mockMessageBus.Verify(m => m.Publish(It.IsAny <UserLoggingOut>())); //TODO: what if the user wasn't actually clocked in at the time? (i.e. two login sessions on different terminals.) //TODO: what if the dataService is unavailable or unresponsive? }
public ActionResult PostLogin(PostLoginViewModel model, string returnUrl) { ViewBag.ReturnUrl = returnUrl; return(View(model)); }