/// <summary> /// Initializes a new instance of the <see cref="LogOn" /> class. /// </summary> /// <param name="mode">The mode.</param> public LogOn(LogOnMode mode) { this.logOnViewModel = new LogOnViewModel(mode); this.DataContext = this.logOnViewModel; this.InitializeComponent(); this.RegisterEvents(); }
public static void Login_Succeed(string UserEmailValid, string UserPassword) { ControllerFake<UserAccountController, LogOnViewModel> controller = new ControllerFake<UserAccountController, LogOnViewModel>(); LogOnViewModel logOnModel = new LogOnViewModel(); logOnModel.Email = UserEmailValid; logOnModel.Password = UserPassword; ActionResult resultPost = controller.Controller.LogOn(logOnModel); Assert.AreEqual(true, HttpContext.Current.Response.Cookies[UserRequestModel_Keys.WcfFormsAuthenticationCookieName].Value != string.Empty); Assert.AreEqual(true, resultPost.GetType() == typeof(RedirectResult)); Assert.AreEqual(true, (((RedirectResult)resultPost).Url == controller.Controller.RedirectResultOnLogIn().Url)); }
public ActionResult Login(LogOnViewModel viewModel) { if (ModelState.IsValid) { if (Membership.ValidateUser(viewModel.Login, viewModel.Password)) { FormsAuthentication.SetAuthCookie(viewModel.Login, viewModel.RememberMe); TempData["user"] = userService.GetByLogin(viewModel.Login).ToPlUser(); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "Incorrect login or password."); } } return View(viewModel); }
public LogOnWindow() { InitializeComponent(); DataContext = new LogOnViewModel(); }
public async Task WillInvalidateModelStateAndShowTheViewWhenAnEntityExceptionIsThrow() { GetMock<AuthenticationService>() .Setup(x => x.Register(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Credential>())) .Throws(new EntityException("aMessage")); var controller = GetController<AuthenticationController>(); var request = new LogOnViewModel() { Register = new RegisterViewModel { Username = "******", Password = "******", EmailAddress = "theEmailAddress", } }; var result = await controller.Register(request, null, linkingAccount: false); ResultAssert.IsView(result, viewName: "LogOn"); Assert.False(controller.ModelState.IsValid); Assert.Equal("aMessage", controller.ModelState["Register"].Errors[0].ErrorMessage); }
public ActionResult Index(LogOnViewModel model, string returnUrl) { if (ModelState.IsValid) { if (authProvider.Authenticate(model.EmailAddress, model.Password, this.userRepository)) { var userObj = userRepository.GetUserByEmailAddress(model.EmailAddress); Session["user"] = userObj; var accountObj = accRepository.Accounts.FirstOrDefault(x => x.ID == userObj.AccountID); Session["account"] = accountObj; var timeZone = accRepository.Accounts.Where(aid => aid.ID == userObj.AccountID).FirstOrDefault().TimeZone; Session["timeZone"] = timeZone; //save details into error table SaveLogonDetails(model.EmailAddress); if (userObj.UserType == "Admin" || userObj.UserType == "Standard") { if (userObj.EmailVerified == true) { //get the folders var folders = CCFolderRepository.CCFolders.Where(guid => guid.AccountGUID == accountObj.AccountGUID).ToList(); Session["folderss"] = folders; return Redirect(returnUrl ?? Url.Action("Index", "Admin")); } else { return Redirect(returnUrl ?? Url.Action("ResendVerification", "SignUp", new { uid = userObj.ID })); } } else if (userObj.UserType == "SystemAdmin") { return Redirect(returnUrl ?? Url.Action("Index", "CorporateContactsAdmin")); } else { return Redirect(returnUrl ?? Url.Action("SetupSync", "User")); } } else { //save details into error table SaveLogonDetails(model.EmailAddress); ModelState.AddModelError("", "Incorrect username or password"); return View(); } } else { return View(); } }
public ActionResult Login(LogOnViewModel model, string returnUrl) { if (ModelState.IsValid) { if (authProvider.Authenticate(model.EmailAddress, model.Password, this.userRepository)) { var userObj = userRepository.GetUserByEmailAddress(model.EmailAddress); Session["user"] = userObj; var accountObj = accRepository.Accounts.FirstOrDefault(x => x.ID == userObj.AccountID); Session["account"] = accountObj; var timeZone = accRepository.Accounts.Where(aid => aid.ID == userObj.AccountID).FirstOrDefault().TimeZone; Session["timeZone"] = timeZone; Session["SysAdminDetails"] = null; List<NotificationListViewModel> notificationList = new List<NotificationListViewModel>(); CronJobController CJC = new CronJobController(); Session["account"] = CJC.checkAccountTrialExpiryForAccount(accountObj); //save details into error table //SaveLogonDetails(model.EmailAddress); if ( userObj.UserType == "Admin" || userObj.UserType == "Standard") { if (userObj.EmailVerified == true) { //get the folders var folders = CCFolderRepository.CCFolders.Where(guid => guid.AccountGUID == accountObj.AccountGUID).ToList(); Session["folderss"] = folders; HelperFunctions HF = new HelperFunctions(); notificationList = HF.generateNotificationList(accountObj); HF.CheckAcccountStatus(accountObj); if(notificationList.Count>0) Session["notifications"] = notificationList; else Session["notifications"] = null; return Redirect(returnUrl ?? Url.Action("Index", "Admin")); } else { return Redirect(returnUrl ?? Url.Action("ResendVerification", "SignUp", new { uid = userObj.ID })); } } else if (userObj.UserType == "SystemAdmin") { HelperFunctions HF = new HelperFunctions(); notificationList = HF.generateNotificationList(accountObj); if (notificationList.Count > 0) Session["notifications"] = notificationList; Session["SysAdminDetails"] = userRepository.GetUserByEmailAddress(model.EmailAddress); return Redirect(returnUrl ?? Url.Action("Index", "CorporateContactsAdmin")); } else { return Redirect(returnUrl ?? Url.Action("SetupSync", "User")); } } else { //save details into error table //SaveLogonDetails(model.EmailAddress); ModelState.AddModelError("", "Incorrect username or password"); return View(); } } else { return View(); } }
public ActionResult LogOn(LogOnViewModel model) { if (this.RequestType() == HttpVerbs.Get) { model = new LogOnViewModel(); model.BaseViewModelInfo.Title = $customNamespace$.Resources.General.GeneralTexts.LogOn; model.UrlReferer = Request.UrlReferrer == null ? string.Empty : Request.UrlReferrer.ToString(); return View(model); } else { if (ModelState.IsValid) { bool isValidUser = this.FormsAuthenticationService.LogIn(model.Email, model.Password, string.Empty, false); //model.RememberMe); if (isValidUser) { this.FormsProfileService.Get().Data.ApplyClientProperties(); if (Url.IsLocalUrl(model.UrlReferer)) // Prevents Open Redirection Attacks { return new RedirectResult(model.UrlReferer); } else { return this.RedirectResultOnLogIn(); } } else { ModelState.AddModelError("Invalid_Credentials", AccountResources.UserNameOrPasswordInvalid); } } model.BaseViewModelInfo.Title = $customNamespace$.Resources.General.GeneralTexts.LogOn; return View(model); } }
public AccountIndexViewModel(CreateAccountViewModel createAccountViewModel, LogOnViewModel logOnViewModel) { CreateAccountViewModel = createAccountViewModel; LogOnViewModel = logOnViewModel; }
public virtual ActionResult Login(LogOnViewModel model, string returnUrl) { if (ModelState.IsValid) { if (authenticationService.LogOn(model.UserName, model.Password, model.RememberMe)) { CreateAuthenticationTicket(model.UserName); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } else { MembershipUser user = membershipService.GetUser(model.UserName); if (user == null) { ModelState.AddModelError("", "This account does not exist. Please try again."); } else { if (!user.IsApproved) { ModelState.AddModelError("", "Your account has not been approved yet."); } else if (user.IsLockedOut) { ModelState.AddModelError("", "Your account is currently locked."); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } } } // If we got this far, something failed, redisplay form return RedirectToAction("Login"); }
public virtual ActionResult Login() { var viewModel = new LogOnViewModel() { EnablePasswordReset = membershipService.EnablePasswordReset }; return ContextDependentView(viewModel); }
public JsonResult JsonLogOn(LogOnViewModel model, string returnUrl) { if (ModelState.IsValid) { if (authenticationService.LogOn(model.UserName, model.Password, model.RememberMe)) { return Json(new { success = true, redirect = returnUrl }); } else { MembershipUser user = membershipService.GetUser(model.UserName); if (user == null) { ModelState.AddModelError("", "This account does not exist. Please try again."); } else { if (!user.IsApproved) { ModelState.AddModelError("", "Your account has not been approved yet."); } else if (user.IsLockedOut) { ModelState.AddModelError("", "Your account is currently locked."); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } } } // If we got this far, something failed return Json(new { errors = GetErrorsFromModelState() }); }
public ActionResult LogOn(LogOnViewModel model) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var username = model.UserName; var password = model.Password; try { if (ModelState.IsValid) { // We have an event here to help with Single Sign Ons // You can do manual lookups to check users based on a webservice and validate a user // Then log them in if they exist or create them and log them in - Have passed in a UnitOfWork // To allow database changes. var e = new LoginEventArgs { UserName = model.UserName, Password = model.Password, RememberMe = model.RememberMe, ReturnUrl = model.ReturnUrl, UnitOfWork = unitOfWork }; EventManager.Instance.FireBeforeLogin(this, e); if (!e.Cancel) { var message = new GenericMessageViewModel(); var user = new MembershipUser(); if (MembershipService.ValidateUser(username, password, Membership.MaxInvalidPasswordAttempts)) { // Set last login date user = MembershipService.GetUser(username); if (user.IsApproved && !user.IsLockedOut && !user.IsBanned) { FormsAuthentication.SetAuthCookie(username, model.RememberMe); user.LastLoginDate = DateTime.UtcNow; if (Url.IsLocalUrl(model.ReturnUrl) && model.ReturnUrl.Length > 1 && model.ReturnUrl.StartsWith("/") && !model.ReturnUrl.StartsWith("//") && !model.ReturnUrl.StartsWith("/\\")) { return Redirect(model.ReturnUrl); } message.Message = LocalizationService.GetResourceString("Members.NowLoggedIn"); message.MessageType = GenericMessages.success; EventManager.Instance.FireAfterLogin(this, new LoginEventArgs { UserName = model.UserName, Password = model.Password, RememberMe = model.RememberMe, ReturnUrl = model.ReturnUrl, UnitOfWork = unitOfWork }); return RedirectToAction("Index", "Home", new { area = string.Empty }); } //else if (!user.IsApproved && SettingsService.GetSettings().ManuallyAuthoriseNewMembers) //{ // message.Message = LocalizationService.GetResourceString("Members.NowRegisteredNeedApproval"); // message.MessageType = GenericMessages.success; //} //else if (!user.IsApproved && SettingsService.GetSettings().NewMemberEmailConfirmation == true) //{ // message.Message = LocalizationService.GetResourceString("Members.MemberEmailAuthorisationNeeded"); // message.MessageType = GenericMessages.success; //} } // Only show if we have something to actually show to the user if (!string.IsNullOrEmpty(message.Message)) { TempData[AppConstants.MessageViewBagName] = message; } else { // get here Login failed, check the login status var loginStatus = MembershipService.LastLoginStatus; switch (loginStatus) { case LoginAttemptStatus.UserNotFound: case LoginAttemptStatus.PasswordIncorrect: ModelState.AddModelError(string.Empty, LocalizationService.GetResourceString("Members.Errors.PasswordIncorrect")); break; case LoginAttemptStatus.PasswordAttemptsExceeded: ModelState.AddModelError(string.Empty, LocalizationService.GetResourceString("Members.Errors.PasswordAttemptsExceeded")); break; case LoginAttemptStatus.UserLockedOut: ModelState.AddModelError(string.Empty, LocalizationService.GetResourceString("Members.Errors.UserLockedOut")); break; case LoginAttemptStatus.Banned: ModelState.AddModelError(string.Empty, LocalizationService.GetResourceString("Members.NowBanned")); break; case LoginAttemptStatus.UserNotApproved: ModelState.AddModelError(string.Empty, LocalizationService.GetResourceString("Members.Errors.UserNotApproved")); user = MembershipService.GetUser(username); SendEmailConfirmationEmail(user); break; default: ModelState.AddModelError(string.Empty, LocalizationService.GetResourceString("Members.Errors.LogonGeneric")); break; } } } } } finally { try { unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); } } return View(model); } }
/// <summary> /// Log on /// </summary> /// <returns></returns> public ActionResult LogOn() { // Create the empty view model var viewModel = new LogOnViewModel(); // See if a return url is present or not and add it var returnUrl = Request["ReturnUrl"]; if (!string.IsNullOrEmpty(returnUrl)) { viewModel.ReturnUrl = returnUrl; } return View(viewModel); }