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
7593bd4c
Commit
7593bd4c
authored
Jun 06, 2023
by
Jason
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
edit user
parent
a8162890
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
284 additions
and
89 deletions
+284
-89
UserController.cs
... Vault Management/backstage/Controllers/UserController.cs
+236
-50
GetUser.cshtml
...oken Vault Management/backstage/Views/User/GetUser.cshtml
+39
-30
ListUsers.cshtml
...en Vault Management/backstage/Views/User/ListUsers.cshtml
+8
-8
style.css
...nt Token Vault Management/backstage/wwwroot/css/style.css
+1
-1
No files found.
Merchant Token Vault Management/backstage/Controllers/UserController.cs
View file @
7593bd4c
...
...
@@ -16,6 +16,7 @@ using backstage.Helpers;
using
backstage.Models
;
using
backstage.Models.Users
;
using
Newtonsoft.Json.Linq
;
using
System.Linq
;
namespace
backstage.Controllers
{
...
...
@@ -65,7 +66,7 @@ namespace backstage.Controllers
// 確認使用者是否已經登入
if
(!
User
.
Identity
.
IsAuthenticated
)
{
return
RedirectToAction
(
"Login"
,
"User"
);
return
RedirectToAction
(
"Login"
,
"User"
);
}
...
...
@@ -129,7 +130,7 @@ namespace backstage.Controllers
{
if
(
v
.
uid
==
1
)
v
.
isAdmin
=
true
;
if
(
a
.
uid
==
v
.
uid
)
if
(
a
.
uid
==
v
.
uid
&&
a
.
enabled
==
1
)
v
.
isAdmin
=
true
;
}
...
...
@@ -152,7 +153,7 @@ namespace backstage.Controllers
// 確認使用者是否已經登入
if
(!
User
.
Identity
.
IsAuthenticated
)
{
return
RedirectToAction
(
"Login"
,
"User"
);
return
RedirectToAction
(
"Login"
,
"User"
);
}
...
...
@@ -169,9 +170,9 @@ namespace backstage.Controllers
{
"uid"
,
uid
.
ToString
()}
};
int
maxRetries
=
types
.
Length
;
// 最大重試次數
int
currentRetry
=
0
;
// 目前重試次數
...
...
@@ -193,13 +194,13 @@ namespace backstage.Controllers
var
user
=
new
User
();
user
.
name
=
GetUserResponse
.
user
.
name
;
user
.
username
=
GetUserResponse
.
user
.
username
;
if
(
GetUserResponse
.
email
!=
null
)
user
.
email
=
GetUserResponse
.
email
;
if
(
GetUserResponse
.
email
!=
null
)
user
.
email
=
GetUserResponse
.
email
;
// 使用 JSON 解析工具將 JSON 字串轉換為物件
//var jsonObject = JsonConvert.DeserializeObject<Dictionary<string, string>>(apiResult.Data.ToString());
//user.created_date = DateTime.Parse(jsonObject["created_date"]);
return
View
(
user
);
}
...
...
@@ -243,7 +244,7 @@ namespace backstage.Controllers
// 確認使用者是否已經登入
if
(!
User
.
Identity
.
IsAuthenticated
)
{
return
RedirectToAction
(
"Login"
,
"User"
);
return
RedirectToAction
(
"Login"
,
"User"
);
}
if
(
string
.
IsNullOrEmpty
(
user
.
password
))
...
...
@@ -288,6 +289,122 @@ namespace backstage.Controllers
}
[
HttpPost
]
public
async
Task
<
IActionResult
>
GetUser
(
User
user
)
{
// 確認使用者是否已經登入
if
(!
User
.
Identity
.
IsAuthenticated
)
{
return
RedirectToAction
(
"Login"
,
"User"
);
}
// 取得使用者的 "token" Claim 值
string
token
=
User
.
FindFirstValue
(
"token"
);
#
region
user
/
list
var
url
=
_config
[
"IP"
]
+
"/user/list"
;
var
httpMethod
=
HttpMethod
.
Post
;
var
types
=
new
[]
{
"all"
};
var
types_data
=
new
{
inc
=
types
};
var
parameters
=
new
Dictionary
<
string
,
string
>
{
{
"token"
,
token
},
{
"types"
,
JsonConvert
.
SerializeObject
(
types_data
)},
{
"email"
,
"1"
},
{
"phone"
,
"1"
}
//{ "types", "{\"inc\":[\"all\"]}"}
};
var
apiResult
=
await
_callApi
.
CallAPI
(
url
,
parameters
,
httpMethod
);
if
(
apiResult
.
IsSuccess
)
{
var
UserResponse
=
JsonConvert
.
DeserializeObject
<
UserResponse
>(
apiResult
.
Data
.
ToString
());
if
(
UserResponse
.
userCount
>
0
)
{
var
existUser
=
UserResponse
.
Users
.
Where
(
u
=>
u
.
uid
==
user
.
uid
).
FirstOrDefault
();
if
(
existUser
==
null
)
{
return
RedirectToAction
(
"ListUsers"
);
}
//檢查name
if
(
string
.
IsNullOrEmpty
(
user
.
name
))
{
ModelState
.
AddModelError
(
"name"
,
"name必填"
);
}
var
existName
=
UserResponse
.
Users
.
Where
(
u
=>
u
.
name
==
user
.
name
).
FirstOrDefault
();
if
(
existName
!=
null
)
{
if
(
existName
.
uid
!=
user
.
uid
)
ModelState
.
AddModelError
(
"name"
,
"name重複"
);
}
//檢查username
if
(
string
.
IsNullOrEmpty
(
user
.
username
))
{
ModelState
.
AddModelError
(
"username"
,
"username必填"
);
}
var
existUserName
=
UserResponse
.
Users
.
Where
(
u
=>
u
.
username
==
user
.
username
).
FirstOrDefault
();
if
(
existUserName
!=
null
)
{
if
(
existUserName
.
uid
!=
user
.
uid
)
ModelState
.
AddModelError
(
"username"
,
"username重複"
);
}
if
(!
ModelState
.
IsValid
)
{
return
View
(
user
);
}
existUser
.
name
=
user
.
name
;
existUser
.
username
=
user
.
username
;
//檢查通過
url
=
_config
[
"IP"
]
+
"/user/mod"
;
parameters
=
new
Dictionary
<
string
,
string
>
{
{
"token"
,
token
},
{
"data"
,
JsonConvert
.
SerializeObject
(
user
)}
//{ "types", "{\"inc\":[\"all\"]}"}
};
apiResult
=
await
_callApi
.
CallAPI
(
url
,
parameters
,
httpMethod
);
if
(
apiResult
.
IsSuccess
)
{
TempData
[
"IsSuccess"
]
=
true
;
TempData
[
"msg"
]
=
"編輯成功"
;
return
RedirectToAction
(
"ListUsers"
);
}
TempData
[
"IsSuccess"
]
=
false
;
TempData
[
"msg"
]
=
"user_id不存在"
;
return
View
(
existUser
);
}
}
//查無使用者
TempData
[
"IsSuccess"
]
=
false
;
TempData
[
"msg"
]
=
"查無使用者"
;
return
RedirectToAction
(
"ListUsers"
);
#
endregion
}
[
HttpGet
]
public
async
Task
<
IActionResult
>
ListDepartments
()
{
...
...
@@ -296,7 +413,7 @@ namespace backstage.Controllers
// 確認使用者是否已經登入
if
(!
User
.
Identity
.
IsAuthenticated
)
{
return
RedirectToAction
(
"Login"
,
"User"
);
return
RedirectToAction
(
"Login"
,
"User"
);
}
...
...
@@ -336,7 +453,7 @@ namespace backstage.Controllers
// 確認使用者是否已經登入
if
(!
User
.
Identity
.
IsAuthenticated
)
{
return
RedirectToAction
(
"Login"
,
"User"
);
return
RedirectToAction
(
"Login"
,
"User"
);
}
...
...
@@ -391,7 +508,7 @@ namespace backstage.Controllers
// 確認使用者是否已經登入
if
(!
User
.
Identity
.
IsAuthenticated
)
{
return
RedirectToAction
(
"Login"
,
"User"
);
return
RedirectToAction
(
"Login"
,
"User"
);
}
if
(
string
.
IsNullOrEmpty
(
department
.
name
))
...
...
@@ -548,8 +665,15 @@ namespace backstage.Controllers
}
/// <summary>
/// enable做兩件事情,user加入admin,並且enable=true,
/// disable做一件事情就是enable=false
/// </summary>
/// <param name="uid"></param>
/// <param name="isAdmin"></param>
/// <returns></returns>
[
HttpPost
]
public
async
Task
<
ResultModel
>
AdminAddAjax
(
int
uid
)
public
async
Task
<
ResultModel
>
AdminAddAjax
(
int
uid
,
bool
isAdmin
)
{
var
result
=
new
ResultModel
();
...
...
@@ -559,60 +683,136 @@ namespace backstage.Controllers
result
.
IsSuccess
=
false
;
result
.
Message
=
"未登入"
;
return
result
;
}
}
// 取得使用者的 "token" Claim 值
string
token
=
User
.
FindFirstValue
(
"token"
);
var
url
=
_config
[
"IP"
]
+
"/admin/add"
;
var
httpMethod
=
HttpMethod
.
Post
;
var
userData
=
new
[]
{
new
{
var
userData
=
new
[]
{
new
{
uid
=
uid
,
desc
=
""
,
roles
=
new
[]
{
1
},
enabled
=
1
}
};
//檢查是否在admin/list
var
existAdmin
=
new
User
();
#
region
admin
/
list
url
=
_config
[
"IP"
]
+
"/admin/list"
;
httpMethod
=
HttpMethod
.
Post
;
var
types
=
new
[]
{
"admin"
};
var
types_data
=
new
{
inc
=
types
};
var
parameters
=
new
Dictionary
<
string
,
string
>
{
{
"token"
,
token
},
{
"user"
,
JsonConvert
.
SerializeObject
(
userData
)}
{
"token"
,
token
},
{
"types"
,
JsonConvert
.
SerializeObject
(
types_data
)},
{
"email"
,
"1"
},
{
"phone"
,
"1"
}
//{ "types", "{\"inc\":[\"all\"]}"}
};
var
apiResult
=
await
_callApi
.
CallAPI
(
url
,
parameters
,
httpMethod
);
var
adminResponse
=
new
UserResponse
();
if
(
apiResult
.
IsSuccess
)
{
var
Response
=
JsonConvert
.
DeserializeObject
<
Response
>(
apiResult
.
Data
.
ToString
());
adminResponse
=
JsonConvert
.
DeserializeObject
<
UserResponse
>(
apiResult
.
Data
.
ToString
());
existAdmin
=
adminResponse
.
Users
.
Where
(
u
=>
u
.
uid
==
uid
).
FirstOrDefault
();
if
(
Response
.
r
==
0
)
}
#
endregion
//加入admin list
if
(
existAdmin
==
null
)
{
if
(
isAdmin
==
true
)
{
result
.
IsSuccess
=
true
;
result
.
Message
=
"權限調整成功"
;
return
result
;
parameters
=
new
Dictionary
<
string
,
string
>
{
{
"token"
,
token
},
{
"user"
,
JsonConvert
.
SerializeObject
(
userData
)}
};
apiResult
=
await
_callApi
.
CallAPI
(
url
,
parameters
,
httpMethod
);
if
(
apiResult
.
IsSuccess
)
{
var
Response
=
JsonConvert
.
DeserializeObject
<
Response
>(
apiResult
.
Data
.
ToString
());
if
(
Response
.
r
==
0
)
{
result
.
IsSuccess
=
true
;
result
.
Message
=
"權限調整成功"
;
return
result
;
}
else
{
result
.
IsSuccess
=
false
;
result
.
Message
=
Response
.
m
.
ToString
();
return
result
;
}
}
else
{
result
.
IsSuccess
=
false
;
result
.
Message
=
apiResult
.
Message
;
return
result
;
}
}
else
{
result
.
IsSuccess
=
false
;
result
.
Message
=
Response
.
m
.
ToString
()
;
result
.
Message
=
"非admin"
;
return
result
;
}
}
else
{
result
.
IsSuccess
=
false
;
result
.
Message
=
apiResult
.
Message
;
return
result
;
url
=
_config
[
"IP"
]
+
"/admin/mod"
;
httpMethod
=
HttpMethod
.
Post
;
existAdmin
.
enabled
=
isAdmin
?
1
:
0
;
parameters
=
new
Dictionary
<
string
,
string
>
{
{
"token"
,
token
},
{
"data"
,
JsonConvert
.
SerializeObject
(
existAdmin
)}
};
apiResult
=
await
_callApi
.
CallAPI
(
url
,
parameters
,
httpMethod
);
if
(
apiResult
.
IsSuccess
)
{
var
Response
=
JsonConvert
.
DeserializeObject
<
Response
>(
apiResult
.
Data
.
ToString
());
if
(
Response
.
r
==
0
)
{
result
.
IsSuccess
=
true
;
result
.
Message
=
"權限調整成功"
;
return
result
;
}
else
{
result
.
IsSuccess
=
false
;
result
.
Message
=
Response
.
m
.
ToString
();
return
result
;
}
}
else
{
result
.
IsSuccess
=
false
;
result
.
Message
=
apiResult
.
Message
;
return
result
;
}
}
}
...
...
@@ -631,19 +831,5 @@ namespace backstage.Controllers
}
public
async
Task
<
IActionResult
>
List
()
{
//TempData["IsSuccess"] = result.IsSuccess;
//TempData["msg"] = result.Message;
//return View(viewModel);
throw
new
NotImplementedException
();
}
public
async
Task
<
ResultModel
>
Delete
(
int
id
)
{
throw
new
NotImplementedException
();
}
}
}
\ No newline at end of file
Merchant Token Vault Management/backstage/Views/User/GetUser.cshtml
View file @
7593bd4c
...
...
@@ -11,7 +11,7 @@
<input id="msg" hidden value="@TempData["msg"]" />
@if (TempData["isSuccess"] != null)
{
<input id="isSuccess" hidden value="@TempData["isSuccess"].ToString()" />
<input id="isSuccess" hidden value="@TempData["isSuccess"].ToString()" />
}
<div id="msgDiv"></div>
</div>
...
...
@@ -21,15 +21,15 @@
<div class="card-body">
<h4 class="card-title">編輯使用者</h4>
<form class="forms-sample" method="post" asp-action="
Create
User" autocomplete="off">
<form class="forms-sample" method="post" asp-action="
Get
User" autocomplete="off">
<div id="errorMsg" asp-validation-summary="All" class="text-danger"></div>
<p class="form-title card-description">基本資料</p>
<div class="row">
<div class="col-md-4 form-group required">
<label asp-for="uid" class="col-form-label" for=""></label>
<input asp-for="uid" type="text" class="form-control"
id=""
disabled>
<input asp-for="uid" type="text" class="form-control" disabled>
</div>
<div class="col-md-4 form-group
required
">
<div class="col-md-4 form-group ">
<label asp-for="created_date" class="col-form-label" for="creation_date"></label>
<input asp-for="created_date" class="form-control" id="creation_date" disabled>
...
...
@@ -37,12 +37,12 @@
</div>
<div class="row">
<div class="col-md-4 form-group
required
">
<div class="col-md-4 form-group ">
<label asp-for="name" class="col-form-label" for=""></label>
<input asp-for="name" type="text" class="form-control" id="">
<span asp-validation-for="name" class="text-danger"></span>
</div>
<div class="col-md-4 form-group
required
">
<div class="col-md-4 form-group ">
<label asp-for="username" class="col-form-label" for="username"></label>
<input asp-for="username" class="form-control" id="username">
<span asp-validation-for="username" class="text-danger"></span>
...
...
@@ -52,34 +52,34 @@
<div class="row">
@if (Model.email!=null)
@if (Model.email.Count > 0)
@if (Model.email.Count > 0)
{
@foreach (var item in Model.email)
@foreach (var item in Model.email)
{
<div class="col-md-2 form-group">
<label asp-for="@item.type" class="col-form-label" for="item.type">type</label>
<input value="@item.type" class="form-control" />
<span asp-validation-for="@item.type" class="text-danger"></span>
</div>
<div class="col-md-6 form-group">
<label asp-for="@item.email" class="col-form-label" for="item.email">email</label>
<input value="@item.email" class="form-control" />
<span asp-validation-for="@item.email" class="text-danger"></span>
</div>
<div class="col-md-2 form-group">
<label asp-for="@item.type" class="col-form-label" for="item.type">type</label>
<input value="@item.type" class="form-control" />
<span asp-validation-for="@item.type" class="text-danger"></span>
</div>
<div class="col-md-6 form-group">
<label asp-for="@item.email" class="col-form-label" for="item.email">email</label>
<input value="@item.email" class="form-control" />
<span asp-validation-for="@item.email" class="text-danger"></span>
</div>
}
}
</div>
<div class="row">
<div class="col-md-4 form-group
required
">
</div>
@*
<div class="row">
<div class="col-md-4 form-group ">
<label asp-for="password" class="col-form-label" for=""></label>
<input asp-for="password" type="text" class="form-control" id="">
<span asp-validation-for="password" class="text-danger"></span>
</div>
</div>
</div>
*@
...
...
@@ -97,14 +97,23 @@
<script nonce="KUY8VewuvyUYVEIvEFue4vwyiuf">
var msg = '@TempData["msg"]';
var IsSuccess = '@TempData["IsSuccess"]';
console.log(IsSuccess + msg);
if (msg != '') {
showAlert(IsSuccess, msg);
}
$(document).ready(function () {
var msg = '@TempData["msg"]';
var IsSuccess = '@TempData["IsSuccess"]';
console.log(IsSuccess + msg);
if (msg != '') {
showAlert(IsSuccess, msg);
}
$(".forms-sample").submit(function (event) {
event.preventDefault();
$('input').removeAttr('disabled');
this.submit();
});
})
</script>
...
...
Merchant Token Vault Management/backstage/Views/User/ListUsers.cshtml
View file @
7593bd4c
...
...
@@ -67,7 +67,7 @@
<td>@i.created_date</td>
<td> <input type="checkbox" class="toggleButton" @(i.enabled==1 ? "checked" : "") disabled></td>
<td> <input type="checkbox"
class="toggleButto
n" @(i.isAdmin ? "checked" : "")></td>
<td> <input type="checkbox"
data-uid="@i.uid" class="toggleButton isAdmi
n" @(i.isAdmin ? "checked" : "")></td>
@*@if (i.isAdmin)
{ <td>是</td>}
else { <td></td>}*@
...
...
@@ -107,30 +107,30 @@
showAlert(IsSuccess, msg);
}
$('
table tbody tr
').each(function () {
$('
.userRow
').each(function () {
var uid = $(this).find('td:first-child').text(); // 獲取行中的 UID 值
console.log('uid=' + uid)
if (uid === '1') {
$(this).find('.
toggleButto
n').prop('disabled', true); // 將切換按鈕設為禁用
$(this).find('.
isAdmi
n').prop('disabled', true); // 將切換按鈕設為禁用
return false; // 停止迴圈
}
});
$('.
toggleButto
n').bootstrapSwitch({
$('.
isAdmi
n').bootstrapSwitch({
onText: 'ON',
offText: 'OFF',
onColor: 'success',
offColor: 'danger',
size: 'small',
onSwitchChange: function (event, state) {
var u
serId = $(this).data('userI
d');
var isAdmin = $(this).
data('admin
');
var u
id = $(this).data('ui
d');
var isAdmin = $(this).
is(':checked
');
// 使用 AJAX 發送請求,處理狀態變更事件
$.ajax({
url: '/
YourController/Toggle
',
url: '/
User/AdminAddAjax
',
type: 'POST',
data: { u
serId: userId, isAdmin: isAdmin, state: state
},
data: { u
id: uid, isAdmin: isAdmin
},
success: function (response) {
// 在成功回調中處理回應
console.log(response);
...
...
Merchant Token Vault Management/backstage/wwwroot/css/style.css
View file @
7593bd4c
...
...
@@ -19270,6 +19270,6 @@ tbody {
height
:
26px
!important
;
}
.departmentRow
{
.departmentRow
,
.userRow
{
cursor
:
pointer
;
}
\ No newline at end of file
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