| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using SqlSugar;
- using WMS.Util;
- using WMS.Info;
- namespace WMS.Core
- {
- public class LoginBLLCore
- {
- /// <summary>
- /// 检测登录用户有效性
- /// </summary>
- public static ACL_USERITEM CheckLoginUser(string UserNo, string UserPwd, EAppType AppType, string WarehouseNo, List<string> WAreaNoList, SqlSugarClient Ctx)
- {
- try
- {
- if (string.IsNullOrWhiteSpace(UserNo))
- throw SysExCore.ThrowFailException("登录用户名为空!!!");
- if (string.IsNullOrWhiteSpace(UserPwd))
- throw SysExCore.ThrowFailException("登录密码为空!!!");
- if (AppType == EAppType.TV || AppType == EAppType.Interface)
- throw SysExCore.ThrowFailException("登录APP类型不正确!!!");
- //离线仓库登录
- //if (AppType == EAppType.OffLineRF)
- //{
- // if (string.IsNullOrWhiteSpace(WarehouseNo))
- // throw SysExCore.ThrowFailException("仓库号为空!!!");
- // //判断仓库
- // var wh = Ctx.Queryable<BASE_WAREHOUSE>().Where(it => it.F_NO == WarehouseNo).First();
- // if (wh == null)
- // throw SysExCore.ThrowFailException("输入参数中仓库号在仓库列表中不存在!!!");
- // if (WAreaNoList == null || WAreaNoList.Count == 0)
- // throw SysExCore.ThrowFailException("仓库区域为空!!!");
- // if (wh.F_TYPENUM != (int)EWarehouseType.OfflineRFWarehouse)
- // throw SysExCore.ThrowFailException("输入参数中仓库号不是离线仓库类型!!!");
- // //判断区域与仓库有没有匹配
- // var walist = Ctx.Queryable<BASE_WAREA>().Where(it => it.F_WAREHOUSENO == WarehouseNo).ToList();
- // if (walist == null || walist.Count == 0)
- // throw SysExCore.ThrowFailException("输入参数中区域号在仓库区域列表中不存在!!!");
- // if (WAreaNoList.Any(it => !walist.Any(b => it == b.F_NO)))
- // throw SysExCore.ThrowFailException("输入参数仓库号与区域号不匹配!!!");
- //}
- //获取数据
- var user = Ctx.Queryable<ACL_USERITEM>().Where(it => it.F_NO.ToUpper() == UserNo.ToUpper()).First();
- if (user == null)
- throw SysExCore.ThrowFailException("无法找到指定用户");
- if (user.F_ISDELETE > 0)
- throw SysExCore.ThrowFailException("用户已删除!!!");
- if (user.F_ISSTOP > 0)
- throw SysExCore.ThrowFailException("用户已停用!!!");
- if (user.F_AUTOSTOPTIME < DateTime.Now)
- throw SysExCore.ThrowFailException("用户已过期!!!");
- if (user.F_PWDERRQTY >= SysSetCore.GetSysSet().UserPwdErrQty)
- throw SysExCore.ThrowFailException(string.Format("用户密码错误已超过{0}次,已被锁定。", SysSetCore.GetSysSet().UserPwdErrQty));
- //用户密码已过期
- if (DateTime.MaxValue!=user.F_EDITPWDTIME)
- {
- if (user.F_EDITPWDTIME.AddDays(SysSetCore.GetSysSet().UserPwdExpD) < DateTime.Now)
- throw SysExCore.ThrowPwdExpiration();
- }
- //用户密码错误
- if (user.F_PASSWORD != SysSecurityCore.Aes256Encrypt(UserPwd))
- {
- int qty = SysSetCore.GetSysSet().UserPwdErrQty - user.F_PWDERRQTY;
- if (user.F_PWDERRQTY > 0)
- throw new SysExCore(ESysExType.PwdError, string.Format("用户密码错误,您还有{0}次", qty > 0 ? qty : 0));
- else
- throw new SysExCore(ESysExType.PwdError, "用户密码错误。");
- }
- if (user.F_PASSWORD == SysSecurityCore.Aes256Encrypt(SysSetCore.GetSysSet().PwdInit))
- {
- throw new SysExCore(ESysExType.PwdInit, "请将初始化密码进行修改。");
- }
- return user;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 是否是管理员
- /// </summary>
- public static bool CheckAdmin(string UserNo)
- {
- bool IsAdmin = false;
- EUserType UserType = GetUserType(UserNo);
- if (UserType == EUserType.SuperAdmin || UserType == EUserType.Super || UserType == EUserType.System)
- {
- IsAdmin = true;
- }
- return IsAdmin;
- }
- /// <summary>
- /// 获取用户类型
- /// </summary>
- public static EUserType GetUserType(string UserNo)
- {
- EUserType UserType = EUserType.User;
- try
- {
- if (UserNo.ToUpper() == EUserType.Super.ToString().ToUpper())
- {
- UserType = EUserType.Super;
- }
- else if (UserNo.ToUpper() == EUserType.System.ToString().ToUpper())
- {
- UserType = EUserType.System;
- }
- else if (UserNo.ToUpper() == EUserType.SuperAdmin.ToString().ToUpper())
- {
- UserType = EUserType.SuperAdmin;
- }
- else
- {
- UserType = EUserType.User;
- }
- //权限管理员
- }
- catch
- {
- }
- return UserType;
- }
- /// <summary>
- /// 更新用户密码错误次数
- /// </summary>
- public static void UpdatePwdErr(string UserNo)
- {
- var i = SysDbCore.GetDbCtx().Updateable<ACL_USERITEM>().SetColumns(it => new ACL_USERITEM() { F_PWDERRQTY = it.F_PWDERRQTY + 1, F_EDITTIME = DateTime.Now, F_EDITUSERNO = UserNo }).Where(it => it.F_NO.ToUpper() == UserNo.ToUpper()).ExecuteCommand();
- if (i <= 0)
- throw SysExCore.ThrowFailException("更新用户密码登录错误次数失败!!!");
- }
- /// <summary>
- /// 检测登录状态
- /// </summary>
- /// <param name="EncryptTokenNo">加密TokenNo</param>
- public static void LoginTokenCheck(string EncryptTokenNo)
- {
- try
- {
- if (string.IsNullOrWhiteSpace(EncryptTokenNo))
- {
- throw SysExCore.ThrowToken();
- }
- SqlSugarClient Ctx = SysDbCore.GetDbCtx();
- string TokenNo = SysSecurityCore.Aes256Decrypt(EncryptTokenNo);
- ACL_USERTOKEN token = Ctx.Queryable<ACL_USERTOKEN>().Where(a => a.F_NO == TokenNo).First();
- if (token == null || string.IsNullOrWhiteSpace(token.F_NO))
- {
- throw SysExCore.ThrowToken();
- }
- if (token.F_APPTYPENUM != (int)EAppType.OffLineRF)
- {
- if (token.F_ETIME != DateTime.MaxValue)
- {
- if (token.F_ETIME.AddMinutes(SysSetCore.GetSysSet().OnLoginTimeOutM) < DateTime.Now)
- throw SysExCore.ThrowLoginTimeout();
- }
- Ctx.Updateable<ACL_USERTOKEN>().SetColumns(it => it.F_ETIME == DateTime.Now).Where(a => a.F_NO == TokenNo).ExecuteCommand();
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- // <summary>
- /// 检测登录状态
- /// </summary>
- public static void LoginTokenCheck()
- {
- LoginTokenCheck(SessionCookieCore.GetLoginTokenNo());
- }
- /// <summary>
- /// 检测登录状态
- /// </summary>
- /// <param name="EncryptTokenNo">加密TokenNo</param>
- public static void LoginTokenCheck(ReqInfo ReqData)
- {
- try
- {
- if (ReqData == null)
- {
- throw SysExCore.ThrowInEmpty();
- }
- LoginTokenCheck(ReqData.EncryptTokenNo);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取用户登录数据
- /// </summary>
- public static LoginUserInfo GetLoginUser(string EncryptTokenNo)
- {
- try
- {
- LoginUserInfo LoginUser = new LoginUserInfo();
- void action(SqlSugarClient ctx)
- {
- if (string.IsNullOrWhiteSpace(EncryptTokenNo))
- {
- throw SysExCore.ThrowFailException("登录凭证为空。");
- }
- string TokenNo = SysSecurityCore.Aes256Decrypt(EncryptTokenNo);
- ACL_USERTOKEN token = ctx.Queryable<ACL_USERTOKEN>().Where(a => a.F_NO == TokenNo).First();
- if (token == null || string.IsNullOrWhiteSpace(token.F_NO))
- {
- throw SysExCore.ThrowFailException("无法找到登录用户信息。");
- }
- if (token == null || string.IsNullOrWhiteSpace(token.F_NO))
- {
- throw SysExCore.ThrowFailException("无法找到登录用户信息。");
- }
- LoginUser.UserNo = token.F_USERNO;
- LoginUser.UserName = token.F_USERNAME;
- LoginUser.UserType = GetUserType(token.F_USERNO);
- LoginUser.IPAddress = token.F_IPADDRESS;
- LoginUser.WAreaNoList = token.F_WAREANOLIST.ToObject<List<string>>();
- LoginUser.WarehouseNo = token.F_WAREHOUSENO;
- LoginUser.EncryptTokenNo = EncryptTokenNo;
- LoginUser.AppType = (EAppType)token.F_APPTYPENUM;
- LoginUser.LoginTime = token.F_BTIME;
- LoginUser.AppDeviceNo = token.F_APPDEVICENO;
- };
- SysDbCore.DbConnExec(action);
- return LoginUser;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取用户登录数据
- /// </summary>
- public static LoginUserInfo GetLoginUser()
- {
- try
- {
- LoginUserInfo LoginUser = GetLoginUser(SessionCookieCore.GetLoginTokenNo());
- void action(SqlSugarClient ctx)
- {
- if (string.IsNullOrWhiteSpace(LoginUser.EncryptTokenNo))
- {
- throw SysExCore.ThrowFailException("登录凭证为空。");
- }
- string TokenNo = SysSecurityCore.Aes256Decrypt(LoginUser.EncryptTokenNo);
- ACL_USERTOKEN token = ctx.Queryable<ACL_USERTOKEN>().Where(a => a.F_NO == TokenNo).First();
- if (token == null || string.IsNullOrWhiteSpace(token.F_NO))
- {
- throw SysExCore.ThrowFailException("无法找到登录用户信息。");
- }
- if (token == null || string.IsNullOrWhiteSpace(token.F_NO))
- {
- throw SysExCore.ThrowFailException("无法找到登录用户信息。");
- }
- LoginUser.UserNo = token.F_USERNO;
- LoginUser.UserName = token.F_USERNAME;
- LoginUser.UserType = GetUserType(token.F_USERNO);
- LoginUser.IPAddress = token.F_IPADDRESS;
- LoginUser.WAreaNoList = token.F_WAREANOLIST.ToObject<List<string>>();
- LoginUser.WarehouseNo = token.F_WAREHOUSENO;
- LoginUser.EncryptTokenNo = LoginUser.EncryptTokenNo;
- LoginUser.AppType = (EAppType)token.F_APPTYPENUM;
- LoginUser.LoginTime = token.F_BTIME;
- LoginUser.AppDeviceNo = token.F_APPDEVICENO;
- };
- SysDbCore.DbConnExec(action);
- return LoginUser;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取用户登录数据
- /// </summary>
- public static LoginUserInfo GetLoginUser(ReqInfo ReqData)
- {
- try
- {
- if (ReqData == null)
- {
- throw SysExCore.ThrowInEmpty();
- }
- return GetLoginUser(ReqData.EncryptTokenNo);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public static byte[] GetVerifyCode()
- {
- try
- {
- string code = "";
- var vcode = VerifyCodeUtil.GetVerifyCode(out code);
- SessionCookieCore.WriteSessionCookieValue(SessionCookieConst.LoginVerifyCodeKey, code);
- return vcode;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- }
- }
|