Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
Project
Project
Details
Activity
Releases
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
zengtianlai3
ioc_sixiang_license
Commits
8f386c27
Commit
8f386c27
authored
Feb 01, 2023
by
ma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善邀请注册接口
parent
016d5233
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
95 additions
and
15 deletions
+95
-15
UserController.java
...n/java/iot/sixiang/license/controller/UserController.java
+43
-5
UserMapper.java
.../src/main/java/iot/sixiang/license/mapper/UserMapper.java
+2
-2
UserService.java
...rc/main/java/iot/sixiang/license/service/UserService.java
+5
-1
UserServiceImpl.java
...ava/iot/sixiang/license/service/impl/UserServiceImpl.java
+31
-2
CommonUtil.java
...se/src/main/java/iot/sixiang/license/util/CommonUtil.java
+13
-4
UserMapper.xml
license/src/main/resources/mapper/UserMapper.xml
+1
-1
No files found.
license/src/main/java/iot/sixiang/license/controller/UserController.java
View file @
8f386c27
package
iot
.
sixiang
.
license
.
controller
;
import
cn.hutool.core.lang.Validator
;
import
com.acc.secret.util.RSAUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.xiaoymin.knife4j.annotations.ApiOperationSupport
;
...
...
@@ -12,6 +13,8 @@ import io.swagger.annotations.ApiImplicitParams;
import
io.swagger.annotations.ApiOperation
;
import
iot.sixiang.license.entity.Permission
;
import
iot.sixiang.license.entity.User
;
import
iot.sixiang.license.entity.UserPermission
;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.jwt.UserUtils
;
import
iot.sixiang.license.log.BusinessType
;
import
iot.sixiang.license.log.MyLog
;
...
...
@@ -20,6 +23,7 @@ import iot.sixiang.license.model.PageInfoModel;
import
iot.sixiang.license.model.PageResult
;
import
iot.sixiang.license.model.ResResult
;
import
iot.sixiang.license.model.dto.AssignUserPermissionDTO
;
import
iot.sixiang.license.model.dto.UpdateNotifyDTO
;
import
iot.sixiang.license.model.vo.UserDeleteVO
;
import
iot.sixiang.license.model.vo.UserUpdatePwdVo
;
import
iot.sixiang.license.model.vo.UserVo
;
...
...
@@ -27,6 +31,7 @@ import iot.sixiang.license.service.PermissionService;
import
iot.sixiang.license.service.UserPermissionService
;
import
iot.sixiang.license.service.UserService
;
import
iot.sixiang.license.util.CommonUtil
;
import
iot.sixiang.license.util.EmailUtils
;
import
iot.sixiang.license.xss.XssUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -51,6 +56,8 @@ import java.util.List;
@Api
(
value
=
"用户模块"
,
tags
=
{
"用户模块"
})
public
class
UserController
{
@Resource
EmailUtils
emailUtils
;
@Autowired
private
UserService
userService
;
@Resource
...
...
@@ -74,24 +81,42 @@ public class UserController {
}
/**
*
添加user
*
邀请用户注册
*
* @param jsonObject
* @return
*/
@ApiOperation
(
value
=
"
用户添加接口"
,
notes
=
"用于添加用户
"
)
@ApiOperation
(
value
=
"
邀请注册接口"
,
notes
=
"用于邀请用户注册
"
)
@PostMapping
(
"add"
)
@MyLog
(
title
=
"
添加用户
"
,
optParam
=
"#{jsonObject}"
,
businessType
=
BusinessType
.
INSERT
)
@MyLog
(
title
=
"
邀请用户注册
"
,
optParam
=
"#{jsonObject}"
,
businessType
=
BusinessType
.
INSERT
)
@ApiOperationSupport
(
params
=
@DynamicParameters
(
name
=
"jsonObject"
,
properties
=
{
@DynamicParameter
(
name
=
"userName"
,
value
=
"账户名"
,
required
=
true
,
dataTypeClass
=
String
.
class
),
@DynamicParameter
(
name
=
"company"
,
value
=
"公司名"
,
required
=
true
,
dataTypeClass
=
String
.
class
)
}))
public
BaseResult
addUser
(
@RequestBody
JSONObject
jsonObject
)
{
String
userId
=
UserUtils
.
getLoginUserId
();
if
(
StringUtils
.
isEmpty
(
userId
))
{
return
BaseResult
.
failed
().
setMsgValue
(
"请重新登录"
);
}
String
userName
=
(
String
)
jsonObject
.
get
(
"userName"
);
String
company
=
(
String
)
jsonObject
.
get
(
"company"
);
if
(!
Validator
.
isEmail
(
userName
))
{
throw
new
IotLicenseException
(
403
,
"请输入正确的邮箱账号"
);
}
String
password
=
CommonUtil
.
genRandomNum
(
18
);
boolean
res
=
userService
.
addUser
(
userName
,
company
,
password
);
User
user
=
userService
.
getUserById
(
Integer
.
parseInt
(
userId
));
List
<
UserPermission
>
userPermissions
=
userPermissionService
.
getPermissionById
(
user
.
getUserId
());
if
(!
CommonUtil
.
checkPermission
(
userPermissions
,
1
))
{
throw
new
IotLicenseException
(
403
,
"该用户无邀请用户注册权限!"
);
}
int
level
=
user
.
getLevel
();
if
(
level
>=
3
||
level
<=
0
)
{
return
BaseResult
.
failed
().
setMsgValue
(
"该等级账号不支持邀请注册用户"
);
}
boolean
res
=
userService
.
addUser
(
userName
,
company
,
password
,
user
.
getUserId
(),
++
level
);
if
(
res
)
{
String
content
=
"注册成功!感谢您使用实名制身份验证云应用平台,请点击以下链接登录:http://web.license.srthinker.com/user#/login"
;
emailUtils
.
sendSimpleMail
(
userName
,
"感谢您使用实名制身份验证云应用平台"
,
content
);
return
BaseResult
.
success
();
}
else
{
return
BaseResult
.
failed
();
...
...
@@ -109,6 +134,14 @@ public class UserController {
@MyLog
(
title
=
"删除用户"
,
optParam
=
"#{userId}"
,
businessType
=
BusinessType
.
DELETE
)
public
BaseResult
deleteUser
(
@RequestBody
UserDeleteVO
userDeleteVO
)
{
String
userId
=
XssUtil
.
checkXSS
(
userDeleteVO
.
getUserId
());
String
curUserId
=
UserUtils
.
getLoginUserId
();
if
(
StringUtils
.
isEmpty
(
curUserId
))
{
return
BaseResult
.
failed
().
setMsgValue
(
"请重新登录"
);
}
List
<
UserPermission
>
userPermissions
=
userPermissionService
.
getPermissionById
(
Integer
.
parseInt
(
curUserId
));
if
(!
CommonUtil
.
checkPermission
(
userPermissions
,
2
))
{
throw
new
IotLicenseException
(
403
,
"该用户无删除用户权限!"
);
}
boolean
res
=
userService
.
deleteUser
(
Integer
.
parseInt
(
userId
));
userPermissionService
.
deleteUserPermission
(
Integer
.
parseInt
(
userId
));
UserUtils
.
removeToken
(
userId
);
...
...
@@ -268,7 +301,7 @@ public class UserController {
}
/**
* 为用户批量分配权限
*
todo 待完善
为用户批量分配权限
*
* @param assignUserPermissionDTO
* @return
...
...
@@ -285,5 +318,10 @@ public class UserController {
}
}
@ApiOperation
(
value
=
"修改通知人接口"
,
notes
=
"修改通知人邮箱"
)
@PostMapping
(
"update_notify"
)
public
BaseResult
updateNotify
(
@RequestBody
UpdateNotifyDTO
updateNotifyDTO
)
{
return
userService
.
updateNotify
(
updateNotifyDTO
);
}
}
license/src/main/java/iot/sixiang/license/mapper/UserMapper.java
View file @
8f386c27
...
...
@@ -19,7 +19,7 @@ public interface UserMapper extends BaseMapper<User> {
boolean
deleteUser
(
int
user
);
boolean
addUser
(
String
userName
,
String
company
,
String
password
,
String
notify
);
boolean
addUser
(
String
userName
,
String
company
,
String
password
,
String
notify
,
int
parent
,
int
level
);
boolean
updateUser
(
int
userId
,
String
password
);
...
...
license/src/main/java/iot/sixiang/license/service/UserService.java
View file @
8f386c27
package
iot
.
sixiang
.
license
.
service
;
import
iot.sixiang.license.entity.User
;
import
iot.sixiang.license.model.BaseResult
;
import
iot.sixiang.license.model.PageInfoModel
;
import
iot.sixiang.license.model.dto.UpdateNotifyDTO
;
import
iot.sixiang.license.model.vo.UserVo
;
/**
...
...
@@ -16,7 +18,7 @@ public interface UserService {
boolean
deleteUser
(
int
userIdVo
);
boolean
addUser
(
String
userName
,
String
company
,
String
password
);
boolean
addUser
(
String
userName
,
String
company
,
String
password
,
int
parent
,
int
level
);
boolean
updateUser
(
User
user
);
...
...
@@ -25,4 +27,6 @@ public interface UserService {
User
getUserById
(
int
userId
);
User
getUserByName
(
String
root
);
BaseResult
updateNotify
(
UpdateNotifyDTO
updateNotifyDTO
);
}
license/src/main/java/iot/sixiang/license/service/impl/UserServiceImpl.java
View file @
8f386c27
...
...
@@ -7,8 +7,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import
iot.sixiang.license.consts.ResultCode
;
import
iot.sixiang.license.entity.User
;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.jwt.UserUtils
;
import
iot.sixiang.license.mapper.UserMapper
;
import
iot.sixiang.license.model.BaseResult
;
import
iot.sixiang.license.model.PageInfoModel
;
import
iot.sixiang.license.model.dto.UpdateNotifyDTO
;
import
iot.sixiang.license.model.vo.UserVo
;
import
iot.sixiang.license.service.UserService
;
import
iot.sixiang.license.util.CommonUtil
;
...
...
@@ -18,6 +21,7 @@ import org.springframework.stereotype.Service;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
...
...
@@ -74,7 +78,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
}
@Override
public
boolean
addUser
(
String
userName
,
String
company
,
String
password
)
{
public
boolean
addUser
(
String
userName
,
String
company
,
String
password
,
int
parent
,
int
level
)
{
String
notify
;
if
(
Validator
.
isEmail
(
userName
))
{
notify
=
userName
;
...
...
@@ -88,11 +92,36 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
if
(
res
!=
null
)
{
throw
new
IotLicenseException
(
403
,
"用户名已存在"
);
}
return
userMapper
.
addUser
(
userName
,
company
,
password
,
notify
);
return
userMapper
.
addUser
(
userName
,
company
,
password
,
notify
,
parent
,
level
);
}
@Override
public
boolean
updateUser
(
User
user
)
{
return
userMapper
.
updateUser
(
user
.
getUserId
(),
user
.
getPassword
());
}
@Override
public
BaseResult
updateNotify
(
UpdateNotifyDTO
updateNotifyDTO
)
{
String
notify
=
updateNotifyDTO
.
getNotify
();
String
loginUserId
=
UserUtils
.
getLoginUserId
();
if
(
StringUtils
.
isEmpty
(
notify
)
||
!
Validator
.
isEmail
(
notify
))
{
throw
new
IotLicenseException
(
ResultCode
.
VALIDATE_FAILED
.
getCode
(),
ResultCode
.
VALIDATE_FAILED
.
getMsg
());
}
if
(
StringUtils
.
isEmpty
(
loginUserId
))
{
throw
new
IotLicenseException
(
ResultCode
.
UNAUTHORIZED
.
getCode
(),
ResultCode
.
UNAUTHORIZED
.
getMsg
());
}
int
userId
=
Integer
.
parseInt
(
loginUserId
);
User
user
=
new
User
();
user
.
setNotify
(
notify
);
user
.
setUpdateTime
(
new
Date
());
LambdaQueryWrapper
<
User
>
wrapper
=
new
LambdaQueryWrapper
<>();
wrapper
.
eq
(
User:
:
getUserId
,
userId
);
int
res
=
userMapper
.
update
(
user
,
wrapper
);
if
(
res
>
0
)
{
return
BaseResult
.
success
();
}
else
{
return
BaseResult
.
failed
();
}
}
}
license/src/main/java/iot/sixiang/license/util/CommonUtil.java
View file @
8f386c27
package
iot
.
sixiang
.
license
.
util
;
import
iot.sixiang.license.consts.Constant
;
import
iot.sixiang.license.entity.UserPermission
;
import
iot.sixiang.license.model.ResResult
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -13,10 +14,7 @@ import java.security.NoSuchAlgorithmException;
import
java.security.SecureRandom
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
...
...
@@ -345,4 +343,15 @@ public class CommonUtil {
}
return
""
;
}
public
static
boolean
checkPermission
(
List
<
UserPermission
>
userPermissions
,
int
permission
)
{
boolean
res
=
false
;
for
(
UserPermission
userPermission
:
userPermissions
)
{
if
(
userPermission
.
getPermission
()
==
permission
)
{
res
=
true
;
break
;
}
}
return
res
;
}
}
license/src/main/resources/mapper/UserMapper.xml
View file @
8f386c27
...
...
@@ -3,7 +3,7 @@
<mapper
namespace=
"iot.sixiang.license.mapper.UserMapper"
>
<insert
id=
"addUser"
parameterType=
"iot.sixiang.license.entity.User"
>
insert into user(user_name, company, password, notify,
create_time, update_time) values (#{userName},#{company}, #{password}, #{notify, jdbcType=VARCHAR
}, now(), now())
insert into user(user_name, company, password, notify,
parent, `level`, create_time, update_time) values (#{userName},#{company}, #{password}, #{notify, jdbcType=VARCHAR}, #{parent}, #{level
}, now(), now())
</insert>
<delete
id=
"deleteUser"
parameterType=
"iot.sixiang.license.entity.User"
>
...
...
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