LoginParse.cs
2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* 登录解析
* 处理登录逻辑,验证客户段提交的账号密码,保存登录信息
*/
using Hh.Mes.Common;
using Hh.Mes.Common.Redis;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.Service.Repository;
using SqlSugar;
using System;
using System.Linq;
namespace Hh.Mes.Service.SystemAuth
{
public class LoginParse : RepositorySqlSugar<sys_user>
{
public LoginResult Do(PassportLoginRequest model)
{
var result = new LoginResult();
try
{
model.Trim();
//获取应用信息
var appInfo = Context.Queryable<sys_info>().First(t => t.appKey == model.AppKey);
if (appInfo == null) throw new Exception("应用不存在");
if (Encryption.Decrypt(appInfo.appSecret) != "hhweb2.0") throw new Exception("应用密钥不正确!");
//获取用户信息
var userInfo = Context.Queryable<sys_user>().First(t => t.account == model.Account);
if (userInfo == null || userInfo.account != model.Account) throw new Exception("登录失败,请检查用户名和密码!");
if (Encryption.Decrypt(userInfo.password) != model.Password) throw new Exception("登录失败,请检查用户名和密码!");
//获取用户的所有组织
var orgsList = Context.Queryable<sys_relevance, sys_dept>((x, y) => new JoinQueryInfos(
JoinType.Inner, x.secondId == y.id && x.relKey == Define.USERORG && x.firstId == userInfo.id))
.Select((x, y) => y).ToList();
var token = Guid.NewGuid().ToString("N");
var currentSession = new UserAuthSession
{
Id = userInfo.id,
Account = userInfo.account,
Name = userInfo.name,
Sex= userInfo.sex,
Idcard = userInfo.idcard,
Token= token,
Organizations = string.Join(",", orgsList.Select(u => u.Name).ToList()),
CreateTime = DateTime.Now,
};
//创建Session
//_cacheContext.Set(currentSession.Token, currentSession, DateTime.Now.AddDays(10));
var cl = new RedisBase();
cl.SetT(token, currentSession, cl.dayTime);
result.Code = 200;
result.ReturnUrl = appInfo.returnUrl;
result.currentSession = currentSession;
result.Token = token;
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.Message;
}
return result;
}
}
}