public static async Task ConfirmEmailAsync(long id, GoblinIdentityConfirmEmailModel model, CancellationToken cancellationToken = default) { ValidationHelper.Validate <GoblinIdentityConfirmEmailModelValidator, GoblinIdentityConfirmEmailModel>(model); try { var endpoint = GetRequest(model.LoggedInUserId) .AppendPathSegment(GoblinIdentityEndpoints.ConfirmEmail.Replace("{id}", id.ToString())); await endpoint .PutJsonAsync(model, cancellationToken : cancellationToken) .ConfigureAwait(true); } catch (FlurlHttpException ex) { await FlurlHttpExceptionHelper.HandleErrorAsync(ex).ConfigureAwait(true); } }
public async Task ConfirmEmail(long id, GoblinIdentityConfirmEmailModel model, CancellationToken cancellationToken = default) { var userEntity = await _userRepo.Get(x => x.Id == id).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(true); if (userEntity == null) { throw new GoblinException(nameof(GoblinIdentityErrorCode.UserNotFound), GoblinIdentityErrorCode.UserNotFound); } if (userEntity.EmailConfirmToken == model.EmailConfirmToken) { if (userEntity.EmailConfirmTokenExpireTime < GoblinDateTimeHelper.SystemTimeNow) { throw new GoblinException(nameof(GoblinIdentityErrorCode.ConfirmEmailTokenExpired), GoblinIdentityErrorCode.ConfirmEmailTokenExpired); } } else { throw new GoblinException(nameof(GoblinIdentityErrorCode.ConfirmEmailTokenInCorrect), GoblinIdentityErrorCode.ConfirmEmailTokenInCorrect); } userEntity.EmailConfirmToken = null; userEntity.EmailConfirmTokenExpireTime = null; userEntity.EmailConfirmedTime = GoblinDateTimeHelper.SystemTimeNow; _userRepo.Update(userEntity, x => x.EmailConfirmToken, x => x.EmailConfirmTokenExpireTime, x => x.EmailConfirmedTime ); await GoblinUnitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(true); }
public async Task <IActionResult> SubmitVerifyEmail(GoblinIdentityConfirmEmailModel model, CancellationToken cancellationToken = default) { if (!ModelState.IsValid) { ViewBag.WarningMessage = Messages.InvalidData; return(View("VerifyEmail", model)); } try { model.LoggedInUserId = LoggedInUser <GoblinIdentityUserModel> .Current.Data.Id; await GoblinIdentityHelper.ConfirmEmailAsync(LoggedInUser <GoblinIdentityUserModel> .Current.Data.Id, model, cancellationToken).ConfigureAwait(true); ViewBag.SuccessMessage = "Your email is verified."; LoggedInUser <GoblinIdentityUserModel> .Current.Data.EmailConfirmedTime = GoblinDateTimeHelper.SystemTimeNow; } catch (GoblinException e) { ViewBag.ErrorMessage = e.ErrorModel.Message; } catch (Exception e) { ViewBag.ErrorMessage = e.Message; } var updateIdentityModel = new GoblinIdentityUpdateIdentityModel { NewUserName = LoggedInUser <GoblinIdentityUserModel> .Current.Data.UserName, NewEmail = LoggedInUser <GoblinIdentityUserModel> .Current.Data.Email }; return(View("Account", updateIdentityModel)); }
public async Task <IActionResult> ConfirmEmail([FromRoute] long id, [FromBody] GoblinIdentityConfirmEmailModel model, CancellationToken cancellationToken = default) { await _userService.ConfirmEmail(id, model, cancellationToken); return(NoContent()); }