public async Task <ActionResult> Register(RegisterViewModel user) { user.Localization = _LocaleLogic.GetLocalizations(); if (ModelState.IsValid == false) { return(View(user)); } MVC5_TemplateIdentityUser _user = new MVC5_TemplateIdentityUser { UserName = user.Email, Email = user.Email }; var result = await _UserManager.CreateAsync(_user, user.Password); if (result.Succeeded == false) { _UserSettingsLogic.AddErrors(ModelState, result); return(View(user)); } //Create UserSettings and set localization for currently created user MVC5_TemplateIdentityUser MVC5_TemplateUser = _UserManager.Find(user.Email, user.Password); UserSettings userSettings = new UserSettings() { UserID = MVC5_TemplateUser.Id, LocalizationID = user.SelectedLocale }; _UserSettingsLogic.CreateEntity(userSettings); return(RedirectToAction("Index", "Home")); }
public async Task <JsonResult> RemoveUserFromRole(ManageUserRolesViewModel manageUserRolesViewModel) { MVC5_TemplateIdentityUser MVC5_TemplateIdentityUser = await _UserManager.FindByNameAsync(manageUserRolesViewModel.UserName); IdentityResult result = await _UserManager.RemoveFromRoleAsync(MVC5_TemplateIdentityUser.Id, manageUserRolesViewModel.RoleName); string resultMessage = result.Succeeded ? SuccessMsg.UserRemovedFromRoleSuccesfully : ErrorMsg.UserRemovedFromRoleError; return(Json(resultMessage)); }
public ActionResult IdentityProfileSettings() { MVC5_TemplateIdentityUser MVC5_TemplateUser = _UserManager.FindById(User.Identity.GetUserId()); IdentityProfileViewModel profileViewModel = new IdentityProfileViewModel() { CurrentEmail = MVC5_TemplateUser.Email, }; return(View(profileViewModel)); }
public ActionResult UserAppSettings() { MVC5_TemplateIdentityUser MVC5_TemplateUser = _UserManager.FindById(User.Identity.GetUserId()); UserAppSettingsViewModel userAppSettings = new UserAppSettingsViewModel() { Localization = _LocaleLogic.GetLocalizations(), SelectedLocale = _UserSettingsLogic.GetByUserID(MVC5_TemplateUser.Id).LocalizationID }; return(View(userAppSettings)); }
public async Task <JsonResult> AddUserToRole(ManageUserRolesViewModel manageUserRolesViewModel) { MVC5_TemplateIdentityUser MVC5_TemplateIdentityUser = await _UserManager.FindByNameAsync(manageUserRolesViewModel.UserName); string resultMessage; if (MVC5_TemplateIdentityUser == null) { resultMessage = ErrorMsg.UserDoesNotExists; return(Json(resultMessage)); } IdentityResult result = await _UserManager.AddToRoleAsync(MVC5_TemplateIdentityUser.Id, manageUserRolesViewModel.RoleName); resultMessage = result.Succeeded ? SuccessMsg.UserAddedToRoleSuccesfuly : ErrorMsg.UserAddedToRoleError; return(Json(resultMessage)); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid == false) { return(View(model)); } var result = await _SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); if (result == SignInStatus.Failure) { ModelState.AddModelError("", ErrorMsg.InvaliLoginAttempt); return(View(model)); } // If user is successfully logged in set localization for it MVC5_TemplateIdentityUser MVC5_TemplateUser = _UserManager.Find(model.Email, model.Password); _LocaleLogic.SetLocalizationForCurrentUser(MVC5_TemplateUser.Id); return(RedirectToAction("Index", "Home")); }