136 lines
5.7 KiB
C#
Executable File
136 lines
5.7 KiB
C#
Executable File
using Newtonsoft.Json.Linq;
|
|
using Opsoft.Data;
|
|
using Opsoft.Data.Model;
|
|
using Opsoft.NetCore.O3App.Domain.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
|
|
namespace Opsoft.NetCore.O3App.WebApi
|
|
{
|
|
public class UserService : IUserService
|
|
{
|
|
|
|
/// <summary>
|
|
/// 验证用户是否可以登录成功
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public bool IsValid(LoginRequest req)
|
|
{
|
|
try
|
|
{
|
|
using (APPServerContext DBContext = new APPServerContext(req.DBAias, req.UserID))
|
|
{
|
|
SYS_LOGINUSER myUser = DBContext.Database.SqlQuery<SYS_LOGINUSER>(
|
|
" select USER_ID,USER_NAME,PR_PASSWORD,FDELETED " +
|
|
" from SYS_LOGINUSER " +
|
|
" where USER_ID=" + DBContext.GetDBParName("@PA1"),
|
|
DBContext.CreateParameter("@PA1", req.UserID)).SingleOrDefault();
|
|
if (myUser != null)
|
|
{
|
|
var pass = myUser.GetPassWord();
|
|
var encryptPass = MD5Help.MD5Encrypt(pass);
|
|
req.UserName = myUser.USER_NAME;
|
|
if (req.IsFaceLogin || encryptPass.Equals(req.Password))
|
|
{
|
|
LicenseInfo PPermissions = this.GetLicense();
|
|
if (PPermissions.HaveLicense)
|
|
{
|
|
if (PPermissions.LicenseDays >= PPermissions.SerialDate)
|
|
{
|
|
if (PPermissions.LicenseDays < PPermissions.SerialDate.AddDays(30))
|
|
{
|
|
req.errtype = "3";//软件将过服务到期日,请提前申请或购买下一年度服务
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
req.errtype = "8";
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
req.errtype = "4"; //软件服务到期日已过,请申请或购买下一年度服务!
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
req.errtype = "5"; //软件未注册,请先注册再使用!
|
|
}
|
|
}
|
|
else
|
|
{
|
|
req.errtype = "2"; //密码不正确
|
|
}
|
|
}
|
|
else
|
|
{
|
|
req.errtype = "1"; //用户名不存在
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
req.errtype = ex.Message;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public JObject GetUser(string userId, string dbAias)
|
|
{
|
|
using APPServerContext DBContext = new APPServerContext(dbAias, userId);
|
|
var parameter = DBContext.CreateParameter("@UserId", userId);
|
|
string sql = $" SELECT T01.*,T03.FROLETYPE FROM SYS_LOGINUSER T01 LEFT JOIN SYS_USERROLERELATION T02 ON T01.USER_ID = T02.USER_ID LEFT JOIN SYS_USERROLE T03 ON T03.FROLENUMBER = T02.FROLEID WHERE T01.USER_ID = {parameter.ParameterName} ";
|
|
DataTable userMessage = DBContext.Database.SqlQuery(sql, parameter);
|
|
string fRoleType = "1";
|
|
JObject returnJObject = new JObject();
|
|
foreach (DataRow userRow in userMessage.Rows)
|
|
{
|
|
if (returnJObject.Property("USER_ID") == null)
|
|
{
|
|
returnJObject.Add("USER_ID", userRow["USER_ID"].ToStringEx());
|
|
returnJObject.Add("USER_NAME", userRow["USER_NAME"].ToStringEx());
|
|
returnJObject.Add("PR_PASSWORD", userRow["PR_PASSWORD"].ToStringEx());
|
|
returnJObject.Add("FDELETED", userRow["FDELETED"].ToStringEx());
|
|
returnJObject.Add("DBAias", dbAias);
|
|
}
|
|
if (userRow["FROLETYPE"].ToStringEx().Equals("0"))
|
|
{
|
|
fRoleType = "0";
|
|
}
|
|
}
|
|
returnJObject.Add("FROLETYPE", fRoleType);
|
|
DBContext.Database.SqlNonQueryAsync(sql, parameter);
|
|
return returnJObject;
|
|
}
|
|
|
|
private LicenseInfo GetLicense()
|
|
{
|
|
LicenseInfo myInfo = new LicenseInfo() { SerialNumber = "" };
|
|
try
|
|
{
|
|
//强制执行抓机器码
|
|
string Maction = "";//SecurityManage.GetLocalCustomerKey(wProductCode);
|
|
List<LicenseInfo> myList = SecurityManage.GetLocalSystemLicenseInfo(Maction);
|
|
foreach (LicenseInfo subinfo in myList)
|
|
{
|
|
//如果产品及版本有注册,那么就看使用日期是否已经有到
|
|
subinfo.SerialDate = DateTime.Now;
|
|
return subinfo;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw e;
|
|
}
|
|
return myInfo;
|
|
}
|
|
|
|
}
|
|
}
|