Commit 4898c489 authored by liqin's avatar liqin 💬

bug fixed

parent b237704a
package cn.wisenergy.chnmuseum.party.common.mvc; package cn.wisenergy.chnmuseum.party.common.mvc;
public class HttpResult { public class HttpResult<T> {
// 响应的状态码 // 响应的状态码
private int code; private Integer resultCode;
// 响应的响应信息 // 响应的响应信息
private String msg; private String message;
// 响应的响应体 // 响应的响应体
private Object body; private T data;
public HttpResult() { public HttpResult() {
} }
public HttpResult(int code, String msg) { public HttpResult(Integer resultCode, String message) {
this.code = code; this.resultCode = resultCode;
this.msg = msg; this.message = message;
} }
public HttpResult(int code, Object body) { public HttpResult(Integer resultCode, T data) {
this.code = code; this.resultCode = resultCode;
this.body = body; this.data = data;
} }
public int getCode() { public HttpResult(Integer resultCode, String message, T data) {
return code; this.resultCode = resultCode;
this.message = message;
this.data = data;
} }
public void setCode(int code) { public Integer getResultCode() {
this.code = code; return resultCode;
} }
public String getMsg() { public void setResultCode(Integer resultCode) {
return msg; this.resultCode = resultCode;
} }
public void setMsg(String msg) { public String getMessage() {
this.msg = msg; return message;
} }
public Object getBody() { public void setMessage(String message) {
return body; this.message = message;
} }
public void setBody(Object body) { public T getData() {
this.body = body; return data;
} }
@Override public void setData(T data) {
public String toString() { this.data = data;
return "{" +
"\"code\":" + code +
", \"msg\":" + "\"" + msg + "\"" +
", \"body\":" + body +
'}';
} }
} }
...@@ -28,7 +28,7 @@ import java.time.LocalDateTime; ...@@ -28,7 +28,7 @@ import java.time.LocalDateTime;
@Accessors(chain = true) @Accessors(chain = true)
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@TableName("asset") @TableName("asset")
@ApiModel(value = "视频", description = "视频") @ApiModel(value = "视频", description = "视频1")
public class Asset implements Serializable { public class Asset implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -28,7 +28,7 @@ import java.time.LocalDateTime; ...@@ -28,7 +28,7 @@ import java.time.LocalDateTime;
@Accessors(chain = true) @Accessors(chain = true)
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@TableName("asset_type") @TableName("asset_type")
@ApiModel(value = "视频分类", description = "视频分类") @ApiModel(value = "视频分类", description = "视频分类1")
public class AssetType implements Serializable { public class AssetType implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -30,7 +30,7 @@ import java.util.List; ...@@ -30,7 +30,7 @@ import java.util.List;
@Accessors(chain = true) @Accessors(chain = true)
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@TableName("copyright_owner") @TableName("copyright_owner")
@ApiModel(value = "版权方", description = "版权方") @ApiModel(value = "版权方", description = "版权方1")
public class CopyrightOwner implements Serializable { public class CopyrightOwner implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -3,6 +3,7 @@ package cn.wisenergy.chnmuseum.party.web.controller; ...@@ -3,6 +3,7 @@ package cn.wisenergy.chnmuseum.party.web.controller;
import cn.wisenergy.chnmuseum.party.auth.SHA256PasswordEncryptionService; import cn.wisenergy.chnmuseum.party.auth.SHA256PasswordEncryptionService;
import cn.wisenergy.chnmuseum.party.auth.util.JwtTokenUtil; import cn.wisenergy.chnmuseum.party.auth.util.JwtTokenUtil;
import cn.wisenergy.chnmuseum.party.common.checkcode.SpecCaptcha; import cn.wisenergy.chnmuseum.party.common.checkcode.SpecCaptcha;
import cn.wisenergy.chnmuseum.party.common.mvc.HttpResult;
import cn.wisenergy.chnmuseum.party.model.Employee; import cn.wisenergy.chnmuseum.party.model.Employee;
import cn.wisenergy.chnmuseum.party.model.Menu; import cn.wisenergy.chnmuseum.party.model.Menu;
import cn.wisenergy.chnmuseum.party.service.impl.EmployeeServiceImpl; import cn.wisenergy.chnmuseum.party.service.impl.EmployeeServiceImpl;
...@@ -180,8 +181,90 @@ public class LoginController { ...@@ -180,8 +181,90 @@ public class LoginController {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
} }
/**
* 管理员ajax登录请求 后端用户登录
*
* @param username
* @param password
* @return
*/
@RequestMapping(value = "login", method = RequestMethod.POST)
public ResponseEntity<Map<String, Object>> login(@RequestParam(value = "username") String username,
@RequestParam(value = "password") String password,
@RequestParam(value = "boxNo") String boxNo,
HttpServletRequest request) {
Map<String, Object> resultMap = new LinkedHashMap<>();
Employee employee;
if (StringUtils.isNoneBlank(username)) {
//访问一次,计数一次
ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue();
if ("LOCK".equals(opsForValue.get(SHIRO_IS_LOCK + username))) {
resultMap.put("status", 400);
resultMap.put("message", "由于密码输入错误次数大于5次,12小时内帐号已禁止登录!请您联系相关管理人员,联系电话:13924551212,邮箱:325346534@zh.com。");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
}
employee = employeeService.selectByUsername(username);
if (employee == null) {
resultMap.put("status", 500);
resultMap.put("message", "用户名或密码不正确!");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
}
if (!employee.getStatus()) {
throw new DisabledAccountException("此帐号已禁用,请联系管理员!");
}
if (!employee.getAllowLogin()) {
throw new DisabledAccountException("您无权访问,请联系管理员!");
}
try {
byte[] salt = employee.getPasswordSalt();
if (!new String(SHA256PasswordEncryptionService.createPasswordHash(password, salt)).equals(new String(employee.getPasswordHash()))) {
opsForValue.increment(SHIRO_LOGIN_COUNT + username, 1);
//计数大于5时,设置用户被锁定一小时
String s = opsForValue.get(SHIRO_LOGIN_COUNT + username);
if (StringUtils.isNotBlank(s)) {
if (Integer.parseInt(s) >= 5) {
opsForValue.set(SHIRO_IS_LOCK + username, "LOCK");
stringRedisTemplate.expire(SHIRO_IS_LOCK + username, 12, TimeUnit.HOURS);
}
}
throw new IncorrectCredentialsException("用户名或密码不正确!");
}
//获取当前用户角色拥有菜单
List<Menu> userMenuPerms = this.menuService.getUserMenuPerms(employee.getRoleId());
//登录时插入系统日志
String operationContent = username + "登录本系统";
if (employee.getBankBranchName() != null) {
operationContent += ",归属网点" + employee.getBankBranchName();
}
this.sysLogController.insertSysLog(operationContent, username);
String token = JwtTokenUtil.sign(username, employee.getId());
// 将token信息存入Redis
stringRedisTemplate.opsForValue().set(SHIRO_JWT_TOKEN + token, employee.getId(), 240, TimeUnit.MINUTES);
resultMap.put("employee", employee);
resultMap.put("token", token);
new HttpResult()
resultMap.put("resultCode", 200);
resultMap.put("message", "成功");
return ResponseEntity.status(HttpStatus.OK).body(resultMap);
} catch (Exception e) {
resultMap.put("status", 500);
resultMap.put("message", e.getMessage());
}
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
}
@RequestMapping(value = "logout", method = RequestMethod.GET) @RequestMapping(value = "logout", method = RequestMethod.GET)
public ResponseEntity<Void> logout(@RequestParam(required = true) String token) { public ResponseEntity<Void> logout(@RequestParam(value = "token") String token) {
try { try {
if (StringUtils.isNotBlank(token)) { if (StringUtils.isNotBlank(token)) {
SecurityUtils.getSubject().logout(); SecurityUtils.getSubject().logout();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment