private async Task <UserDTO> MapUserToDTOWithRoles(HoundDogUser user)
        {
            _logger.LogDebug($"Mapping db user {user.Id} to dto user");
            var userdto = _mapper.Map <UserDTO>(user);

            userdto.Roles = string.Join(", ", await _signinManager.UserManager.GetRolesAsync(user));
            return(userdto);
        }
Esempio n. 2
0
 private void ChangePhoneNumber(HoundDogUser user, UserDTO userdata)
 {
     if (userdata.HasChangePhone)
     {
         user.PhoneNumber          = _phoneparser.ParsePhoneNumber(userdata.PhoneNumber);
         user.PhoneNumberConfirmed = false;
     }
 }
Esempio n. 3
0
 private void ChangeEmailAddress(HoundDogUser user, UserDTO userdata)
 {
     if (userdata.HasChangeEmail)
     {
         user.EmailConfirmed          = false;
         user.EmailConfirmedTimestamp = null;
         user.Email           = userdata.Email;
         user.NormalizedEmail = userdata.Email.ToUpperInvariant();
     }
 }
Esempio n. 4
0
        private async Task <string> DetermineAccountType(HoundDogUser user)
        {
            var roles = await _userManager.GetRolesAsync(user);

            if (roles.Any(x => x.ToLowerInvariant() == "admin"))
            {
                return("Admin");
            }
            if (roles.Any(x => x.ToLowerInvariant() == "user"))
            {
                return("User");
            }
            return("Guest");
        }
        private async Task <(AuthenticatorPayloadDTO GeneratedCode, FieldValidationErrorDTO Error)> GenerateAuthenticatorSharedKey(HoundDogUser user)
        {
            var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);

            if (string.IsNullOrEmpty(unformattedKey))
            {
                await _userManager.ResetAuthenticatorKeyAsync(user);

                unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
            }
            var formattedkey = FormatKey(unformattedKey);
            var qrcodeuri    = GenerateQrCodeUri(user.Email, unformattedKey);

            return(new AuthenticatorPayloadDTO()
            {
                SharedKey = formattedkey, QrCodeUri = qrcodeuri
            }, null);
        }
Esempio n. 6
0
        private async Task <(bool Succeeded, FieldValidationErrorDTO Error)> GeneratePhoneConfirmation(HoundDogUser user)
        {
            if (user.PhoneNumberConfirmed)
            {
                return(false, new FieldValidationErrorDTO(string.Empty, "The user account phone number has already been confirmed!"));
            }

            var sendsuccess = await _smsverifier.SendVerificationToPhoneNumber(user.PhoneNumber);

            if (!sendsuccess)
            {
                return(false, new FieldValidationErrorDTO(string.Empty, $"Could not send verification code to number {user.PhoneNumber}"));
            }
            return(true, new FieldValidationErrorDTO());
        }
        private async Task <(bool Succeeded, FieldValidationErrorDTO Error)> GenerateEmailConfirmation(HoundDogUser user)
        {
            var confirmToken = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            var encodedtoken = HttpUtility.UrlEncode(confirmToken);
            var callbackUrl  = $"{_config.GetSection(IUserEmailManager.HostAPIBaseUrlConfigName)?.Value}api/user/{user.Id}/emailconfirmation?token={encodedtoken}";
            var body         = @$ "<form method='post' action='{callbackUrl}' class='inline'" +
                               $"  <label>Please click the below button to confirm your email address on your HoundDog account.</label><br />" +
                               $"  <button type='submit' class='link-button'>I hereby confirm this email address to be my own</button>" +
                               $"</form>";
            await _emailer.SendEmailAsync(_config.GetSection(IUserEmailManager.SendingFromAddressConfigName)?.Value, user.Email, "HoundDog email verification request", body, true);

            return(true, new FieldValidationErrorDTO());
        }
Esempio n. 8
0
        private async Task <(bool Succeeded, IEnumerable <FieldValidationErrorDTO> Errors)> GeneratePasswordChangeNotification(HoundDogUser user)
        {
            try
            {
                // TODO: buid body
                await _emailer.SendEmailAsync(_config.GetSection("AppSettings:SendingFromAddress")?.Value, user.Email, "HoundDog password change notification", "This is a notification to tell you that your password has been successfully changed, if you did not instigate this action please contact HoundDog security at once!", true);

                return(true, new List <FieldValidationErrorDTO>());
            }
            catch (Exception ex)
            {
                return(false, null);
            }
        }
Esempio n. 9
0
        private async Task <(bool Succeeded, FieldValidationErrorDTO Error)> SendPasswordResetLink(HoundDogUser user)
        {
            try
            {
                var confirmToken = await _userManager.GeneratePasswordResetTokenAsync(user);

                var encodedtoken = HttpUtility.UrlEncode(confirmToken); // WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(confirmToken));
                var callbackUrl  = $"{_config.GetSection("WebClientLinks:BaseUrl")?.Value}resetpassword?userid={user.Id}&token={encodedtoken}";
                var body         = $"Please follow the below link to reset your password;\n\n{callbackUrl}";
                await _emailer.SendEmailAsync(_config.GetSection("AppSettings:SendingFromAddress")?.Value, user.Email, "HoundDog password reset request", body, true);

                return(true, new FieldValidationErrorDTO());
            }
            catch (Exception ex)
            {
                return(false, new FieldValidationErrorDTO(string.Empty, ex.Message));
            }
        }