Exemplo n.º 1
0
        public async Task Handle(ClaimsPrincipal principal)
        {
            var identityId = principal.GetUserId();
            var user       = await _tenantUsersRepository.GetByIdentity(identityId);

            if (user == null)
            {
                _tenantUsersRepository.Add(new Core.Models.User
                {
                    Id           = Guid.NewGuid(),
                    AspNetUserId = identityId,
                    Name         = principal.GetEmail(),
                    CreatedDate  = DateTime.UtcNow,
                    Deleted      = false,
                    Active       = true,
                    PartyId      = principal.GetPartyId(),
                    PartyName    = principal.GetPartyName()
                });
                await _tenantUsersRepository.Save();
            }
            else
            {
                user.Name      = principal.GetEmail();
                user.PartyId   = principal.GetPartyId();
                user.PartyName = principal.GetPartyName();
                await _tenantUsersRepository.Save();
            }
        }
Exemplo n.º 2
0
        public async Task <Response <UserModel> > ActivateAccountConfirm(ActivateAccountRequest request)
        {
            if (!request.Id.HasValue)
            {
                return(Response.ForError("Request id is required."));
            }

            var user = await _usersRepository.GetById(request.Id.Value);

            if (user == null)
            {
                return(Response.ForError("Associated user not found."));
            }

            if (user.Active)
            {
                return(Response.ForError("Account already activated."));
            }

            var aspNetUser = await _userManager.FindByIdAsync(user.AspNetUserId);

            var tokenResult = await _userManager.ConfirmEmailAsync(aspNetUser, request.Token);

            if (!tokenResult.Succeeded)
            {
                return(ConvertToResponse(tokenResult));
            }

            var passwordResult = await _userManager.AddPasswordAsync(aspNetUser, request.Password);

            if (!passwordResult.Succeeded)
            {
                _logger.LogWarning("account activation failed: {0}", passwordResult.Errors);
            }
            else
            {
                user.Active = true;
                await _usersRepository.Save();
            }

            return(ConvertToResponse(passwordResult));
        }