Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
Ecsite
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shoei.kanno
Ecsite
Commits
6719145e
Commit
6719145e
authored
Oct 23, 2020
by
issei.miyajima
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '管理画面_user権限変更非同期' into 'master'
user権限変更非同期 See merge request
!81
parents
a71348ea
8d8e2d91
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
21 deletions
+91
-21
SecurityConfig.java
src/main/java/com/example/SecurityConfig.java
+2
-1
ManagementController.java
src/main/java/com/example/web/ManagementController.java
+13
-13
ManagementRestController.java
src/main/java/com/example/web/ManagementRestController.java
+35
-0
management.js
src/main/resources/static/js/management.js
+33
-4
management.html
src/main/resources/templates/management.html
+8
-3
No files found.
src/main/java/com/example/SecurityConfig.java
View file @
6719145e
...
...
@@ -14,7 +14,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
public
void
configure
(
WebSecurity
web
)
throws
Exception
{
web
.
debug
(
false
).
ignoring
().
antMatchers
(
"/images/**"
,
"/js/**"
,
"/css/**"
,
"/fonts/**"
,
"/limited/inputCart"
,
"/limited/buy"
,
"/limited/editCart"
);
web
.
debug
(
false
).
ignoring
().
antMatchers
(
"/images/**"
,
"/js/**"
,
"/css/**"
,
"/fonts/**"
,
"/limited/inputCart"
,
"/limited/buy"
,
"/limited/editCart"
,
"/limited/admin/management/1/changeRole"
);
}
@Override
...
...
@@ -35,6 +35,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter{
.
invalidateHttpSession
(
true
)
.
deleteCookies
(
"JSESSIONID"
)
//ログアウト時キャッシュを削除する処理
.
logoutSuccessUrl
(
"/limited/login"
);
//ログアウト後に表示するURL
//http.csrf().disable();
}
@Bean
//パスワードのハッシュか
...
...
src/main/java/com/example/web/ManagementController.java
View file @
6719145e
...
...
@@ -204,19 +204,19 @@ public class ManagementController {
return
"redirect:/limited/admin/management"
;
}
//user権限変更
@PostMapping
(
path
=
"{id}"
)
String
changeRoles
(
Integer
id
,
@AuthenticationPrincipal
LoginUser
loginUser
){
User
user
=
loginUserDetailsService
.
findOne
(
id
);
String
role
=
user
.
getRoles
();
if
(
role
.
equals
(
"ADMIN"
)){
user
.
setRoles
(
"USER"
);
}
else
{
user
.
setRoles
(
"ADMIN"
);
}
loginUserDetailsService
.
create
(
user
);
return
"redirect:/limited/admin/management"
;
}
//
//user権限変更
//
@PostMapping(path = "{id}")
//
String changeRoles(Integer id, @AuthenticationPrincipal LoginUser loginUser){
//
User user = loginUserDetailsService.findOne(id);
//
String role = user.getRoles();
//
if(role.equals("ADMIN")){
//
user.setRoles("USER");
//
}else{
//
user.setRoles("ADMIN");
//
}
//
loginUserDetailsService.create(user);
//
return "redirect:/limited/admin/management";
//
}
}
src/main/java/com/example/web/ManagementRestController.java
0 → 100644
View file @
6719145e
package
com
.
example
.
web
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.annotation.AuthenticationPrincipal
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.example.domain.User
;
import
com.example.service.LoginUser
;
import
com.example.service.LoginUserDetailsService
;
@RestController
@RequestMapping
(
"limited/admin/management"
)
public
class
ManagementRestController
{
@Autowired
LoginUserDetailsService
loginUserDetailsService
;
//user権限変更
@PostMapping
(
path
=
"{id}/changeRole"
)
User
changeRoles
(
@PathVariable
Integer
id
,
@AuthenticationPrincipal
LoginUser
loginUser
,
@RequestBody
User
userdata
){
User
user
=
loginUserDetailsService
.
findOne
(
id
);
//String role = userdata.getRoles();
if
(
userdata
.
getRoles
().
equals
(
"ADMIN"
)){
user
.
setRoles
(
"USER"
);
}
else
{
user
.
setRoles
(
"ADMIN"
);
}
loginUserDetailsService
.
create
(
user
);
return
user
;
}
}
src/main/resources/static/js/management.js
View file @
6719145e
...
...
@@ -7,15 +7,44 @@ $('#user_button').on('click', function(){
$
(
'#shoe_management'
).
hide
();
})
//権限変更の確認アラート
$
(
'.roleBtn'
).
on
(
'click'
,
function
(){
if
(
!
confirm
(
'本当に権限を変更しますか?'
))
{
return
false
;
}
else
{
$
(
'.roleBtn'
).
click
(
function
(
event
){
var
token
=
$
(
"meta[name='_csrf']"
).
attr
(
"content"
);
var
header
=
$
(
"meta[name='_csrf_header']"
).
attr
(
"content"
);
$
(
document
).
ajaxSend
(
function
(
e
,
xhr
,
options
)
{
xhr
.
setRequestHeader
(
header
,
token
);
});
console
.
log
(
"ok"
);
if
(
confirm
(
'本当に権限を変更しますか?'
))
{
//user権限変更
let
userIntId
=
event
.
target
.
parentElement
.
parentElement
.
parentElement
.
parentElement
.
parentElement
.
children
[
0
].
textContent
;
let
userId
=
parseInt
(
event
.
target
.
parentElement
.
parentElement
.
parentElement
.
parentElement
.
parentElement
.
children
[
0
].
textContent
);
let
userRole
=
event
.
target
.
parentElement
.
parentElement
.
parentElement
.
parentElement
.
parentElement
.
children
[
2
].
textContent
;
let
RoleForm
=
event
.
target
.
parentElement
.
parentElement
.
parentElement
.
parentElement
.
parentElement
.
children
[
2
];
let
data
=
{
id
:
userId
,
roles
:
userRole
};
$
.
ajax
({
type
:
'POST'
,
url
:
'management/'
+
userIntId
+
'/changeRole'
,
contentType
:
'application/json'
,
dataType
:
"json"
,
data
:
JSON
.
stringify
(
data
)
})
.
done
(
function
(
data1
,
textStatus
,
jqXHR
){
//レスポンスからuserRole取得
let
responseRole
=
data1
.
roles
;
//HTML上で書き換え
RoleForm
.
textContent
=
responseRole
;
})
}
})
//商品管理
$
(
'#shoe_button'
).
on
(
'click'
,
function
(){
$
(
'#user_management'
).
hide
();
...
...
src/main/resources/templates/management.html
View file @
6719145e
...
...
@@ -2,6 +2,8 @@
<html
class=
"no-js"
lang=
"en"
xmlns:th=
"http://www.thymeleaf.org"
xmlns:sec=
"http://www.thymeleaf.org/extras/spring-security"
>
<head>
<meta
name=
"_csrf"
th:content=
"${_csrf.token}"
/>
<meta
name=
"_csrf_header"
th:content=
"${_csrf.headerName}"
/>
<meta
charset=
"utf-8"
/>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge,chrome=1"
/>
<title>
Limited
</title>
...
...
@@ -42,17 +44,20 @@
<tr
th:each=
"users : ${users}"
>
<td
th:text=
"${users.id}"
>
1
</td>
<td
th:text=
"${users.name}"
>
demo
</td>
<td
name=
"roles"
th:text=
"${users.roles}"
></td>
<td
name=
"roles"
th:text=
"${users.roles}"
class=
"userRoleForm"
></td>
<td>
<div
th:object=
"${user}"
th:switch=
"${user.id}"
>
<div
th:case=
"${users.id}"
>
<a>
ログイン中のため変更できません
</a>
</div>
<div
th:case=
"*"
>
<form
th:action=
"@{/limited/admin/management/{id}(id=${users.id})}"
th:method=
"post"
>
<form>
<button
type=
"button"
name=
"form"
value=
"権限変更"
class=
"roleBtn"
>
権限変更
</button>
</form>
<!-- <form th:action="@{/limited/admin/management/{id}(id=${users.id})}" th:method="post">
<input type="submit" name="form" value="権限変更" class="roleBtn"/>
<input type="hidden" name="id" th:value="${users.id}"/>
</form>
</form>
-->
</div>
</div>
</td>
...
...
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