public async Task <ActionResult> PasswordRecover(AccountPasswordRecoverViewModel model) { if (ModelState.IsValid) { // var adminUser = await _appUserManager.FindByEmailAsync(model.Email); // if (adminUser != null && adminUser.Realms.Contains(Realm.AdminWebsite)) { // var mailModel = new AccountPasswordRecoverMessageViewModel() { Name = adminUser.FullName ?? adminUser.UserName, PageTitle = GetLocalizedString <AreaResources>("RecoverPassword"), ResetLink = Url.Action(nameof(PasswordSetNew), "Account", new { resetToken = await _appUserManager.GeneratePasswordResetTokenAsync(adminUser.Id), area = AppAreas.GetAreaName(Area.Users) }, protocol: Request.Url.Scheme) }; // var subject = $"[{GetLocalizedString("AppName")}] {mailModel.PageTitle}"; var message = RenderViewToString("PasswordRecoverMessage", model: mailModel); // _emailDispatcherService.Dispatch(message, subject, new MailAddress(adminUser.Email, adminUser.FullName)); } return(RedirectToAction(nameof(PasswordRecover), new { status = AccountActionStatus.PasswordRecoverMessageSent.ToLowerCaseString() })); } return(View(model)); }
private ActionResult RedirectToLocal(string returnUrl = null) { if (!string.IsNullOrWhiteSpace(returnUrl) && Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } return(RedirectToAction("Index", "Home", new { area = AppAreas.GetAreaName(Area.Root) })); }
public async Task <ActionResult> PasswordChange(AccountPasswordChangeViewModel model) { if (ModelState.IsValid) { var result = await _appUserManager.ChangePasswordAsync( User.Id, model.Password, model.NewPassword ); if (result.Succeeded) { Feedback.AddMessage(FeedbackMessageType.Success, GetLocalizedString <AreaResources>("DefaultSuccessMessage")); return(RedirectToAction("Index", "Home", new { area = AppAreas.GetAreaName(Area.Root) })); } ModelState.AddModelError("Password", GetLocalizedString <AreaResources>("InvalidPasswordMessage")); } return(View(model)); }
protected void Application_Error() { var exception = Server.GetLastError(); var httpException = exception as HttpException; var loggerInstance = DependencyResolver.Current.GetService <ILogger>(); loggerInstance?.Fatal(exception, exception.Message); if (Initialized) { var httpStatusCode = httpException?.GetHttpCode() ?? 500; if (exception is HttpAntiForgeryException) { httpStatusCode = (int)HttpStatusCode.BadRequest; } Server.ClearError(); Response.Clear(); var data = new RouteData(); data.Values["ex"] = exception; data.Values["code"] = httpStatusCode; data.Values["area"] = AppAreas.GetAreaName(Area.Root); data.Values["action"] = nameof(ErrorsController.Index); data.Values["controller"] = nameof(ErrorsController).RemoveControllerSuffix(); var controller = DependencyResolver.Current.GetService <ErrorsController>() as IController; var requestContext = new RequestContext(new HttpContextWrapper(Context), data); controller.Execute(requestContext); } }
public ActionResult Add(UserViewModel model) { if (ModelState.IsValid) { var user = new UserEntity { FullName = model.FullName, Email = model.Email, Realms = model.Realms.Select(realm => realm.ChangeType <Realm>()).ToList(), Roles = model.Roles.Select(role => role.ChangeType <Role>()).ToList() }; // user.SetDefaultUserName(); user.LockoutEnabled = _Constants.UsersLockoutEnabledByDefault; user.EmailConfirmed = true; // var initialPassword = user.GetInitialPassword(); user.PasswordHash = _passwordHasher.HashPassword(initialPassword); // user = _managementUsersRepository.Create(user); if (user.Id > 0) { // var mail = new UserCreatedMessageViewModel() { Email = user.Email, FullName = user.FullName, InitialPassword = initialPassword, PageTitle = GetLocalizedString("Management_Users_UserCreatedMessageSubject"), }; // Provide the user information on how to access allowed realms. foreach (var realm in user.Realms) { switch (realm) { case Realm.AdminWebsite: { var link = Url.Action( "Index", "Home", new { area = AppAreas.GetAreaName(Area.Root) }, protocol: Request.Url.Scheme); mail.AllowedRealms.Add(new UserCreatedMessageViewModel.AllowedRealmInfo() { Realm = realm, RealmUri = new Uri(link, UriKind.Absolute) }); } break; } } // var subject = $"[{GetLocalizedString("_App_Name")}] {mail.PageTitle}"; var message = RenderViewToString("UserCreatedMessage", model: mail); // _emailDispatcherService.Dispatch(message, subject, new MailAddress(user.Email, user.FullName)); // Feedback.AddMessage(FeedbackMessageType.Success, GetLocalizedString("DefaultSuccessMessage")); // return(RedirectToAction(nameof(Index))); } ModelState.AddModelError(string.Empty, GetLocalizedString("DefaultErrorMessage")); } model = BuildUserViewModel(postedModel: model); return(View("Manager", model)); }