public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { LoginBl.OnLogin(model); if (!string.IsNullOrEmpty(model.ErrorMessage)) ModelState.AddModelError("", model.ErrorMessage); else { if(model.IsFirstTimeLogin) return RedirectToAction("ChangePassword"); if(model.NeedToSelectRole) return RedirectToAction("ChangeRole", new { returnUrl=returnUrl}); if (Url.IsLocalUrl(returnUrl)) return Redirect(returnUrl); return RedirectToAction("Index", "Home"); } } return View(model); }
//public IFormsAuthenticationService FormsService //{ // get; // set; //} //protected override void Initialize(RequestContext requestContext) //{ // if (FormsService == null) // { // FormsService = new FormsAuthenticationService(); // } // base.Initialize(requestContext); //} // ************************************** // URL: /Account/LogOn // ************************************** public ActionResult LogOn() { var model = new LogOnModel(); LoginBl.InitForm(model); if (!string.IsNullOrEmpty(model.ErrorMessage)) { ModelState.AddModelError("", model.ErrorMessage); model.IsButtonHidden = true; } return View(model); }
public void OnLogin(LogOnModel model) { try { if (!string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Password)) { User user = UserDao.FindByLogin(model.UserName); if (user != null) { if (user.PasswordIsValid(model.Password)) { if (user.IsActive) { //AuthenticationService.CurrentUser = AuthenticationService.CreateUser(user); if (user.IsFirstTimeLogin && ((user.UserRole & UserRole.Employee) > 0 || (user.UserRole & UserRole.Manager) > 0 || (user.UserRole & UserRole.PersonnelManager) > 0 /*|| (user.UserRole & UserRole.ConsultantOutsorsingManager) > 0*/)) //DEPRECATED Убрал роль консультант ОК { model.IsFirstTimeLogin = user.IsFirstTimeLogin; model.UserId = user.Id; IUser dto = AuthenticationService.CreateUser(user,user.UserRole); AuthenticationService.SetChangePasswordCookie(dto); } else { formsAuthenticationService.SignIn(model.UserName, false); List<UserRolesDto> usersAndRoles = GetUserRoles(user); if (usersAndRoles.Count == 0) throw new ArgumentException("Отсутствуют роли в системе для данного пользователя"); UserRole role = user.UserRole; if (IsUserHaveManyRoles(usersAndRoles)) { model.NeedToSelectRole = true; role = UserRole.NoRole; } AddRecordToUserLogin(user,role); IUser dto = AuthenticationService.CreateUser(user,role); AuthenticationService.setAuthTicket(dto); } } else model.ErrorMessage = Resources.Login_AccountInactive; } else model.ErrorMessage = Resources.Login_PasswordIncorrect; } else model.ErrorMessage = Resources.Login_LoginIncorrect; } } catch (Exception ex) { Log.Error("Exception:", ex); model.ErrorMessage = "Exception:" + ex.GetBaseException().Message; } }
protected void CheckDbVesion(LogOnModel model) { Version dbVersion; try { dbVersion = DBVersionDao.GetDatabaseVersion(); if ((dbVersion.Major != AppVersion.Major) || (dbVersion.Build != AppVersion.Build)) model.ErrorMessage = string.Format("Версия приложения {0} не соответствует версии базы данных {1}", AppVersion, dbVersion); } catch (Exception ex) { Log.Error(ex); model.ErrorMessage = string.Format("Exception on login:{0}", ex.GetBaseException().Message); return; } }
public void InitForm(LogOnModel model) { CheckDbVesion(model); }