feat: 增加用户登录授权方法
This commit is contained in:
parent
9ed6fc4541
commit
206368282d
|
@ -1,6 +1,7 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Longbow.Security.Cryptography" Version="5.2.0" />
|
||||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
|
||||||
|
|
|
@ -1,14 +1,57 @@
|
||||||
using BootstrapAdmin.Web.Core;
|
using BootstrapAdmin.DataAccess.Models;
|
||||||
|
using BootstrapAdmin.Web.Core;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
|
|
||||||
namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
||||||
{
|
{
|
||||||
class DictsService : BaseDatabase, IDicts
|
class DictsService : BaseDatabase, IDicts
|
||||||
{
|
{
|
||||||
|
private string AppId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="db"></param>
|
/// <param name="db"></param>
|
||||||
public DictsService(IDatabase db) => Database = db;
|
/// <param name="configuration"></param>
|
||||||
|
public DictsService(IDatabase db, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
Database = db;
|
||||||
|
AppId = configuration.GetValue("AppId", "BA");
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Dict> GetAll() => Database.Fetch<Dict>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取 站点 Title 配置信息
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public string GetWebTitle()
|
||||||
|
{
|
||||||
|
var dicts = GetAll();
|
||||||
|
var title = "网站标题";
|
||||||
|
var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == AppId)?.Name;
|
||||||
|
if (!string.IsNullOrEmpty(name))
|
||||||
|
{
|
||||||
|
title = dicts.First(d => d.Category == name && d.Name == "网站标题")?.Code ?? "网站标题";
|
||||||
|
}
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取站点 Footer 配置信息
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public string GetWebFooter()
|
||||||
|
{
|
||||||
|
var dicts = GetAll();
|
||||||
|
var title = "网站页脚";
|
||||||
|
var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == AppId)?.Name;
|
||||||
|
if (!string.IsNullOrEmpty(name))
|
||||||
|
{
|
||||||
|
title = dicts.First(d => d.Category == name && d.Name == "网站页脚")?.Code ?? "网站页脚";
|
||||||
|
}
|
||||||
|
return title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
using BootstrapAdmin.Web.Core;
|
using BootstrapAdmin.DataAccess.Models;
|
||||||
|
using BootstrapAdmin.Web.Core;
|
||||||
|
using Longbow.Security.Cryptography;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
|
|
||||||
namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
||||||
|
@ -20,8 +22,22 @@ namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
public bool Authenticate(string userName, string password)
|
public bool Authenticate(string userName, string password)
|
||||||
{
|
{
|
||||||
return true;
|
var user = Database.SingleOrDefault<User>("select DisplayName, Password, PassSalt from Users where ApprovedTime is not null and UserName = @0", userName);
|
||||||
|
|
||||||
|
var isAuth = false;
|
||||||
|
if (user != null && !string.IsNullOrEmpty(user.PassSalt))
|
||||||
|
{
|
||||||
|
isAuth = user.Password == LgbCryptography.ComputeHash(password, user.PassSalt);
|
||||||
}
|
}
|
||||||
|
return isAuth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public string GetDisplayName(string userName) => Database.ExecuteScalar<string>("select DisplayName from Users where UserName = @0", userName);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue