Exemplo n.º 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.EnableAccountLogin,

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

            return(vm);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(RecoverInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(await this.CreateViewModelAsync(model)));
            }

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

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

                    await this._notificationService
                    .SendUserAccountRecoverEmailAsync(userAccount);

                    return(this.View("Success", new SuccessViewModel()
                    {
                        ReturnUrl = model.ReturnUrl,

                        // TODO: Use a provider helper or something
                        Provider = userAccount.Email
                                   .Split('@')
                                   .LastOrDefault()
                    }));
                }
                else
                {
                    this.ModelState.AddModelError(this._localizer[
                                                      ErrorMessages.UserAccountIsDeactivated]);
                }
            }
            else
            {
                this.ModelState.AddModelError(this._localizer[
                                                  ErrorMessages.UserAccountDoesNotExists]);
            }

            return(this.View(
                       await this.CreateViewModelAsync(model, userAccount)));
        }
Exemplo n.º 3
0
 public RecoverViewModel(RecoverInputModel inputModel)
 {
     this.Email     = inputModel.Email;
     this.ReturnUrl = inputModel.ReturnUrl;
 }