Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
T
TokenVaultManagement
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jasonwai
TokenVaultManagement
Commits
bb835eee
Commit
bb835eee
authored
Jun 19, 2023
by
Jason
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.新增key
2.token vault權限 List, add user, edit user permission
parent
48556b95
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
694 additions
and
214 deletions
+694
-214
TokenVaultController .cs
...Management/backstage/Controllers/TokenVaultController .cs
+306
-39
Response.cs
Merchant Token Vault Management/backstage/Models/Response.cs
+2
-1
TokenVault.cs
...ault Management/backstage/Models/TokenVault/TokenVault.cs
+16
-0
Permission.zh.resx
...t/backstage/Resources/Views/TokenVault/Permission.zh.resx
+186
-0
List.cshtml
...n Vault Management/backstage/Views/TokenVault/List.cshtml
+1
-1
ListFields.cshtml
...t Management/backstage/Views/TokenVault/ListFields.cshtml
+1
-0
Permission.cshtml
...t Management/backstage/Views/TokenVault/Permission.cshtml
+182
-173
No files found.
Merchant Token Vault Management/backstage/Controllers/TokenVaultController .cs
View file @
bb835eee
...
...
@@ -60,7 +60,7 @@ namespace backstage.Controllers
var
TokenVaultResponse
=
new
TokenVaultResponse
();
string
msg
=
string
.
Empty
;
ViewBag
.
Merchant_id
=
merchantId
;
logger
.
Info
(
"merchantId="
+
merchantId
);
logger
.
Info
(
"merchantId="
+
merchantId
);
#
region
取得部門列表
var
DepartmentsResponse
=
new
DepartmentsResponse
();
...
...
@@ -103,51 +103,313 @@ namespace backstage.Controllers
[
Authorize
(
Policy
=
"AdminOnly"
)]
[
HttpGet
]
public
async
Task
<
IActionResult
>
Permission
(
int
merchant
I
d
)
public
async
Task
<
IActionResult
>
Permission
(
int
merchant
_id
,
int
vault_i
d
)
{
// var TokenVaultResponse = new TokenVaultResponse();
// string msg = string.Empty;
// ViewBag.Merchant_id = merchantId;
// logger.Info("merchantId=" + merchantId);
// #region 取得部門列表
// var DepartmentsResponse = new DepartmentsResponse();
// var url = _config["IP"] + "/merchant/list";
// var httpMethod = HttpMethod.Post;
// // 取得使用者的 "token" Claim 值
// string token = User.FindFirstValue("token");
// var parameters = new Dictionary<string, string>
// {
// { "token", token }
// };
// var apiResult = await _callApi.CallAPI(url, parameters, httpMethod);
// if (apiResult.IsSuccess)
// {
// DepartmentsResponse = JsonConvert.DeserializeObject<DepartmentsResponse>(apiResult.Data.ToString());
// if (DepartmentsResponse.r == 0)
// {
// ViewBag.DepartmentsList = (from o in DepartmentsResponse.merchants
// select new SelectListItem
// {
// Value = o.merchant_id.ToString(),
// Text = o.merchant_id + "_" + o.name
// }).ToList();
// }
// }
// #endregion
string
msg
=
string
.
Empty
;
ViewBag
.
Merchant_id
=
merchant_id
;
ViewBag
.
vault_id
=
vault_id
;
#
region
取得使用者權限列表
var
url
=
_config
[
"IP"
]
+
"/merchant/vault/access/get"
;
var
httpMethod
=
HttpMethod
.
Post
;
// 取得使用者的 "token" Claim 值
string
token
=
User
.
FindFirstValue
(
"token"
);
var
parameters
=
new
Dictionary
<
string
,
string
>
{
{
"token"
,
token
},
{
"vault_id"
,
vault_id
.
ToString
()
},
{
"merchant_id"
,
merchant_id
.
ToString
()
}
};
var
apiResult
=
await
_callApi
.
CallAPI
(
url
,
parameters
,
httpMethod
);
var
permissionList
=
new
List
<
Permission
>();
if
(
apiResult
.
IsSuccess
)
{
var
Response
=
JsonConvert
.
DeserializeObject
<
Response
>(
apiResult
.
Data
.
ToString
());
if
(
Response
.
r
==
0
)
{
try
{
permissionList
=
JsonConvert
.
DeserializeObject
<
List
<
Permission
>>(
Response
.
data
.
ToString
());
ViewBag
.
permissionList
=
permissionList
;
}
catch
(
Exception
e
)
{
TempData
[
"IsSuccess"
]
=
false
;
TempData
[
"msg"
]
=
e
.
Message
+
e
.
InnerException
?.
Message
;
return
RedirectToAction
(
"List"
);
}
}
else
{
TempData
[
"IsSuccess"
]
=
false
;
TempData
[
"msg"
]
=
Response
;
return
RedirectToAction
(
"List"
);
}
}
else
{
TempData
[
"IsSuccess"
]
=
false
;
TempData
[
"msg"
]
=
apiResult
.
Message
;
return
RedirectToAction
(
"List"
);
}
#
endregion
#
region
取得
vault
info
httpMethod
=
HttpMethod
.
Post
;
url
=
_config
[
"IP"
]
+
"/v2/vault/get"
;
parameters
=
new
Dictionary
<
string
,
string
>
{
{
"Merchant_id"
,
merchant_id
.
ToString
()},
{
"id"
,
vault_id
.
ToString
()},
{
"info"
,
"INFO"
}
};
apiResult
=
await
_callApi
.
CallAPI
(
url
,
parameters
,
httpMethod
);
if
(
apiResult
.
IsSuccess
)
{
var
TokenVaultResponse
=
JsonConvert
.
DeserializeObject
<
TokenVaultResponse
>(
apiResult
.
Data
.
ToString
());
if
(
TokenVaultResponse
.
r
==
0
)
{
if
(
TokenVaultResponse
.
info
.
Count
>
0
)
{
ViewBag
.
VaultInfo
=
TokenVaultResponse
.
info
[
0
];
}
else
{
RedirectToAction
(
"List"
);
}
}
}
#
endregion
#
region
處理使用者選單
#
region
user
/
list
var
UserResponse
=
new
UserResponse
();
url
=
_config
[
"IP"
]
+
"/user/list"
;
httpMethod
=
HttpMethod
.
Post
;
var
types
=
new
[]
{
"all"
};
var
types_data
=
new
{
inc
=
types
};
parameters
=
new
Dictionary
<
string
,
string
>
{
{
"token"
,
token
},
{
"types"
,
JsonConvert
.
SerializeObject
(
types_data
)},
{
"email"
,
"1"
},
{
"phone"
,
"1"
}
//{ "types", "{\"inc\":[\"all\"]}"}
};
apiResult
=
await
_callApi
.
CallAPI
(
url
,
parameters
,
httpMethod
);
if
(
apiResult
.
IsSuccess
)
{
UserResponse
=
JsonConvert
.
DeserializeObject
<
UserResponse
>(
apiResult
.
Data
.
ToString
());
}
#
endregion
var
newUser
=
new
List
<
User
>();
if
(
UserResponse
.
r
==
0
)
{
if
(
UserResponse
.
userCount
>
0
)
{
foreach
(
var
a
in
UserResponse
.
Users
)
{
if
(
a
.
enabled
==
1
)
{
var
existUser
=
permissionList
.
Where
(
u
=>
u
.
user_id
==
a
.
uid
).
FirstOrDefault
();
if
(
existUser
==
null
)
{
newUser
.
Add
(
a
);
}
}
}
ViewBag
.
newUser
=
(
from
o
in
newUser
select
new
SelectListItem
{
Value
=
o
.
uid
.
ToString
(),
Text
=
o
.
uid
+
"_"
+
o
.
username
}).
ToList
();
}
}
#
endregion
return
View
();
}
/// <summary>
/// ajax權限增加使用者
/// </summary>
/// <param name="merchant_id"></param>
/// <param name="vault_id"></param>
/// <param name="mask_id"></param>
/// <returns></returns>
[
Authorize
(
Policy
=
"AdminOnly"
)]
[
HttpPost
]
public
async
Task
<
ResultModel
>
AddUserPermission
(
int
merchant_id
,
int
vault_id
,
int
user_id
,
int
access_code
)
{
var
result
=
new
ResultModel
();
// 取得使用者的 "token" Claim 值
string
token
=
User
.
FindFirstValue
(
"token"
);
string
msg
;
var
url
=
_config
[
"IP"
]
+
"/merchant/vault/access"
;
var
httpMethod
=
HttpMethod
.
Post
;
var
parameters
=
new
Dictionary
<
string
,
string
>
{
{
"vault_id"
,
vault_id
.
ToString
()},
{
"merchant_id"
,
merchant_id
.
ToString
()},
{
"token"
,
token
},
{
"user_id"
,
user_id
.
ToString
()},
{
"access_code"
,
access_code
.
ToString
()}
};
var
apiResult
=
await
_callApi
.
CallAPI
(
url
,
parameters
,
httpMethod
);
if
(
apiResult
.
IsSuccess
)
{
try
{
var
Response
=
JsonConvert
.
DeserializeObject
<
Response
>(
apiResult
.
Data
.
ToString
());
if
(
Response
.
r
==
0
)
{
switch
(
_currentLanguage
)
{
case
"en"
:
msg
=
"Create user permission success."
;
break
;
case
"zh"
:
msg
=
"新增使用者權限成功"
;
break
;
default
:
msg
=
"新增使用者權限成功"
;
break
;
}
result
.
IsSuccess
=
true
;
result
.
Message
=
msg
;
return
result
;
}
else
{
result
.
IsSuccess
=
false
;
result
.
Message
=
System
.
Text
.
RegularExpressions
.
Regex
.
Unescape
(
string
.
Join
(
", "
,
Response
.
failInfo
));
return
result
;
}
}
catch
(
Exception
e
)
{
result
.
IsSuccess
=
false
;
result
.
Message
=
e
.
Message
+
e
.
InnerException
?.
Message
;
return
result
;
}
}
result
.
IsSuccess
=
false
;
result
.
Message
=
apiResult
.
Message
;
return
result
;
}
/// <summary>
/// ajax 編輯 權限使用者
/// </summary>
/// <param name="merchant_id"></param>
/// <param name="vault_id"></param>
/// <param name="mask_id"></param>
/// <returns></returns>
[
Authorize
(
Policy
=
"AdminOnly"
)]
[
HttpPost
]
public
async
Task
<
ResultModel
>
ModUserPermission
(
int
merchant_id
,
int
vault_id
,
int
access_id
,
int
access_code
,
int
enabled
)
{
var
result
=
new
ResultModel
();
// 取得使用者的 "token" Claim 值
string
token
=
User
.
FindFirstValue
(
"token"
);
string
msg
;
var
url
=
_config
[
"IP"
]
+
"/merchant/vault/access"
;
var
httpMethod
=
HttpMethod
.
Put
;
var
parameters
=
new
Dictionary
<
string
,
string
>
{
{
"vault_id"
,
vault_id
.
ToString
()},
{
"merchant_id"
,
merchant_id
.
ToString
()},
{
"token"
,
token
},
{
"id"
,
access_id
.
ToString
()},
{
"access_code"
,
access_code
.
ToString
()},
{
"enabled"
,
enabled
.
ToString
()}
};
var
apiResult
=
await
_callApi
.
CallAPI
(
url
,
parameters
,
httpMethod
);
if
(
apiResult
.
IsSuccess
)
{
try
{
var
Response
=
JsonConvert
.
DeserializeObject
<
Response
>(
apiResult
.
Data
.
ToString
());
if
(
Response
.
r
==
0
)
{
switch
(
_currentLanguage
)
{
case
"en"
:
msg
=
"Edit user permission success."
;
break
;
case
"zh"
:
msg
=
"編輯使用者權限成功"
;
break
;
default
:
msg
=
"編輯使用者權限成功"
;
break
;
}
result
.
IsSuccess
=
true
;
result
.
Message
=
msg
;
return
result
;
}
else
{
result
.
IsSuccess
=
false
;
result
.
Message
=
System
.
Text
.
RegularExpressions
.
Regex
.
Unescape
(
string
.
Join
(
", "
,
Response
.
failInfo
));
return
result
;
}
}
catch
(
Exception
e
)
{
result
.
IsSuccess
=
false
;
result
.
Message
=
e
.
Message
+
e
.
InnerException
?.
Message
;
return
result
;
}
}
result
.
IsSuccess
=
false
;
result
.
Message
=
apiResult
.
Message
;
return
result
;
}
[
Authorize
(
Policy
=
"AdminOnly"
)]
[
HttpGet
]
public
async
Task
<
IActionResult
>
ListFields
([
FromQuery
]
int
Merchant_id
,
int
vault_id
)
...
...
@@ -165,6 +427,7 @@ namespace backstage.Controllers
// 取得使用者的 "token" Claim 值
string
token
=
User
.
FindFirstValue
(
"token"
);
#
region
取得
vault
info
var
httpMethod
=
HttpMethod
.
Post
;
var
url
=
_config
[
"IP"
]
+
"/v2/vault/get"
;
var
parameters
=
new
Dictionary
<
string
,
string
>
...
...
@@ -192,6 +455,7 @@ namespace backstage.Controllers
}
}
#
endregion
url
=
_config
[
"IP"
]
+
"/v2/vault/get"
;
...
...
@@ -887,6 +1151,8 @@ namespace backstage.Controllers
}
[
HttpGet
]
public
async
Task
<
IActionResult
>
ListMasks
(
int
Merchant_id
,
int
vault_id
,
int
field_id
)
{
...
...
@@ -1230,7 +1496,8 @@ namespace backstage.Controllers
}
else
{
else
{
result
.
IsSuccess
=
false
;
result
.
Message
=
apiResult
.
Message
;
return
result
;
...
...
@@ -1246,7 +1513,7 @@ namespace backstage.Controllers
}
//return View();
}
...
...
Merchant Token Vault Management/backstage/Models/Response.cs
View file @
bb835eee
...
...
@@ -10,9 +10,10 @@ namespace TokenVault_management.Models
//user/list response
public
int
r
{
get
;
set
;
}
public
Object
m
{
get
;
set
;
}
public
Object
data
{
get
;
set
;
}
public
string
flags
{
get
;
set
;
}
public
List
<
string
>
failInfo
{
get
;
set
;
}
}
}
Merchant Token Vault Management/backstage/Models/TokenVault/TokenVault.cs
View file @
bb835eee
...
...
@@ -96,6 +96,22 @@ namespace backstage.Models.TokenVault
}
public
class
Permission
{
public
int
id
{
get
;
set
;
}
public
int
merchant_id
{
get
;
set
;
}
public
int
user_id
{
get
;
set
;
}
public
string
username
{
get
;
set
;
}
public
int
vault_idvault_id
{
get
;
set
;
}
public
int
access_code
{
get
;
set
;
}
public
int
enable
{
get
;
set
;
}
public
string
created
{
get
;
set
;
}
public
string
modified
{
get
;
set
;
}
}
...
...
Merchant Token Vault Management/backstage/Resources/Views/TokenVault/Permission.zh.resx
0 → 100644
View file @
bb835eee
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema
id=
"root"
xmlns=
""
xmlns:xsd=
"http://www.w3.org/2001/XMLSchema"
xmlns:msdata=
"urn:schemas-microsoft-com:xml-msdata"
>
<xsd:import
namespace=
"http://www.w3.org/XML/1998/namespace"
/>
<xsd:element
name=
"root"
msdata:IsDataSet=
"true"
>
<xsd:complexType>
<xsd:choice
maxOccurs=
"unbounded"
>
<xsd:element
name=
"metadata"
>
<xsd:complexType>
<xsd:sequence>
<xsd:element
name=
"value"
type=
"xsd:string"
minOccurs=
"0"
/>
</xsd:sequence>
<xsd:attribute
name=
"name"
use=
"required"
type=
"xsd:string"
/>
<xsd:attribute
name=
"type"
type=
"xsd:string"
/>
<xsd:attribute
name=
"mimetype"
type=
"xsd:string"
/>
<xsd:attribute
ref=
"xml:space"
/>
</xsd:complexType>
</xsd:element>
<xsd:element
name=
"assembly"
>
<xsd:complexType>
<xsd:attribute
name=
"alias"
type=
"xsd:string"
/>
<xsd:attribute
name=
"name"
type=
"xsd:string"
/>
</xsd:complexType>
</xsd:element>
<xsd:element
name=
"data"
>
<xsd:complexType>
<xsd:sequence>
<xsd:element
name=
"value"
type=
"xsd:string"
minOccurs=
"0"
msdata:Ordinal=
"1"
/>
<xsd:element
name=
"comment"
type=
"xsd:string"
minOccurs=
"0"
msdata:Ordinal=
"2"
/>
</xsd:sequence>
<xsd:attribute
name=
"name"
type=
"xsd:string"
use=
"required"
msdata:Ordinal=
"1"
/>
<xsd:attribute
name=
"type"
type=
"xsd:string"
msdata:Ordinal=
"3"
/>
<xsd:attribute
name=
"mimetype"
type=
"xsd:string"
msdata:Ordinal=
"4"
/>
<xsd:attribute
ref=
"xml:space"
/>
</xsd:complexType>
</xsd:element>
<xsd:element
name=
"resheader"
>
<xsd:complexType>
<xsd:sequence>
<xsd:element
name=
"value"
type=
"xsd:string"
minOccurs=
"0"
msdata:Ordinal=
"1"
/>
</xsd:sequence>
<xsd:attribute
name=
"name"
type=
"xsd:string"
use=
"required"
/>
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader
name=
"resmimetype"
>
<value>
text/microsoft-resx
</value>
</resheader>
<resheader
name=
"version"
>
<value>
2.0
</value>
</resheader>
<resheader
name=
"reader"
>
<value>
System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader
name=
"writer"
>
<value>
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data
name=
"AddToken Vault"
xml:space=
"preserve"
>
<value>
新增代碼庫
</value>
</data>
<data
name=
"Choose department"
xml:space=
"preserve"
>
<value>
選擇部門
</value>
</data>
<data
name=
"Create date"
xml:space=
"preserve"
>
<value>
建立日
</value>
</data>
<data
name=
"Creation Date"
xml:space=
"preserve"
>
<value>
建立日期
</value>
</data>
<data
name=
"Data Token Vault"
xml:space=
"preserve"
>
<value>
資料代碼保險庫
</value>
</data>
<data
name=
"Description"
xml:space=
"preserve"
>
<value>
描述
</value>
</data>
<data
name=
"Edit date"
xml:space=
"preserve"
>
<value>
修改日
</value>
</data>
<data
name=
"Enable"
xml:space=
"preserve"
>
<value>
啟動
</value>
</data>
<data
name=
"Manage"
xml:space=
"preserve"
>
<value>
管理
</value>
</data>
<data
name=
"Name"
xml:space=
"preserve"
>
<value>
名稱
</value>
</data>
<data
name=
"Number of codes"
xml:space=
"preserve"
>
<value>
代碼數量
</value>
</data>
<data
name=
"Number of users"
xml:space=
"preserve"
>
<value>
使用者數量
</value>
</data>
<data
name=
"Operate"
xml:space=
"preserve"
>
<value>
操作
</value>
</data>
<data
name=
"Permission"
xml:space=
"preserve"
>
<value>
權限
</value>
</data>
<data
name=
"Please select permission"
xml:space=
"preserve"
>
<value>
請選擇權限(複選)
</value>
</data>
<data
name=
"Save"
xml:space=
"preserve"
>
<value>
儲存
</value>
</data>
<data
name=
"Serial number"
xml:space=
"preserve"
>
<value>
編號
</value>
</data>
<data
name=
"Status"
xml:space=
"preserve"
>
<value>
狀態
</value>
</data>
<data
name=
"Token Vault"
xml:space=
"preserve"
>
<value>
代碼庫
</value>
</data>
<data
name=
"Token Vault List"
xml:space=
"preserve"
>
<value>
代碼化保險庫列管理
</value>
</data>
<data
name=
"Tpye"
xml:space=
"preserve"
>
<value>
種類
</value>
</data>
<data
name=
"User"
xml:space=
"preserve"
>
<value>
使用者
</value>
</data>
</root>
\ No newline at end of file
Merchant Token Vault Management/backstage/Views/TokenVault/List.cshtml
View file @
bb835eee
...
...
@@ -196,7 +196,7 @@
var vaultid = $(this).data('vault_id');
var merchantid = $(this).data('merchant_id');
console.log('vaultid=' + vaultid);
window.location.href = '/tokenvault/Permission/' + "?vault_id=" + vaultid + "&
M
erchant_id=" + merchantid;
window.location.href = '/tokenvault/Permission/' + "?vault_id=" + vaultid + "&
m
erchant_id=" + merchantid;
});
...
...
Merchant Token Vault Management/backstage/Views/TokenVault/ListFields.cshtml
View file @
bb835eee
...
...
@@ -93,6 +93,7 @@
<a type="button" class="btn btn-info float-right mb-2 @disabledClass" data-toggle="modal" data-target="#myModal">@Localizer["Create"]</a>
</div>
</div>
<div>
<div class="rank-table">
<div class="table-responsive">
...
...
Merchant Token Vault Management/backstage/Views/TokenVault/Permission.cshtml
View file @
bb835eee
@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer
@model
backstage.Models.TokenVault.FieldsResponse
@model
List<backstage.Models.TokenVault.Permission>
@{
ViewData["Title"] = @Localizer["
Field List
Management"];
ViewData["Title"] = @Localizer["
Permission
Management"];
}
@{
bool isAdmin = User.IsInRole("Admin");
string disabledClass = isAdmin ? "" : "disabled";
}
@section header{
<style>
.bootstrap-select {
width: 100% !important;
}
</style>
}}
<div class="page-header">
<h3 class="page-title">@Localizer["Permission Management"]</h3>
...
...
@@ -40,36 +46,57 @@
</ul>
</div>
</div>
<div>
<div class="newBlock newPerm">
<button type="button" class="btn btn-mainblue-solid" data-toggle="collapse" data-target="#newPermission"><img src="~/images/memberGo/permission/userRights-4-white-100.png">新增使用者及權限</button>
</div> <!--end fo newBlock-->
<div style="display: flex; justify-content: space-between;">
<div style="float: left; width: 50%;">
<div class="table-responsive">
<table class="table table-striped table-hover0 table-bordered0" id="memberGoTbl_dataDetail">
<tbody>
<tr>
<th>@Localizer["Token Vault"]</th>
<td class="item">@Localizer["Serial number"]</td>
<td class="content">@ViewBag.VaultInfo.vault_id</td>
<td class="item">@Localizer["Name"]</td>
<td class="content">@ViewBag.VaultInfo.name</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="newBlock newPerm" style="float: right;">
<button type="button" class="btn btn-mainblue-solid" data-toggle="collapse" data-target="#newPermission"><img src="~/images/memberGo/permission/userRights-4-white-100.png">新增使用者及權限</button>
</div> <!--end fo newBlock-->
</div>
<div id="newPermission" class="collapse">
<div class="row">
<div class="col-md-5">
<div class="form-group">
<select title="請選擇使用者" class="selectpicker selecter form-control selectpicker-tokenization">
<option>test A</option>
<option>test B</option>
<option>test C</option>z
<option>test D</option>
<select id="newUserSelect" title="@Localizer["Token Vault List"]請選擇使用者" class="selectpicker selecter form-control selectpicker-tokenization">
@foreach (var user in ViewBag.newUser)
{
<option value="@user.Value">@user.Text</option>
}
</select>
</div>
</div>
<div class="col-md-5">
<div class="form-group">
<select
multiple title="
請選擇權限(複選)" class="selectpicker selecter form-control selectpicker-tokenization">
<option>Read</option>
<option>Write</option>
<option>Update</option>
<option>Delete</option>
<option>Enable & Disable</option>
<select
id="access_code_select" multiple title="@Localizer["Token Vault List"]
請選擇權限(複選)" class="selectpicker selecter form-control selectpicker-tokenization">
<option
value="1"
>Read</option>
<option
value="2"
>Write</option>
<option
value="4"
>Update</option>
<option
value="8"
>Delete</option>
<option
value="16"
>Enable & Disable</option>
</select>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<button class="btn btn-primary newPermConfirmBtn">新增</button>
<button class="btn btn-primary newPermConfirmBtn">
@Localizer["Token Vault List"]
新增</button>
</div>
</div>
</div>
...
...
@@ -80,139 +107,52 @@
<table class="table table-striped table-hover" id="memberGoTbl_permission">
<tbody>
<tr>
<th style=" border-left: solid 1px #d9d9d9;">編號</th>
<th>使用者</th>
<th>權限</th>
<th>啟動</th>
<th>建立日</th>
<th>修改日</th>
<th style=" border-right: solid 1px #d9d9d9;">操作</th>
</tr>
<tr>
<td>01</td>
<td>test1</td>
<td>
<div>
<select multiple title="請選擇權限(複選)" class="selectpicker selecter selectpicker-tokenization">
<option>Read</option>
<option>Write</option>
<option>Update</option>
<option>Delete</option>
<option>Enable & Disable</option>
</select>
</div>
</td>
<td>
<input type="checkbox" checked>
</td>
<td>2018-11-09 15:14:43</td>
<td>2018-11-09 15:14:43</td>
<td>
<button class="btn btn-primary btn-sm" title="儲存">儲存</button>
</td>
</tr>
<tr>
<td>02</td>
<td>test2</td>
<td>
<div>
<select multiple title="請選擇權限(複選)" class="selectpicker selectpicker-tokenization">
<option>Read</option>
<option>Write</option>
<option>Update</option>
<option>Delete</option>
<option>Enable & Disable</option>
</select>
</div>
</td>
<td>
<input type="checkbox" checked>
</td>
<td>2018-11-09 15:14:43</td>
<td>2018-11-09 15:14:43</td>
<td>
<button class="btn btn-primary btn-sm" title="儲存">儲存</button>
</td>
</tr>
<tr>
<td>03</td>
<td>test3</td>
<td>
<div>
<select multiple title="請選擇權限(複選)" class="selectpicker selectpicker-tokenization">
<option>Read</option>
<option>Write</option>
<option>Update</option>
<option>Delete</option>
<option>Enable & Disable</option>
</select>
</div>
</td>
<td>
<input type="checkbox" checked>
</td>
<td>2018-11-09 15:14:43</td>
<td>2018-11-09 15:14:43</td>
<td>
<button class="btn btn-primary btn-sm" title="儲存">儲存</button>
</td>
</tr>
<tr>
<td>04</td>
<td>test4</td>
<td>
<div>
<select title="請選擇權限(複選)" class="selectpicker selectpicker-tokenization" multiple>
<option>Read</option>
<option>Write</option>
<option>Update</option>
<option>Delete</option>
<option>Enable & Disable</option>
</select>
</div>
</td>
<td>
<input type="checkbox" checked>
</td>
<td>2018-11-09 15:14:43</td>
<td>2018-11-09 15:14:43</td>
<td>
<button class="btn btn-primary btn-sm" title="儲存">儲存</button>
</td>
</tr>
<tr>
<td>05</td>
<td>test5</td>
<td>
<div>
<select title="請選擇權限(複選)" class="selectpicker selectpicker-tokenization" multiple>
<option>Read</option>
<option>Write</option>
<option>Update</option>
<option>Delete</option>
<option>Enable & Disable</option>
</select>
</div>
</td>
<td>
<input type="checkbox" checked>
</td>
<td>2018-11-09 15:14:43</td>
<td>2018-11-09 15:14:43</td>
<td>
<button class="btn btn-primary btn-sm" title="儲存">儲存</button>
</td>
<th style=" border-left: solid 1px #d9d9d9;">@Localizer["Token Vault List"]編號</th>
<th>@Localizer["User"]</th>
<th>@Localizer["Permission"]</th>
<th>@Localizer["Enable"]</th>
<th>@Localizer["Create date"]</th>
<th>@Localizer["Edit date"]</th>
<th style=" border-right: solid 1px #d9d9d9;">@Localizer["Operate"]</th>
</tr>
@if (ViewBag.permissionList != null && ViewBag.permissionList.Count > 0)
{
@foreach (var p in ViewBag.permissionList)
{
<tr>
<td>@p.id</td>
<td>@p.user_id _ @p.username</td>
<td>
<div>
<select multiple title="@Localizer["Please select permission"]" class="selectpicker selecter selectpicker-tokenization permissionSelect">
<option value="1">Read</option>
<option value="2">Write</option>
<option value="4">Update</option>
<option value="8">Delete</option>
<option value="16">Enable & Disable</option>
</select>
</div>
</td>
<td>
<input type="checkbox" @(p.enable == 1 ? "checked" : "")>
</td>
<td>@p.created</td>
<td>@p.modified</td>
<td>
<button data-id="@p.id" class="btn btn-primary btn-sm saveBtn" title="@Localizer["Save"]">@Localizer["Save"]</button>
</td>
</tr>
}
}
</tbody>
<!-- <tfoot>
<tr>
<td colspan="7" class="permissionList">
<button type="button" class="btn btn-mainblue-hollow" data-dismiss="modal">關閉</button>
</td>
</tr>
</tfoot> -->
<tr>
<td colspan="7" class="permissionList">
<button type="button" class="btn btn-mainblue-hollow" data-dismiss="modal">關閉</button>
</td>
</tr>
</tfoot> -->
</table>
</div>
...
...
@@ -240,43 +180,112 @@
showAlert(IsSuccess, msg);
}
//載入權限清單
// 每個物件都有一個 id 和一個 access_code
var model = @Html.Raw(Json.Serialize(ViewBag.permissionList));
//user按鈕
$(document).on('click', '.usersBtn', function () {
var merchant_id = parseInt('@ViewBag.Merchant_id');
var vault_id = parseInt('@ViewBag.vault_id');
var field_id = parseInt($(this).closest('tr').attr('id'));
$('#memberGoTbl_permission tr').each(function() {
var tr = $(this);
var id = tr.find('td:first').text();
window.location.href = '/tokenvault/ListUsers/' + "?vault_id=" + vault_id + "&Merchant_id=" + merchant_id+"&field_id="+field_id;
});
var item = model.find(function(x) { return x.id == id; });
if (item) {
var access_code = item.access_code;
var binaryStr = access_code.toString(2).padStart(5, '0');
var selectpicker = tr.find('.permissionSelect');
var valuesToSelect = [];
for (var i = binaryStr.length - 1, j = 1; i >= 0; i--, j *= 2) {
if (binaryStr[i] == '1') {
valuesToSelect.push(j.toString());
}
}
//mask按鈕
$(document).on('click', '.masksBtn', function () {
var merchant_id = parseInt('@ViewBag.Merchant_id');
var vault_id = parseInt('@ViewBag.vault_id');
var field_id = parseInt($(this).closest('tr').attr('id'));
// 清除所有選擇
selectpicker.selectpicker('deselectAll');
window.location.href = '/tokenvault/ListMasks/' + "?vault_id=" + vault_id + "&Merchant_id=" + merchant_id+"&field_id="+field_id;
}
);
// 設置需要的選擇
selectpicker.selectpicker('val', valuesToSelect
);
// 通知 selectpicker 已經選擇選項的變更
tr.find('.selectpicker.selecter.selectpicker-tokenization').change();
}
});
$('#newUserSelect').change(function () {
var selectedValue = $(this).val();
console.log('選擇的值:' + selectedValue);
});
//新增使用者權限按鈕
$(document).on('click', '.newPermConfirmBtn', function () {
var sum = 0;
$('#access_code_select').find('option:selected').each(function () {
sum += parseInt($(this).val());
});
var data = {
merchant_id:'@ViewBag.merchant_id',
vault_id:'@ViewBag.vault_id',
user_id: $('#newUserSelect').val(),
access_code: sum
};
$.ajax({
url: '/TokenVault/AddUserPermission',
type: 'POST',
data: data,
success: function (data) {
showAlert(data.isSuccess, data.message);
if (data.isSuccess) {
setTimeout(function () {
location.reload();
}, 2000);
}
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
showAlert(false, "發生錯誤");
}
});
});
//編輯使用者權限儲存按鈕
$(document).on('click', '.saveBtn', function () {
var sum = 0;
$(this).closest('tr').find('td:eq(2)').find('select option:selected').each(function () {
sum += parseInt($(this).val());
});
var data = {
merchant_id:'@ViewBag.merchant_id',
vault_id:'@ViewBag.vault_id',
access_id:parseInt($(this).closest('tr').find('td:eq(0)').text()),
access_code: sum,
enabled: $(this).closest('tr').find('td:eq(3)').find('input[type=checkbox]').is(':checked') ? 1 : 0
};
$.ajax({
url: '/TokenVault/ModUserPermission',
type: 'POST',
data: data,
success: function (data) {
showAlert(data.isSuccess, data.message);
if (data.isSuccess) {
setTimeout(function () {
location.reload();
}, 2000);
}
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
showAlert(false, "發生錯誤");
}
});
});
////Modal按鈕
//$("#createFieldBtn").on("click", function () {
// // 確認按鈕被點擊時的處理程式碼
// // 在這裡呼叫您的 API
// $('form').submit(function (e) {
// e.preventDefault(); // 防止表單自動提交
// $.post('/TokenVault/CreateField', $('form').serialize()).done(function (data) {
// console.log(data);
// })
// });
//});
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment