user, jsp -> html
parent
daa1e0d30f
commit
181d518df7
|
@ -81,7 +81,7 @@ public class SOSUserDetails implements UserDetails {
|
|||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
return user.enabled();
|
||||
}
|
||||
|
||||
public User user() {
|
||||
|
|
|
@ -4,10 +4,21 @@ package com.monkeyk.sos.domain.user;
|
|||
* @author Shengzhao Li
|
||||
*/
|
||||
public enum Privilege {
|
||||
/**
|
||||
* Default privilege
|
||||
*/
|
||||
USER,
|
||||
|
||||
USER, //Default privilege
|
||||
|
||||
ADMIN, //admin
|
||||
UNITY, //资源权限:UNITY
|
||||
MOBILE //资源权限:MOBILE
|
||||
/**
|
||||
* //admin
|
||||
*/
|
||||
ADMIN,
|
||||
/**
|
||||
* //资源权限:UNITY
|
||||
*/
|
||||
UNITY,
|
||||
/**
|
||||
* //资源权限:MOBILE
|
||||
*/
|
||||
MOBILE
|
||||
}
|
|
@ -41,6 +41,30 @@ public class UserDto implements Serializable {
|
|||
|
||||
private List<Privilege> privileges = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* true 启用
|
||||
* false 禁用
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
/**
|
||||
* 别名
|
||||
*
|
||||
* @see org.springframework.security.oauth2.core.oidc.OidcScopes#PROFILE
|
||||
* @since 3.0.0
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*
|
||||
* @see org.springframework.security.oauth2.core.oidc.OidcScopes#ADDRESS
|
||||
* @since 3.0.0
|
||||
*/
|
||||
private String address;
|
||||
|
||||
|
||||
public UserDto() {
|
||||
}
|
||||
|
@ -54,6 +78,35 @@ public class UserDto implements Serializable {
|
|||
|
||||
this.privileges = user.privileges();
|
||||
this.createTime = user.createTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
||||
|
||||
this.enabled = user.enabled();
|
||||
this.address = user.address();
|
||||
this.nickname = user.nickname();
|
||||
}
|
||||
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
|
|
|
@ -41,6 +41,10 @@ public class UserFormDto extends UserDto {
|
|||
.email(getEmail())
|
||||
.password(PasswordHandler.encode(getPassword()));
|
||||
user.privileges().addAll(getPrivileges());
|
||||
//v3.0.0 added
|
||||
user.address(getAddress())
|
||||
.nickname(getNickname())
|
||||
.enabled(isEnabled());
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public class UserServiceImpl implements UserService {
|
|||
private UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
|
||||
// @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
User user = userRepository.findByUsername(username);
|
||||
if (user == null || user.archived()) {
|
||||
|
@ -50,7 +50,7 @@ public class UserServiceImpl implements UserService {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
// @Transactional(readOnly = true)
|
||||
public UserJsonDto loadCurrentUserJsonDto() {
|
||||
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
final Object principal = authentication.getPrincipal();
|
||||
|
@ -65,7 +65,7 @@ public class UserServiceImpl implements UserService {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
// @Transactional(readOnly = true)
|
||||
public UserOverviewDto loadUserOverviewDto(UserOverviewDto overviewDto) {
|
||||
List<User> users = userRepository.findUsersByUsername(overviewDto.getUsername());
|
||||
overviewDto.setUserDtos(UserDto.toDtos(users));
|
||||
|
@ -73,14 +73,14 @@ public class UserServiceImpl implements UserService {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
// @Transactional(readOnly = true)
|
||||
public boolean isExistedUsername(String username) {
|
||||
final User user = userRepository.findByUsername(username);
|
||||
return user != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
// @Transactional(propagation = Propagation.REQUIRED)
|
||||
public String saveUser(UserFormDto formDto) {
|
||||
User user = formDto.newUser();
|
||||
userRepository.saveUser(user);
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width,user-scalable=no"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||
<link rel="shortcut icon" href="../static/favicon.ico" th:href="@{/favicon.ico}"/>
|
||||
|
||||
<title>Add User - Spring Security&OAuth2.1</title>
|
||||
|
||||
<th:block th:insert="~{fragments/main::header-css}"/>
|
||||
</head>
|
||||
<body class="container">
|
||||
<a th:href="@{/}">Home</a>
|
||||
|
||||
<h2>Add User</h2>
|
||||
|
||||
<form th:object="${formDto}" class="form-horizontal" th:method="post">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">Username<em class="text-danger">*</em></label>
|
||||
|
||||
<div class="col-sm-10">
|
||||
<input th:name="username" class="form-control" placeholder="Type username"
|
||||
required="required" th:field="*{username}"/>
|
||||
|
||||
<p class="help-block">Username, unique.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">Password<em class="text-danger">*</em></label>
|
||||
|
||||
<div class="col-sm-10">
|
||||
<input type="password" th:name="password" class="form-control" placeholder="Type password"
|
||||
required="required" th:field="*{password}"/>
|
||||
|
||||
<p class="help-block">Password, unique.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">Privileges<em class="text-danger">*</em></label>
|
||||
|
||||
<div class="col-sm-10">
|
||||
<label class="checkbox-inline">
|
||||
<input type="checkbox" th:name="privileges" th:value="MOBILE" th:field="*{privileges}"/> MOBILE
|
||||
</label>
|
||||
<label class="checkbox-inline">
|
||||
<input type="checkbox" th:name="privileges" th:value="UNITY" th:field="*{privileges}"/> UNITY
|
||||
</label>
|
||||
|
||||
<p class="help-block">Select Privilege(s).</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">Enable/Disable<em class="text-danger">*</em></label>
|
||||
|
||||
<div class="col-sm-10">
|
||||
<label class="checkbox-inline">
|
||||
<input type="radio" th:name="enabled" th:value="true" th:field="*{enabled}"/> Enable
|
||||
</label>
|
||||
<label class="checkbox-inline">
|
||||
<input type="radio" th:name="enabled" th:value="false" th:field="*{enabled}"/> Disable
|
||||
</label>
|
||||
|
||||
<p class="help-block">Enable/Disable the user</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">Phone</label>
|
||||
|
||||
<div class="col-sm-10">
|
||||
<input th:name="phone" class="form-control" placeholder="Type phone" th:field="*{phone}"/>
|
||||
|
||||
<p class="help-block">User phone, optional.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">Email</label>
|
||||
|
||||
<div class="col-sm-10">
|
||||
<input th:name="email" type="email" class="form-control" placeholder="Type email" th:field="*{email}"/>
|
||||
|
||||
<p class="help-block">User email, optional.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">Nickname</label>
|
||||
|
||||
<div class="col-sm-10">
|
||||
<input th:name="nickname" class="form-control" placeholder="Type nickname" th:field="*{nickname}"/>
|
||||
|
||||
<p class="help-block">User nickname, optional.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">Address</label>
|
||||
|
||||
<div class="col-sm-10">
|
||||
<input th:name="address" class="form-control" placeholder="Type address" th:field="*{address}"/>
|
||||
|
||||
<p class="help-block">User address, optional.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-2"></div>
|
||||
<div class="col-sm-10">
|
||||
<span th:errors="*" class="label label-warning"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-2"></div>
|
||||
<div class="col-sm-10">
|
||||
<button type="submit" class="btn btn-success">Save</button>
|
||||
<a href="../overview">Cancel</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
<div th:replace="~{fragments/main :: footer}"/>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue