feat: 增加 ILogin 业务逻辑
This commit is contained in:
parent
3de89cd94e
commit
5b8ca016c2
|
@ -0,0 +1,63 @@
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 登录用户信息实体类
|
||||||
|
/// </summary>
|
||||||
|
public class LoginLog
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获得/设置 Id
|
||||||
|
/// </summary>
|
||||||
|
public string? Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获得/设置 用户名
|
||||||
|
/// </summary>
|
||||||
|
[DisplayName("登录名称")]
|
||||||
|
public string UserName { get; set; } = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获得/设置 登录时间
|
||||||
|
/// </summary>
|
||||||
|
[DisplayName("登录时间")]
|
||||||
|
public DateTime LoginTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获得/设置 登录IP地址
|
||||||
|
/// </summary>
|
||||||
|
[DisplayName("主机")]
|
||||||
|
public string Ip { get; set; } = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获得/设置 登录浏览器
|
||||||
|
/// </summary>
|
||||||
|
[DisplayName("浏览器")]
|
||||||
|
public string Browser { get; set; } = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获得/设置 登录操作系统
|
||||||
|
/// </summary>
|
||||||
|
[DisplayName("操作系统")]
|
||||||
|
public string OS { get; set; } = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获得/设置 登录地点
|
||||||
|
/// </summary>
|
||||||
|
[DisplayName("登录地点")]
|
||||||
|
public string City { get; set; } = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获得/设置 登录是否成功
|
||||||
|
/// </summary>
|
||||||
|
[DisplayName("登录结果")]
|
||||||
|
public string Result { get; set; } = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获得/设置 用户 UserAgent
|
||||||
|
/// </summary>
|
||||||
|
[DisplayName("登录名称")]
|
||||||
|
public string UserAgent { get; set; } = "";
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,9 +33,11 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
// 增加数据服务
|
// 增加数据服务
|
||||||
services.AddSingleton(typeof(IDataService<>), typeof(DefaultDataService<>));
|
services.AddSingleton(typeof(IDataService<>), typeof(DefaultDataService<>));
|
||||||
|
|
||||||
|
// 增加业务服务
|
||||||
services.AddSingleton<INavigations, NavigationsService>();
|
services.AddSingleton<INavigations, NavigationsService>();
|
||||||
services.AddSingleton<IDicts, DictsService>();
|
services.AddSingleton<IDicts, DictsService>();
|
||||||
services.AddSingleton<IUsers, UsersService>();
|
services.AddSingleton<IUsers, UsersService>();
|
||||||
|
services.AddSingleton<ILogins, LoginsService>();
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
using BootstrapAdmin.Web.Core;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
||||||
|
{
|
||||||
|
class LoginsService : ILogins
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="result"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public Task<bool> Log(string userName, bool result)
|
||||||
|
{
|
||||||
|
return Task.FromResult(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
namespace BootstrapAdmin.Web.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public interface ILogins
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="result"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> Log(string userName, bool result);
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,11 +60,12 @@ namespace Bootstrap.Admin.Controllers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The login.</returns>
|
/// <returns>The login.</returns>
|
||||||
/// <param name="userService"></param>
|
/// <param name="userService"></param>
|
||||||
|
/// <param name="loginService"></param>
|
||||||
/// <param name="userName">User name.</param>
|
/// <param name="userName">User name.</param>
|
||||||
/// <param name="password">Password.</param>
|
/// <param name="password">Password.</param>
|
||||||
/// <param name="remember">Remember.</param>
|
/// <param name="remember">Remember.</param>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> Login([FromServices] IUsers userService, string userName, string password, string remember)
|
public async Task<IActionResult> Login([FromServices] IUsers userService, [FromServices] ILogins loginService, string userName, string password, string remember)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
|
if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
|
||||||
{
|
{
|
||||||
|
@ -72,7 +73,7 @@ namespace Bootstrap.Admin.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
var auth = userService.Authenticate(userName, password);
|
var auth = userService.Authenticate(userName, password);
|
||||||
//await HttpContext.Log(userName, auth);
|
await loginService.Log(userName, auth);
|
||||||
return auth ? await SignInAsync(userName, remember == "true") : RedirectLogin();
|
return auth ? await SignInAsync(userName, remember == "true") : RedirectLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue