|
|
|
@@ -1,12 +1,6 @@ |
|
|
|
using Diligent.WebAPI.Business.Services.Interfaces; |
|
|
|
using Diligent.WebAPI.Data.Entities; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.AspNetCore.WebUtilities; |
|
|
|
using Microsoft.AspNetCore.WebUtilities; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using System; |
|
|
|
using System.Net; |
|
|
|
using System.Security.Policy; |
|
|
|
|
|
|
|
namespace Diligent.WebAPI.Business.Services |
|
|
|
{ |
|
|
|
@@ -14,6 +8,7 @@ namespace Diligent.WebAPI.Business.Services |
|
|
|
public class UserService : IUserService |
|
|
|
{ |
|
|
|
private readonly AuthorizationSettings _authSettings; |
|
|
|
private readonly FrontEndSettings _frontEndSettings; |
|
|
|
private readonly UserManager<User> _userManager; |
|
|
|
private readonly IMapper _mapper; |
|
|
|
private readonly DatabaseContext _databaseContext; |
|
|
|
@@ -22,9 +17,10 @@ namespace Diligent.WebAPI.Business.Services |
|
|
|
private const string GoogleApiTokenInfoUrl = "https://www.googleapis.com/oauth2/v3/tokeninfo?id_token={0}"; |
|
|
|
private string[] SupportedClientsIds = { "" }; |
|
|
|
|
|
|
|
public UserService(IOptions<AuthorizationSettings> authSettings, UserManager<User> userManager, IMapper mapper, DatabaseContext databaseContext, IEmailer emailer, ILogger<UserService> logger) |
|
|
|
public UserService(IOptions<AuthorizationSettings> authSettings, IOptions<FrontEndSettings> frontEndSettings, UserManager<User> userManager, IMapper mapper, DatabaseContext databaseContext, IEmailer emailer, ILogger<UserService> logger) |
|
|
|
{ |
|
|
|
_authSettings = authSettings.Value; |
|
|
|
_frontEndSettings = frontEndSettings.Value; |
|
|
|
_userManager = userManager; |
|
|
|
_mapper = mapper; |
|
|
|
_databaseContext = databaseContext; |
|
|
|
@@ -401,7 +397,7 @@ namespace Diligent.WebAPI.Business.Services |
|
|
|
|
|
|
|
token = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(token)); |
|
|
|
|
|
|
|
await _emailer.SendEmailAndWriteToDbAsync(email, "Reset password", $"<a href='http://localhost:3000/reset-password?token={token}&email={email}'>RESET PASSWORD LINK</a>", isHtml: true); |
|
|
|
await _emailer.SendEmailAndWriteToDbAsync(email, "Reset password", renderHTMLtoString($"{_frontEndSettings.BaseUrl}/reset-password?token={token}&email={email}"), isHtml: true); |
|
|
|
|
|
|
|
user.PasswordResetToken = token; |
|
|
|
await _databaseContext.SaveChangesAsync(); |
|
|
|
@@ -411,6 +407,25 @@ namespace Diligent.WebAPI.Business.Services |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private string renderHTMLtoString(string url) |
|
|
|
{ |
|
|
|
return "<div style=\"font-family: sans-serif\">" + |
|
|
|
"<div style=\"font-family: sans-serif;text-align: center;\">" + |
|
|
|
"<h2 style=\"color: #017397;\">HR Center Password Reset</h2>" + |
|
|
|
"<p style=\"font-size: 20px\">" + |
|
|
|
"To reset your HR Center password, please click on the button below." + |
|
|
|
"</p>" + |
|
|
|
"<a style = \"color: white;text-decoration:none;background-color: #017397;cursor: pointer;font-size: 20px;width: 220px;text-align: center;border-radius: 5px;padding: 5px 15px;height: 25px;\" " + |
|
|
|
$"href=\"{url}\">" + |
|
|
|
" RESET PASSWORD" + |
|
|
|
"</a>" + |
|
|
|
"<p style = \"font-size: 12px; margin-top: 25px;\" >" + |
|
|
|
"Please do not reply to this email.This message was sent from a notification-only address that is not monitored." + |
|
|
|
"</p>" + |
|
|
|
"</div>" + |
|
|
|
"</div>"; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<ServiceResponseDTO<object>> PasswordResetAsync(string email, string code, string password) |
|
|
|
{ |
|
|
|
var user = await _userManager.FindByEmailAsync(email); |