auth improvements related to multi-tenancy
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -21,20 +21,23 @@ namespace Oqtane.Pages
|
||||
|
||||
public async Task<IActionResult> OnPostAsync(string username, string password, bool remember, string returnurl)
|
||||
{
|
||||
bool validuser = false;
|
||||
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(username);
|
||||
if (identityuser != null)
|
||||
if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
|
||||
{
|
||||
var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, password, false);
|
||||
if (result.Succeeded)
|
||||
bool validuser = false;
|
||||
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(username);
|
||||
if (identityuser != null)
|
||||
{
|
||||
validuser = true;
|
||||
var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, password, false);
|
||||
if (result.Succeeded)
|
||||
{
|
||||
validuser = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (validuser)
|
||||
{
|
||||
await _identitySignInManager.SignInAsync(identityuser, remember);
|
||||
if (validuser)
|
||||
{
|
||||
await _identitySignInManager.SignInAsync(identityuser, remember);
|
||||
}
|
||||
}
|
||||
|
||||
if (returnurl == null)
|
||||
@ -49,4 +52,4 @@ namespace Oqtane.Pages
|
||||
return LocalRedirect(Url.Content("~" + returnurl));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Pages
|
||||
{
|
||||
@ -12,7 +12,10 @@ namespace Oqtane.Pages
|
||||
{
|
||||
public async Task<IActionResult> OnPostAsync(string returnurl)
|
||||
{
|
||||
await HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme);
|
||||
if (HttpContext.User.Identity.IsAuthenticated)
|
||||
{
|
||||
await HttpContext.SignOutAsync(Constants.AuthenticationScheme);
|
||||
}
|
||||
|
||||
if (returnurl == null)
|
||||
{
|
||||
@ -26,4 +29,4 @@ namespace Oqtane.Pages
|
||||
return LocalRedirect(Url.Content("~" + returnurl));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,21 +48,24 @@ namespace Oqtane.Pages
|
||||
}
|
||||
|
||||
// if culture not specified and framework is installed
|
||||
if (HttpContext.Request.Cookies[CookieRequestCultureProvider.DefaultCookieName] == null && !string.IsNullOrEmpty(_configuration.GetConnectionString("DefaultConnection")))
|
||||
if (!string.IsNullOrEmpty(_configuration.GetConnectionString("DefaultConnection")))
|
||||
{
|
||||
var alias = _tenantManager.GetAlias();
|
||||
if (alias != null)
|
||||
{
|
||||
// set default language for site if the culture is not supported
|
||||
var languages = _languages.GetLanguages(alias.SiteId);
|
||||
if (languages.Any() && languages.All(l => l.Code != CultureInfo.CurrentUICulture.Name))
|
||||
if (HttpContext.Request.Cookies[CookieRequestCultureProvider.DefaultCookieName] == null)
|
||||
{
|
||||
var defaultLanguage = languages.Where(l => l.IsDefault).SingleOrDefault() ?? languages.First();
|
||||
SetLocalizationCookie(defaultLanguage.Code);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetLocalizationCookie(_localizationManager.GetDefaultCulture());
|
||||
// set default language for site if the culture is not supported
|
||||
var languages = _languages.GetLanguages(alias.SiteId);
|
||||
if (languages.Any() && languages.All(l => l.Code != CultureInfo.CurrentUICulture.Name))
|
||||
{
|
||||
var defaultLanguage = languages.Where(l => l.IsDefault).SingleOrDefault() ?? languages.First();
|
||||
SetLocalizationCookie(defaultLanguage.Code);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetLocalizationCookie(_localizationManager.GetDefaultCulture());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user