:sparkles:新增手机号登录功能
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using ZR.Common;
|
||||
using ZR.Common;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
public class CacheService
|
||||
{
|
||||
private readonly static string CK_verifyScan = "verifyScan_";
|
||||
private readonly static string CK_phoneSmsCode = "phone_sms_code_";
|
||||
#region 用户权限 缓存
|
||||
public static List<string> GetUserPerms(string key)
|
||||
{
|
||||
@@ -59,5 +59,23 @@ namespace ZR.Service.System
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static object SetPhoneCode(string key, string val)
|
||||
{
|
||||
var ck = CK_phoneSmsCode + key;
|
||||
|
||||
return CacheHelper.SetCache(ck, val, 10);
|
||||
}
|
||||
public static bool CheckPhoneCode(string key, string val)
|
||||
{
|
||||
var ck = CK_phoneSmsCode + key;
|
||||
var save_code = CacheHelper.Get(ck);
|
||||
|
||||
if (save_code != null && save_code.Equals(val))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using Infrastructure;
|
||||
using System;
|
||||
using ZR.Model;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.ServiceCore.Model.Dto;
|
||||
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
@@ -15,7 +14,14 @@ namespace ZR.Service.System.IService
|
||||
/// <param name="logininfor"></param>
|
||||
/// <returns></returns>
|
||||
public SysUser Login(LoginBodyDto loginBody, SysLogininfor logininfor);
|
||||
|
||||
/// <summary>
|
||||
/// 手机号登录
|
||||
/// </summary>
|
||||
/// <param name="loginBody"></param>
|
||||
/// <param name="logininfor"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
SysUser PhoneLogin(PhoneLoginDto loginBody, SysLogininfor logininfor, SysUser user);
|
||||
/// <summary>
|
||||
/// 查询操作日志
|
||||
/// </summary>
|
||||
|
||||
@@ -81,6 +81,6 @@ namespace ZR.Service.System.IService
|
||||
|
||||
SysUser Login(LoginBodyDto user);
|
||||
|
||||
void UpdateLoginInfo(LoginBodyDto user, long userId);
|
||||
void UpdateLoginInfo(string userIP, long userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Extensions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using UAParser;
|
||||
using ZR.Model;
|
||||
@@ -8,6 +7,7 @@ using ZR.Model.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Repository;
|
||||
using ZR.Service.System.IService;
|
||||
using ZR.ServiceCore.Model.Dto;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
@@ -64,10 +64,40 @@ namespace ZR.Service.System
|
||||
logininfor.Status = "0";
|
||||
logininfor.Msg = "登录成功";
|
||||
AddLoginInfo(logininfor);
|
||||
SysUserService.UpdateLoginInfo(loginBody, user.UserId);
|
||||
SysUserService.UpdateLoginInfo(loginBody.LoginIP, user.UserId);
|
||||
return user;
|
||||
}
|
||||
/// <summary>
|
||||
/// 登录验证
|
||||
/// </summary>
|
||||
/// <param name="logininfor"></param>
|
||||
/// <param name="loginBody"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public SysUser PhoneLogin(PhoneLoginDto loginBody, SysLogininfor logininfor, SysUser user)
|
||||
{
|
||||
logininfor.UserName = user.UserName;
|
||||
logininfor.Status = "1";
|
||||
logininfor.LoginTime = DateTime.Now;
|
||||
logininfor.Ipaddr = loginBody.LoginIP;
|
||||
|
||||
ClientInfo clientInfo = httpContextAccessor.HttpContext.GetClientInfo();
|
||||
logininfor.Browser = clientInfo.ToString();
|
||||
logininfor.Os = clientInfo.OS.ToString();
|
||||
|
||||
if (user.Status == 1)
|
||||
{
|
||||
logininfor.Msg = "该用户已禁用";
|
||||
AddLoginInfo(logininfor);
|
||||
throw new CustomException(ResultCode.LOGIN_ERROR, logininfor.Msg, false);
|
||||
}
|
||||
|
||||
logininfor.Status = "0";
|
||||
logininfor.Msg = "登录成功";
|
||||
AddLoginInfo(logininfor);
|
||||
SysUserService.UpdateLoginInfo(loginBody.LoginIP, user.UserId);
|
||||
return user;
|
||||
}
|
||||
/// <summary>
|
||||
/// 查询登录日志
|
||||
/// </summary>
|
||||
|
||||
@@ -329,12 +329,12 @@ namespace ZR.Service
|
||||
/// <summary>
|
||||
/// 修改登录信息
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="userIP"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public void UpdateLoginInfo(LoginBodyDto user, long userId)
|
||||
public void UpdateLoginInfo(string userIP, long userId)
|
||||
{
|
||||
Update(new SysUser() { LoginIP = user.LoginIP, LoginDate = DateTime.Now, UserId = userId }, it => new { it.LoginIP, it.LoginDate });
|
||||
Update(new SysUser() { LoginIP = userIP, LoginDate = DateTime.Now, UserId = userId }, it => new { it.LoginIP, it.LoginDate });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user