-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserService.cs
198 lines (183 loc) · 7.18 KB
/
UserService.cs
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iPow.Infrastructure.Data.DataSys;
using iPow.Infrastructure.Crosscutting.Comm.Service;
namespace iPow.Infrastructure.Crosscutting.Authorize
{
/// <summary>
///
/// </summary>
public partial class UserService : IUserService
{
/// <summary>
///
/// </summary>
iPow.Domain.Repository.IAdminUserRepository adminUserRepository;
/// <summary>
///
/// </summary>
iPow.Domain.Repository.IAdminUserExtensionRepository adminUserExtensionRepository;
/// <summary>
///
/// </summary>
iPow.Domain.Repository.IAdminUserIndividuationRepository adminUserIndividuationRepository;
/// <summary>
///
/// </summary>
iPow.Domain.Repository.IUserActionRepository userActionRepository;
/// <summary>
///
/// </summary>
iPow.Domain.Repository.IUserRoleRepository userRoleRepository;
/// <summary>
///
/// </summary>
iPow.Domain.Repository.IRolePermissionRepository rolePermissionRepository;
/// <summary>
/// Initializes a new instance of the <see cref="UserService"/> class.
/// </summary>
/// <param name="adminUser">The admin user.</param>
/// <param name="adminUserExtension">The admin user extension.</param>
/// <param name="adminUserIndividuation">The admin user individuation.</param>
/// <param name="userAction">The user action.</param>
/// <param name="userRole">The user role.</param>
public UserService(iPow.Domain.Repository.IAdminUserRepository adminUser,
iPow.Domain.Repository.IAdminUserExtensionRepository adminUserExtension,
iPow.Domain.Repository.IAdminUserIndividuationRepository adminUserIndividuation,
iPow.Domain.Repository.IUserActionRepository userAction,
iPow.Domain.Repository.IUserRoleRepository userRole,
iPow.Domain.Repository.IRolePermissionRepository rolePermission)
{
if (adminUser == null)
{
throw new ArgumentNullException("adminuserrepository is null");
}
if (adminUserExtension == null)
{
throw new ArgumentNullException("adminUserExtensionRepository is null");
}
if (adminUserIndividuation == null)
{
throw new ArgumentNullException("adminUserIndividuationRepository is null");
}
if (userAction == null)
{
throw new ArgumentNullException("userActionRepository is null");
}
if (userRole == null)
{
throw new ArgumentNullException("userRoleRepository is null");
}
if (rolePermission == null)
{
throw new ArgumentNullException("rolePermissionRepository is null");
}
adminUserRepository = adminUser;
adminUserExtensionRepository = adminUserExtension;
adminUserIndividuationRepository = adminUserIndividuation;
userActionRepository = userAction;
userRoleRepository = userRole;
rolePermissionRepository = rolePermission;
}
#region exist
/// <summary>
/// Exists the user by name PWD.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="pwd">The PWD.</param>
/// <param name="login">if set to <c>true</c> [login].</param>
/// <returns></returns>
public bool ExistUserByNamePwd(string name, string pwd, bool login)
{
bool b = false;
pwd = iPow.Infrastructure.Crosscutting.Function.StringHelper.Tomd5(pwd);
var user = adminUserRepository.GetList(e => e.username == name)
.Where(e => e.password == pwd)
.Where(d => d.Activity == true)
.FirstOrDefault();
if (user != null)
{
b = true;
var log = new Sys_AdminUserLog();
log.AddTime = System.DateTime.Now;
log.IpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP();
log.PageUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetCurrentUrl();
log.ReferrerUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetReferrerUrl();
log.State = true;
log.TypeId = 1;
log.UserId = 0;
log.UserId = 0;
log.FullMessage = "ExistUserByNamePwd 用户Id号:" + user.id.ToString();
log.ShortMessage = "查找用户名:" + name + " 密码:" + pwd + "成功";
//查找成功
if (login)
{
user.lastloginip = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP();
user.lastlogintime = System.DateTime.Now;
user.logintimes += 1;
//添加日志用户日志
log.ShortMessage = "用户名:" + name + " 密码:" + pwd + "登陆成功";
}
iPow.Infrastructure.Data.LoggerReopsitoryManager.AddLogInfo(log);
}
return b;
}
/// <summary>
/// Exists the user by name PWD no MD5.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="pwd">The PWD.</param>
/// <returns></returns>
public bool ExistUserByNamePwdEncrypted(string name, string pwd)
{
bool b = false;
var user = adminUserRepository.GetList(e => e.username == name)
.Where(e => e.password == pwd)
.Where(d => d.Activity == true)
.FirstOrDefault();
if (user != null)
{
b = true;
}
return b;
}
/// <summary>
/// Exists the name of the user by.
/// </summary>
/// <param name="name">The name.</param>
/// <returns></returns>
public bool ExistUserByName(string name)
{
bool b = false;
int res = adminUserRepository.GetList(e => e.username == name).Count();
if (res > 0)
{
b = true;
}
return b;
}
/// <summary>
/// Exists the name of the user by.
/// </summary>
/// <param name="email"></param>
/// <returns></returns>
public bool ExistUserByEmail(string email)
{
return adminUserRepository.GetList(d => d.Email == email).Any();
}
#endregion
/// <summary>
/// 用于Add user前的 存在与否判断
/// </summary>
/// <param name="userId"></param>
/// <param name="roleId"></param>
/// <returns></returns>
public bool UserHasUser(string username, string email)
{
var res = adminUserRepository.GetList(e => e.username == username && e.Email == email).Any();
return res;
}
}
}