|
|
@ -1,7 +1,15 @@ |
|
|
|
using CustomerOnlineV2.Common.Models; |
|
|
|
using CustomerOnlineV2.Common.Helper; |
|
|
|
using CustomerOnlineV2.Common.Models; |
|
|
|
using CustomerOnlineV2.Common.Models.AccountModel; |
|
|
|
using CustomerOnlineV2.Common.Models.HomeModel; |
|
|
|
using CustomerOnlineV2.Common.Models.Notification; |
|
|
|
using CustomerOnlineV2.Repository.Repository.AccountRepository; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.IdentityModel.Tokens; |
|
|
|
using Notify = Azure.Core.HttpHeader; |
|
|
|
using Newtonsoft.Json; |
|
|
|
|
|
|
|
using static CustomerOnlineV2.Common.Models.Notification.PasswordGenerator; |
|
|
|
|
|
|
|
namespace CustomerOnlineV2.Business.Business.AccountBusiness |
|
|
|
{ |
|
|
@ -32,7 +40,91 @@ namespace CustomerOnlineV2.Business.Business.AccountBusiness |
|
|
|
} |
|
|
|
public async Task<CommonResponse> PasswordReset(PasswordResetModel model, LoginResponse logindetails) |
|
|
|
{ |
|
|
|
//var randomPassword = PasswordGenerator.GenerateRandomPassword();
|
|
|
|
//model.RandomPassword = randomPassword;
|
|
|
|
|
|
|
|
|
|
|
|
SendNotificationRequest request = new SendNotificationRequest() |
|
|
|
{ |
|
|
|
IsBulkNotification = false, |
|
|
|
UserName = model.Username, |
|
|
|
//ProcessId = processId,
|
|
|
|
ProviderId = "ResetPassword", |
|
|
|
NotificationTypeId = NOTIFICATION_TYPE.EMAIL.ToString(), |
|
|
|
//Template = Common.Model.Enum.NotifyTemplate.RESET_PASSWORD_EMAIL,
|
|
|
|
Recipients = new List<RecipientViewModel>() |
|
|
|
{ |
|
|
|
new RecipientViewModel() |
|
|
|
{ |
|
|
|
NotificationContent = new NotificationDTO() { |
|
|
|
// Body = JsonConvert.SerializeObject(bodyMappings),
|
|
|
|
//Title will be set by mapping json
|
|
|
|
}, |
|
|
|
Address= model.Username |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return await _accountRepo.PasswordReset(model, logindetails); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static string GenerateRandomPassword(PasswordOptions opts = null) |
|
|
|
{ |
|
|
|
if (opts == null) opts = new PasswordOptions() |
|
|
|
{ |
|
|
|
RequiredLength = 8, |
|
|
|
RequiredUniqueChars = 4, |
|
|
|
RequireDigit = true, |
|
|
|
RequireLowercase = true, |
|
|
|
RequireNonAlphanumeric = true, |
|
|
|
RequireUppercase = true |
|
|
|
}; |
|
|
|
|
|
|
|
string[] randomChars = new[] { |
|
|
|
"ABCDEFGHJKMNPQRSTUVWXYZ", // uppercase
|
|
|
|
"abcdefghjkmnpqrstuvwxyz", // lowercase
|
|
|
|
"23456789", // digits
|
|
|
|
"@#" // non-alphanumeric
|
|
|
|
}; |
|
|
|
string[] randomChars1 = new[] { |
|
|
|
// uppercase
|
|
|
|
"abcdefghjkmnpqrstuvwxyz", // lowercase
|
|
|
|
"23456789", // digits
|
|
|
|
// non-alphanumeric
|
|
|
|
}; |
|
|
|
Random rand = new Random(); |
|
|
|
List<char> chars = new List<char>(); |
|
|
|
|
|
|
|
if (opts.RequireUppercase) |
|
|
|
chars.Insert(rand.Next(0, chars.Count), |
|
|
|
randomChars[0][rand.Next(0, randomChars[0].Length)]); |
|
|
|
|
|
|
|
if (opts.RequireLowercase) |
|
|
|
chars.Insert(rand.Next(0, chars.Count), |
|
|
|
randomChars[1][rand.Next(0, randomChars[1].Length)]); |
|
|
|
|
|
|
|
if (opts.RequireDigit) |
|
|
|
chars.Insert(rand.Next(0, chars.Count), |
|
|
|
randomChars[2][rand.Next(0, randomChars[2].Length)]); |
|
|
|
|
|
|
|
if (opts.RequireNonAlphanumeric) |
|
|
|
chars.Insert(rand.Next(0, chars.Count), |
|
|
|
randomChars[3][rand.Next(0, randomChars[3].Length)]); |
|
|
|
|
|
|
|
for (int i = chars.Count; i < opts.RequiredLength |
|
|
|
|| chars.Distinct().Count() < opts.RequiredUniqueChars; i++) |
|
|
|
{ |
|
|
|
string rcs = randomChars1[rand.Next(0, randomChars1.Length)]; |
|
|
|
|
|
|
|
chars.Insert(rand.Next(0, chars.Count), |
|
|
|
rcs[rand.Next(0, rcs.Length)]); |
|
|
|
} |
|
|
|
|
|
|
|
return new string(chars.ToArray()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |