public Task <ConfirmationProcessResult> ConfirmAccount(ConfirmationProcessRequest input) { return(this.authService.ProcessConfirmation(this.HttpContext, input)); }
/// <summary> /// Process confirmation submit /// </summary> /// <param name="httpContext">The HTTP context</param> /// <param name="request">The confirmation process request</param> /// <returns></returns> public async Task <ConfirmationProcessResult> ProcessConfirmation(HttpContext httpContext, ConfirmationProcessRequest request) { // check if valid request if (request == null || request.Email.IsBlank()) { throw ErrorDefinition.Unknown(IdentityErrors.INVALID_EMAIL).AsException(); } // gets the authorization context by the return URL (authorize callback URL) var context = await this.identityInteraction.GetAuthorizationContextAsync(request.ReturnUrl); // the return url var returnUrl = request.ReturnUrl.IsBlank() || context == null ? "/" : request.ReturnUrl; // gets the user by email var user = await this.userService.GetByEmail(request.Email); // check if no user if (user == null) { throw ErrorDefinition.Validation(IdentityErrors.INVALID_EMAIL).AsException(); } // email is confirmed if (user.EmailVerified) { throw ErrorDefinition.Validation(IdentityErrors.EMAIL_ALREADY_CONFIRMED).AsException(); } // get codes for the target var codes = await this.userService.GetConfirmations(request.Email); // choose ones that are not expired var validCodes = codes.Where(c => c.ValidUntil >= DateTime.UtcNow); // check is valid var isValid = validCodes.Any(c => this.passwordHasher.Check(c.CodeHash, request.Code).Verified); // verification failed if (!isValid) { throw ErrorDefinition.Validation(IdentityErrors.INVALID_CONFIRMATION_CODE).AsException(); } // confirm otherwise user = await this.ProceedConfirmation(user); // do sign-in registration was successful await this.SignInImpl(httpContext, new SignInPrincipal { Subject = user.Id, Email = user.Email, DisplayName = user.FullName, Provider = IdentityProviders.LOCAL }); // build result return(new ConfirmationProcessResult { Subject = user.Id, ContinueFlow = context != null, ReturnUrl = returnUrl }); }