コード例 #1
0
        public async Task <ActionResult> ConfirmRegistration(ConfirmEmailVM confirmEmailVM)
        {
            if (string.IsNullOrWhiteSpace(confirmEmailVM.Code))
            {
                ModelState.AddModelError("", "Code are required");
                return(BadRequest(ModelState));
            }
            var accountInDB = _context.Accounts.Where(a => a.Id == confirmEmailVM.AccountId && a.IsDeleted == false).FirstOrDefault();

            if (accountInDB == null)
            {
                return(NotFound());
            }

            if (accountInDB.EmailConfirmed)
            {
                return(NoContent());
            }

            var            codeDecodedBytes = WebEncoders.Base64UrlDecode(confirmEmailVM.Code);
            var            codeDecoded      = Encoding.UTF8.GetString(codeDecodedBytes);
            IdentityResult result           = await this._userManager.ConfirmEmailAsync(accountInDB, codeDecoded);

            if (result.Succeeded)
            {
                return(Content("Success"));
            }
            else
            {
                var message = string.Join(", ", result.Errors.Select(x => "Code " + x.Code + " Description" + x.Description));
                return(Content(message));
            }
        }
コード例 #2
0
        public async Task <IActionResult> ConfirmEmail([FromBody] ConfirmEmailVM model)
        {
            if (model.UserId == null || model.Ctoken == null)
            {
                return(NotFound());
            }
            var user = await userManager.FindByIdAsync(model.UserId);

            model.Ctoken = HttpUtility.UrlDecode(model.Ctoken);
            var res = await userManager.ConfirmEmailAsync(user, model.Ctoken);

            if (res.Succeeded)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
コード例 #3
0
ファイル: AuthController.cs プロジェクト: Emad-Sayed/DDD
        public async Task <IActionResult> ConfirmEmail(ConfirmEmailVM model)
        {
            var user = await _userManager.Users.FirstOrDefaultAsync(x => x.Email == model.Email);

            if (user == null)
            {
                return(BadRequest("user_with_this_email_not_found"));
            }

            var result = await _userManager.ConfirmEmailAsync(user, model.Token);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors));
            }

            await ConfirmDistributorUserEmail(user.Id);

            return(Ok(new { user.EmailConfirmed }));
        }
コード例 #4
0
        public async Task <IActionResult> EmailValidation(string userId, string token)
        {
            var user = await this._userService.GetById(userId);

            var emailConfirmed = await this._userService.ConfirmEmail(user, token);

            var confirmEmailVM = new ConfirmEmailVM();

            if (emailConfirmed)
            {
                confirmEmailVM.Result  = "Успех!";
                confirmEmailVM.Message = "Имейлът беше потвърден!\nРегистрацията е активирана.";
                return(View(confirmEmailVM));
            }

            confirmEmailVM.Result  = "Грешка";
            confirmEmailVM.Message = "Не можем да потвърдим имейла!";

            return(View(confirmEmailVM));
        }
コード例 #5
0
        public async Task <ActionResult> ConfirmEmail([FromBody] ConfirmEmailVM model)
        {
            // This is called when the user presses the confirm email link that is sent to his/her inbox
            if (!ModelState.IsValid)
            {
                return(BadRequest("There is something wrong with the request payload")); // TODO: Return friendlier validation errors
            }

            try
            {
                // Get the user
                var user = await _userManager.FindByIdAsync(model.UserId);

                if (user == null)
                {
                    // This is only possible if the user changes the email confirmation link before clicking
                    return(BadRequest("The supplied user id could not be found"));
                }

                // Rely on the injected user manager to validate the token and confirm the user's email
                IdentityResult result = await _userManager.ConfirmEmailAsync(user, model.EmailConfirmationToken);

                if (!result.Succeeded)
                {
                    return(BadRequest(result.ErrorMessage("Could not confirm email")));
                }

                // All good
                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.StackTrace);
                return(BadRequest(ex.Message));
            }
        }