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> > SendForgotPasswordEmail(ForgotPasswordUserRequest request)
        {
            var identity = await _userManager.Users.FirstOrDefaultAsync(u => u.Email == request.Email);

            if (identity == null)
            {
                _logger.LogWarning($"Username {request.Email} does not exist.");
                return(Response <UserModel> .ForSuccess());
            }

            var user = await _usersRepository.GetByIdentity(identity.Id);

            var token = await _userManager.GenerateEmailConfirmationTokenAsync(identity);

            var template = await GetUserEmailAsync(identity, user, _templateData.ForgotPasswordEmailFileName, "reset-password", token);

            await _emailClient.Send(identity.Email, "Forgot password notification", template);

            _logger.LogInformation($"Reset password email sent for {request.Email}.");

            return(Response <UserModel> .ForSuccess());
        }