login improvements
This commit is contained in:
@@ -563,11 +563,11 @@ namespace Oqtane.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
// GET api/<controller>/loginlink/x
|
||||
[HttpGet("loginlink/{email}")]
|
||||
public async Task<bool> SendLoginLink(string email)
|
||||
// GET api/<controller>/loginlink/x/y
|
||||
[HttpGet("loginlink/{email}/{returnurl}")]
|
||||
public async Task<bool> SendLoginLink(string email, string returnurl)
|
||||
{
|
||||
return await _userManager.SendLoginLink(email);
|
||||
return await _userManager.SendLoginLink(email, returnurl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Oqtane.Managers
|
||||
Task<List<UserLogin>> GetLogins(int userId, int siteId);
|
||||
Task<User> AddLogin(User user, string token, string type, string key, string name);
|
||||
Task DeleteLogin(int userId, string provider, string key);
|
||||
Task<bool> SendLoginLink(string email);
|
||||
Task<bool> SendLoginLink(string email, string returnurl);
|
||||
}
|
||||
|
||||
public class UserManager : IUserManager
|
||||
@@ -960,7 +960,7 @@ namespace Oqtane.Managers
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> SendLoginLink(string email)
|
||||
public async Task<bool> SendLoginLink(string email, string returnurl)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -973,7 +973,7 @@ namespace Oqtane.Managers
|
||||
|
||||
var alias = _tenantManager.GetAlias();
|
||||
var user = GetUser(identityuser.UserName, alias.SiteId);
|
||||
string url = alias.Protocol + alias.Name + "/pages/loginlink?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
|
||||
string url = alias.Protocol + alias.Name + "/pages/loginlink?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token) + "&returnurl=" + WebUtility.UrlEncode(returnurl);
|
||||
string siteName = _sites.GetSite(alias.SiteId).Name;
|
||||
string subject = _localizer["LoginLinkEmailSubject"];
|
||||
subject = subject.Replace("[SiteName]", siteName);
|
||||
|
||||
@@ -27,38 +27,45 @@ namespace Oqtane.Pages
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(string name, string token)
|
||||
public async Task<IActionResult> OnGetAsync(string name, string token, string returnurl)
|
||||
{
|
||||
var returnurl = "/login";
|
||||
returnurl = (returnurl == null) ? "" : WebUtility.UrlDecode(returnurl);
|
||||
|
||||
if (bool.Parse(HttpContext.GetSiteSettings().GetValue("LoginOptions:LoginLink", "false")) &&
|
||||
!User.Identity.IsAuthenticated && !string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(token))
|
||||
!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(token))
|
||||
{
|
||||
var validuser = false;
|
||||
|
||||
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(name);
|
||||
if (identityuser != null)
|
||||
if (!User.Identity.IsAuthenticated)
|
||||
{
|
||||
var result = await _identityUserManager.ConfirmEmailAsync(identityuser, token);
|
||||
if (result.Succeeded)
|
||||
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(name);
|
||||
if (identityuser != null)
|
||||
{
|
||||
await _identitySignInManager.SignInAsync(identityuser, false);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Security, "Login Link Successful For User {Username}", name);
|
||||
validuser = true;
|
||||
returnurl = "/";
|
||||
var result = await _identityUserManager.ConfirmEmailAsync(identityuser, token);
|
||||
if (result.Succeeded)
|
||||
{
|
||||
await _identitySignInManager.SignInAsync(identityuser, false);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Security, "Login Link Successful For User {Username}", name);
|
||||
validuser = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!validuser)
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Login Link Failed For User {Username}", name);
|
||||
returnurl += $"?status={ExternalLoginStatus.LoginLinkFailed}";
|
||||
returnurl = HttpContext.GetAlias().Path + $"/login?status={ExternalLoginStatus.LoginLinkFailed}";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Login Link Attempt For User {Username}", name);
|
||||
returnurl = "/";
|
||||
returnurl = HttpContext.GetAlias().Path;
|
||||
}
|
||||
|
||||
if (!returnurl.StartsWith("/"))
|
||||
{
|
||||
returnurl = "/" + returnurl;
|
||||
}
|
||||
|
||||
return LocalRedirect(Url.Content("~" + returnurl));
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
@@ -11,7 +9,6 @@ using Oqtane.Extensions;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Managers;
|
||||
using Oqtane.Shared;
|
||||
using Radzen.Blazor.Markdown;
|
||||
|
||||
namespace Oqtane.Pages
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ using Oqtane.Infrastructure;
|
||||
using Oqtane.Managers;
|
||||
using Oqtane.Security;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.UI;
|
||||
|
||||
namespace Oqtane.Pages
|
||||
{
|
||||
@@ -103,7 +104,7 @@ namespace Oqtane.Pages
|
||||
{
|
||||
identityuser = null;
|
||||
var requestOptionsJson = await _identitySignInManager.MakePasskeyRequestOptionsAsync(identityuser);
|
||||
returnurl += $"?options={WebUtility.UrlEncode(requestOptionsJson)}";
|
||||
returnurl = HttpContext.GetAlias().Path + $"/login?options={WebUtility.UrlEncode(requestOptionsJson)}&returnurl={WebUtility.UrlEncode(returnurl)}";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -129,6 +130,7 @@ namespace Oqtane.Pages
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Passkey Login Failed - Invalid Credential");
|
||||
returnurl = HttpContext.GetAlias().Path + $"/login?status={ExternalLoginStatus.PasskeyFailed}&returnurl={WebUtility.UrlEncode(returnurl)}";
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user