示例#1
0
        internal async Task <RecoverViewModel> CreateViewModelAsync(
            RecoverInputModel inputModel,
            UserAccount userAccount = null)
        {
            AuthorizationRequest context = await this._interaction
                                           .GetAuthorizationContextAsync(inputModel.ReturnUrl);

            if (context == null)
            {
                return(null);
            }

            Client client = await this._clientService
                            .FindEnabledClientByIdAsync(context.ClientId);

            IEnumerable <ExternalProvider> providers =
                await this._clientService.GetEnabledProvidersAsync(client);

            RecoverViewModel vm = new RecoverViewModel(inputModel)
            {
                EnableAccountRegistration =
                    this._applicationOptions.EnableAccountRegistration,

                EnableLocalLogin = (client != null ?
                                    client.EnableLocalLogin : false) &&
                                   this._applicationOptions.EnableLocalLogin,

                LoginHint             = context.LoginHint,
                ExternalProviders     = providers.ToArray(),
                ExternalProviderHints = userAccount?.Accounts?
                                        .Select(c => c.Provider)
            };

            return(vm);
        }
示例#2
0
        public async Task <IActionResult> Index(RecoverInputModel model)
        {
            if (ModelState.IsValid)
            {
                // Load user by email
                string email = model.Email.ToLower();

                // Check if user with same email exists
                UserAccount userAccount = await this._userAccountService
                                          .LoadByEmailAsync(email);

                if (userAccount != null)
                {
                    if (userAccount.IsLoginAllowed)
                    {
                        await this._userAccountService
                        .SetResetPasswordVirificationKeyAsync(
                            userAccount,
                            model.ReturnUrl);

                        await this.SendEmailAsync(userAccount);

                        return(this.View("Success", new SuccessViewModel()
                        {
                            ReturnUrl = model.ReturnUrl,
                            Provider = userAccount.Email
                                       .Split('@')
                                       .LastOrDefault()
                        }));
                    }
                    else
                    {
                        this.ModelState.AddModelError(IdentityBaseConstants
                                                      .ErrorMessages.UserAccountIsDeactivated);
                    }
                }
                else
                {
                    this.ModelState.AddModelError(IdentityBaseConstants
                                                  .ErrorMessages.UserAccountDoesNotExists);
                }

                return(this.View(
                           await this.CreateViewModelAsync(model, userAccount)
                           ));
            }

            return(this.View(await CreateViewModelAsync(model)));
        }
 public RecoverViewModel(RecoverInputModel inputModel)
 {
     this.Email     = inputModel.Email;
     this.ReturnUrl = inputModel.ReturnUrl;
 }