Bläddra i källkod

Merge branch 'bugfix/reset_password_clean' of Neca/HRCenter into BE_dev

pull/29/head
safet.purkovic 3 år sedan
förälder
incheckning
a27784bd0b

+ 24
- 9
Diligent.WebAPI.Business/Services/UserService.cs Visa fil

@@ -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);

+ 7
- 0
Diligent.WebAPI.Business/Settings/FrontEndSettings.cs Visa fil

@@ -0,0 +1,7 @@
namespace Diligent.WebAPI.Business.Settings
{
public class FrontEndSettings
{
public string BaseUrl { get; set; }
}
}

+ 1
- 0
Diligent.WebAPI.Host/Extensions/MailServerConfigurationExtension.cs Visa fil

@@ -5,6 +5,7 @@
public static void ConfigureMailServer(this WebApplicationBuilder builder)
{
builder.Services.Configure<MailSettings>(builder.Configuration.GetSection("Mail"));
builder.Services.Configure<FrontEndSettings>(builder.Configuration.GetSection("FrontEnd"));
}
}
}

+ 3
- 0
Diligent.WebAPI.Host/appsettings.Development.json Visa fil

@@ -16,5 +16,8 @@
"SmtpPassword": "66443869eaad55",
"SmtpFrom": "noreply@hrcenter.net",
"SmtpFromName": "HRCenter Team"
},
"FrontEnd": {
"BaseUrl": "http://localhost:3000"
}
}

+ 3
- 0
Diligent.WebAPI.Host/appsettings.json Visa fil

@@ -16,5 +16,8 @@
"SmtpPassword": "66443869eaad55",
"SmtpFrom": "noreply@hrcenter.net",
"SmtpFromName": "HRCenter Team"
},
"FrontEnd": {
"BaseUrl": "http://localhost:3000"
}
}

Laddar…
Avbryt
Spara