Added ip locate. Fixed oauth2 mail send. Fixed mail send when generating tokens
This commit is contained in:
@@ -58,7 +58,7 @@ public class OAuth2Controller : Controller
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
token = await UserService.GenerateToken(user);
|
token = await UserService.GenerateToken(user, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Response.Cookies.Append("token", token, new ()
|
Response.Cookies.Append("token", token, new ()
|
||||||
@@ -116,7 +116,7 @@ public class OAuth2Controller : Controller
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
token = await UserService.GenerateToken(user);
|
token = await UserService.GenerateToken(user, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Response.Cookies.Append("token", token, new ()
|
Response.Cookies.Append("token", token, new ()
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ public class UserService
|
|||||||
private readonly AuditLogService AuditLogService;
|
private readonly AuditLogService AuditLogService;
|
||||||
private readonly MailService MailService;
|
private readonly MailService MailService;
|
||||||
private readonly IdentityService IdentityService;
|
private readonly IdentityService IdentityService;
|
||||||
|
private readonly IpLocateService IpLocateService;
|
||||||
|
|
||||||
private readonly string JwtSecret;
|
private readonly string JwtSecret;
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ public class UserService
|
|||||||
SecurityLogService securityLogService,
|
SecurityLogService securityLogService,
|
||||||
AuditLogService auditLogService,
|
AuditLogService auditLogService,
|
||||||
MailService mailService,
|
MailService mailService,
|
||||||
IdentityService identityService)
|
IdentityService identityService, IpLocateService ipLocateService)
|
||||||
{
|
{
|
||||||
UserRepository = userRepository;
|
UserRepository = userRepository;
|
||||||
TotpService = totpService;
|
TotpService = totpService;
|
||||||
@@ -36,6 +37,7 @@ public class UserService
|
|||||||
AuditLogService = auditLogService;
|
AuditLogService = auditLogService;
|
||||||
MailService = mailService;
|
MailService = mailService;
|
||||||
IdentityService = identityService;
|
IdentityService = identityService;
|
||||||
|
IpLocateService = ipLocateService;
|
||||||
|
|
||||||
JwtSecret = configService
|
JwtSecret = configService
|
||||||
.GetSection("Moonlight")
|
.GetSection("Moonlight")
|
||||||
@@ -77,6 +79,7 @@ public class UserService
|
|||||||
});
|
});
|
||||||
|
|
||||||
await MailService.SendMail(user!, "register", values => {});
|
await MailService.SendMail(user!, "register", values => {});
|
||||||
|
|
||||||
await AuditLogService.Log(AuditLogType.Register, x =>
|
await AuditLogService.Log(AuditLogType.Register, x =>
|
||||||
{
|
{
|
||||||
x.Add<User>(user.Email);
|
x.Add<User>(user.Email);
|
||||||
@@ -177,11 +180,13 @@ public class UserService
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
var location = await IpLocateService.GetLocation();
|
||||||
|
|
||||||
await MailService.SendMail(user!, "passwordChange", values =>
|
await MailService.SendMail(user!, "passwordChange", values =>
|
||||||
{
|
{
|
||||||
values.Add("Ip", IdentityService.GetIp());
|
values.Add("Ip", IdentityService.GetIp());
|
||||||
values.Add("Device", IdentityService.GetDevice());
|
values.Add("Device", IdentityService.GetDevice());
|
||||||
values.Add("Location", "In your walls");
|
values.Add("Location", location);
|
||||||
});
|
});
|
||||||
|
|
||||||
await AuditLogService.Log(AuditLogType.ChangePassword, x =>
|
await AuditLogService.Log(AuditLogType.ChangePassword, x =>
|
||||||
@@ -201,6 +206,7 @@ public class UserService
|
|||||||
{
|
{
|
||||||
x.Add<int>(id);
|
x.Add<int>(id);
|
||||||
});
|
});
|
||||||
|
|
||||||
throw new Exception("Invalid username");
|
throw new Exception("Invalid username");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,13 +228,18 @@ public class UserService
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> GenerateToken(User user, bool sendMail = false)
|
public async Task<string> GenerateToken(User user, bool sendMail = false)
|
||||||
|
{
|
||||||
|
var location = await IpLocateService.GetLocation();
|
||||||
|
|
||||||
|
if (sendMail)
|
||||||
{
|
{
|
||||||
await MailService.SendMail(user!, "login", values =>
|
await MailService.SendMail(user!, "login", values =>
|
||||||
{
|
{
|
||||||
values.Add("Ip", IdentityService.GetIp());
|
values.Add("Ip", IdentityService.GetIp());
|
||||||
values.Add("Device", IdentityService.GetDevice());
|
values.Add("Device", IdentityService.GetDevice());
|
||||||
values.Add("Location", "In your walls");
|
values.Add("Location", location);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var token = JwtBuilder.Create()
|
var token = JwtBuilder.Create()
|
||||||
.WithAlgorithm(new HMACSHA256Algorithm())
|
.WithAlgorithm(new HMACSHA256Algorithm())
|
||||||
@@ -257,11 +268,13 @@ public class UserService
|
|||||||
|
|
||||||
await AuditLogService.Log(AuditLogType.PasswordReset, x => {});
|
await AuditLogService.Log(AuditLogType.PasswordReset, x => {});
|
||||||
|
|
||||||
|
var location = await IpLocateService.GetLocation();
|
||||||
|
|
||||||
await MailService.SendMail(user, "passwordReset", values =>
|
await MailService.SendMail(user, "passwordReset", values =>
|
||||||
{
|
{
|
||||||
values.Add("Ip", IdentityService.GetIp());
|
values.Add("Ip", IdentityService.GetIp());
|
||||||
values.Add("Device", IdentityService.GetDevice());
|
values.Add("Device", IdentityService.GetDevice());
|
||||||
values.Add("Location", "In your walls");
|
values.Add("Location", location);
|
||||||
values.Add("Password", newPassword);
|
values.Add("Password", newPassword);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user