10
10
11
11
namespace APIJSON . NET . Services
12
12
{
13
+ /// <summary>
14
+ ///
15
+ /// </summary>
13
16
public class IdentityService : IIdentityService
14
17
{
15
18
private IHttpContextAccessor _context ;
16
19
private List < Role > roles ;
17
20
21
+ /// <summary>
22
+ ///
23
+ /// </summary>
24
+ /// <param name="context"></param>
25
+ /// <param name="_roles"></param>
18
26
public IdentityService ( IHttpContextAccessor context , IOptions < List < Role > > _roles )
19
27
{
20
28
_context = context ?? throw new ArgumentNullException ( nameof ( context ) ) ;
21
29
roles = _roles . Value ;
22
30
}
31
+
32
+ /// <summary>
33
+ ///
34
+ /// </summary>
35
+ /// <returns></returns>
23
36
public string GetUserIdentity ( )
24
37
{
25
38
return _context . HttpContext . User . FindFirstValue ( ClaimTypes . NameIdentifier ) ;
26
39
}
27
40
41
+ /// <summary>
42
+ ///
43
+ /// </summary>
44
+ /// <returns></returns>
28
45
public string GetUserRoleName ( )
29
46
{
30
47
return _context . HttpContext . User . FindFirstValue ( ClaimTypes . Role ) ;
31
48
}
49
+
50
+ /// <summary>
51
+ ///
52
+ /// </summary>
53
+ /// <returns></returns>
32
54
public Role GetRole ( )
33
55
{
34
56
var role = new Role ( ) ;
@@ -43,23 +65,37 @@ public Role GetRole()
43
65
}
44
66
return role ;
45
67
}
46
- public ( bool , string ) GetSelectRole ( string table )
68
+
69
+ /// <summary>
70
+ ///
71
+ /// </summary>
72
+ /// <param name="table"></param>
73
+ /// <returns></returns>
74
+ public Tuple < bool , string > GetSelectRole ( string table )
47
75
{
48
76
var role = GetRole ( ) ;
49
77
if ( role == null || role . Select == null || role . Select . Table == null )
50
78
{
51
- return ( false , $ "appsettings.json权限配置不正确!") ;
79
+ return Tuple . Create ( false , $ "appsettings.json权限配置不正确!") ;
52
80
}
53
81
string tablerole = role . Select . Table . FirstOrDefault ( it => it == "*" || it . Equals ( table , StringComparison . CurrentCultureIgnoreCase ) ) ;
54
82
55
83
if ( string . IsNullOrEmpty ( tablerole ) )
56
84
{
57
- return ( false , $ "表名{ table } 没权限查询!") ;
85
+ return Tuple . Create ( false , $ "表名{ table } 没权限查询!") ;
58
86
}
59
87
int index = Array . IndexOf ( role . Select . Table , tablerole ) ;
60
88
string selectrole = role . Select . Column [ index ] ;
61
- return ( true , selectrole ) ;
89
+ return Tuple . Create ( true , selectrole ) ;
62
90
}
91
+
92
+
93
+ /// <summary>
94
+ ///
95
+ /// </summary>
96
+ /// <param name="col"></param>
97
+ /// <param name="selectrole"></param>
98
+ /// <returns></returns>
63
99
public bool ColIsRole ( string col , string [ ] selectrole )
64
100
{
65
101
if ( selectrole . Contains ( "*" ) )
0 commit comments