public async Task <IAccount> HandleRegistrationAsync( IOwinEnvironment environment, IApplication application, IDictionary <string, string> formData, IAccount newAccount, Func <string, CancellationToken, Task> errorHandler, CancellationToken cancellationToken) { var defaultAccountStore = await application.GetDefaultAccountStoreAsync(cancellationToken); var preRegisterHandlerContext = new PreRegistrationContext(environment, newAccount, formData) { AccountStore = defaultAccountStore as IDirectory }; await _handlers.PreRegistrationHandler(preRegisterHandlerContext, cancellationToken); if (preRegisterHandlerContext.Result != null) { if (!preRegisterHandlerContext.Result.Success) { var message = string.IsNullOrEmpty(preRegisterHandlerContext.Result.ErrorMessage) ? "An error has occurred. Please try again." : preRegisterHandlerContext.Result.ErrorMessage; await errorHandler(message, cancellationToken); return(null); } } if (!string.IsNullOrEmpty(preRegisterHandlerContext.OrganizationNameKey)) { var organization = await _client.GetOrganizationByNameKeyAsync(preRegisterHandlerContext.OrganizationNameKey, cancellationToken); if (organization == null) { await errorHandler("The specified organization does not exist.", cancellationToken); return(null); } return(await organization.CreateAccountAsync( preRegisterHandlerContext.Account, preRegisterHandlerContext.Options, cancellationToken)); } if (preRegisterHandlerContext.AccountStore != null) { return(await preRegisterHandlerContext.AccountStore.CreateAccountAsync( preRegisterHandlerContext.Account, preRegisterHandlerContext.Options, cancellationToken)); } return(await application.CreateAccountAsync( preRegisterHandlerContext.Account, preRegisterHandlerContext.Options, cancellationToken)); }
public async Task <IAccount> HandleRegistrationAsync( IOwinEnvironment environment, IApplication application, IAccount newAccount, CancellationToken cancellationToken) { var defaultAccountStore = await application.GetDefaultAccountStoreAsync(cancellationToken); var preRegisterHandlerContext = new PreRegistrationContext(environment, newAccount) { AccountStore = defaultAccountStore as IDirectory }; await _handlers.PreRegistrationHandler(preRegisterHandlerContext, cancellationToken); IAccount createdAccount; if (preRegisterHandlerContext.AccountStore != null) { createdAccount = await preRegisterHandlerContext.AccountStore.CreateAccountAsync( preRegisterHandlerContext.Account, preRegisterHandlerContext.Options, cancellationToken); } else { createdAccount = await application.CreateAccountAsync( preRegisterHandlerContext.Account, preRegisterHandlerContext.Options, cancellationToken); } return(createdAccount); }