public async Task <IActionResult> AcceptInvite(InviteAcceptModel model) { if (model.IsNotValid()) { model.SetInputModelValues(); return(View(model)); } var request = new UserAcceptInviteRequest(model.Token, model.Email, model.FirstName, model.LastName, model.Password); var response = await OrganizationService.AcceptInvitation(request); if (response.Status.IsNotSuccess) { model.MapMessages(response); model.SetInputModelValues(); return(View(model)); } return(Redirect("/User/AcceptInviteDone")); }
public async Task <UserAcceptInviteResponse> AcceptInvitation(UserAcceptInviteRequest request) { var response = new UserAcceptInviteResponse(); var user = await _userRepository.Select(x => x.InvitationToken == request.Token && x.Email == request.Email); if (user.IsExist() && user.InvitedAt.HasValue && user.InvitedAt.Value.AddDays(2) > DateTime.UtcNow) { user.FirstName = request.FirstName; user.LastName = request.LastName; user.PasswordHash = _cryptoHelper.Hash(request.Password, user.ObfuscationSalt); //todo:send welcome email //todo uow var result = await _userRepository.Update(user.Id, user); if (result) { var organization = _cacheManager.GetCachedOrganization(user.OrganizationUid); organization.UserCount++; result = await _organizationRepository.Update(user.Id, organization); if (result) { _cacheManager.UpsertOrganizationCache(organization, _organizationFactory.MapCurrentOrganization(organization)); response.Status = ResponseStatus.Success; return(response); } } } response.Status = ResponseStatus.Failed; return(response); }