|
|
package com.xkl.controller.uploadsoft;
|
|
|
|
|
|
import com.wordnik.swagger.annotations.*;
|
|
|
import com.wordnik.swagger.annotations.Api;
|
|
|
import com.wordnik.swagger.annotations.ApiImplicitParam;
|
|
|
import com.wordnik.swagger.annotations.ApiImplicitParams;
|
|
|
import com.wordnik.swagger.annotations.ApiOperation;
|
|
|
import com.xkl.authorization.annotation.Authorization;
|
|
|
import com.xkl.authorization.annotation.CurrentAdmin;
|
|
|
import com.xkl.authorization.annotation.CurrentUser;
|
|
|
import com.xkl.authorization.manager.ITokenManager;
|
|
|
import com.xkl.authorization.model.TokenModel;
|
|
|
import com.xkl.config.Constants;
|
|
|
import com.xkl.config.ResultStatus;
|
|
|
import com.xkl.domain.AMPMachine;
|
|
|
import com.xkl.domain.Admin;
|
|
|
import com.xkl.model.ResultModel;
|
|
|
import com.xkl.repository.AMPMachineRepository;
|
|
|
import com.xkl.repository.AdminRepository;
|
|
|
import org.hibernate.validator.constraints.SafeHtml;
|
|
|
import com.xkl.security.SecurityTool;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
...
|
...
|
@@ -39,29 +40,33 @@ public class UpSoftAccountController { |
|
|
@Autowired
|
|
|
private ITokenManager tokenManager;
|
|
|
|
|
|
private static final String UPSOFT_TOKEN_PREFIX = "UPSOFT_TOKEN";
|
|
|
public static final String UPSOFT_TOKEN_PREFIX = "UPSOFTTOKEN";
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "报告上传软件登录", notes = "login")
|
|
|
|
|
|
public ResponseEntity<ResultModel> login(@RequestParam String account, @RequestParam String password
|
|
|
, @RequestParam String ampserial, @RequestParam String ampkey) {
|
|
|
public ResponseEntity<ResultModel> login(@RequestParam String account, @RequestParam String password) {
|
|
|
// , @RequestParam String ampserial, @RequestParam String ampkey
|
|
|
Assert.notNull(account, "account can not be empty");
|
|
|
Assert.notNull(password, "password can not be empty");
|
|
|
Assert.notNull(ampserial, "ampserial can not be empty");
|
|
|
Assert.notNull(ampkey, "ampkey can not be empty");
|
|
|
|
|
|
AMPMachine ampMachine = ampMachineRepository.findBySecretKey(ampkey.trim());
|
|
|
if (ampMachine == null ||// 未找到密钥所对应的机器
|
|
|
!ampMachine.getAMPSerial().equals(ampserial) ||//amp序号不符合
|
|
|
ampMachine.getStatus() != 1) {//用户无效
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.AMP_KEY_ERROR), HttpStatus.NOT_FOUND);
|
|
|
|
|
|
// Assert.notNull(ampserial, "ampserial can not be empty");
|
|
|
// Assert.notNull(ampkey, "ampkey can not be empty");
|
|
|
// AMPMachine ampMachine = ampMachineRepository.findBySecretKey(ampkey.trim());
|
|
|
// if (ampMachine == null ||// 未找到密钥所对应的机器
|
|
|
// !ampMachine.getAMPSerial().equals(ampserial) ||//amp序号不符合
|
|
|
// ampMachine.getStatus() != 1) {//用户无效
|
|
|
// return new ResponseEntity<>(ResultModel.error(ResultStatus.AMP_KEY_ERROR), HttpStatus.NOT_FOUND);
|
|
|
// }
|
|
|
Admin admin = adminRepository.findByAccountAndStatus(account, Constants.STATUS_OK);
|
|
|
//未注册
|
|
|
if (admin == null) {
|
|
|
//提示用户名或密码错误
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND);
|
|
|
}
|
|
|
|
|
|
Admin admin = adminRepository.findByAccount(account);
|
|
|
if (admin == null || //未注册
|
|
|
!admin.getPwd().equals(password) ||//密码错误
|
|
|
String salt = admin.getSalt();
|
|
|
String pass_in_db = admin.getPwd();
|
|
|
String calcuPass = SecurityTool.getPassword(account, password, salt);
|
|
|
if (!calcuPass.equals(pass_in_db) ||//密码错误
|
|
|
admin.getStatus() != 1) {//用户无效
|
|
|
//提示用户名或密码错误
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND);
|
...
|
...
|
@@ -83,17 +88,20 @@ public class UpSoftAccountController { |
|
|
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/upsoft/modpwd", method = RequestMethod.PUT)
|
|
|
@RequestMapping(method = RequestMethod.PUT)
|
|
|
@Authorization
|
|
|
@ApiOperation(value = "报告上传软件修改密码")
|
|
|
@ApiImplicitParams({
|
|
|
@ApiImplicitParam(name = "authorization", value = "请以如下格式输入登录返回信息:adminId_tokens", required = true, dataType = "string", paramType = "header"),
|
|
|
})
|
|
|
public ResponseEntity<ResultModel> modpwd(@CurrentAdmin Admin admin, @RequestParam String newpwd) {
|
|
|
|
|
|
admin = adminRepository.findById(admin.getId());
|
|
|
admin.setPwd(newpwd);
|
|
|
Assert.notNull(newpwd, "password can not be empty");
|
|
|
String salt = SecurityTool.genSalt();
|
|
|
String pass2Db = SecurityTool.getPassword(admin.getAccount(), newpwd, salt);
|
|
|
admin.setPwd(pass2Db);
|
|
|
admin.setSalt(salt);
|
|
|
adminRepository.save(admin);
|
|
|
tokenManager.deleteToken(UPSOFT_TOKEN_PREFIX + admin.getId());
|
|
|
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
|
|
|
}
|
|
|
} |
...
|
...
|
|