Authored by zhaoyue

ADD code for uspih

git add --all src/*
git add push.sh
git add pom.xml
git commit -m "Fix little points"
git commit -m "ADD code for uspih"
git push origin zhaoyue-dev4
git status
... ...
... ... @@ -4,14 +4,14 @@ package com.xkl.config;
* 自定义请求状态码
*/
public enum ResultStatus {
SUCCESS(100, "成功"),
SUCCESS(100, "成功/Success"),
SIGN_ERROR(-100, "签名错误或者客户端时间有误"),
USER_REGISTER(1000,"用户注册成功"),
USER_LOGOUT(1001,"退出登录成功"),
USER_MODPASS_LOGOUT(1002,"修改密码成功,请重新登录"),
USERNAME_OR_PASSWORD_ERROR(-1001, "用户名或密码错误"),
USER_NOT_FOUND(-1002, "用户不存在"),
USERNAME_OR_PASSWORD_ERROR(-1001, "用户名或密码错误/Account or Password is wrong"),
USER_NOT_FOUND(-1002, "用户不存在/User is not exist"),
USER_NOT_LOGIN(-1004, "用户未登录"),
USER_IS_EXIT(-1005, "用户已注册"),
... ...
package com.xkl.controller;
import com.xkl.authorization.annotation.Authorization;
import com.xkl.authorization.annotation.CurrentUser;
import com.xkl.authorization.annotation.LogAnnotation;
import com.xkl.authorization.annotation.Sign;
import com.xkl.authorization.annotation.*;
import com.xkl.authorization.manager.ITokenManager;
import com.xkl.config.Constants;
import com.xkl.config.ResultStatus;
import com.xkl.domain.User;
import com.xkl.domain.XklAdminEntity;
import com.xkl.domain.XklMemberEntity;
import com.xkl.model.ResultModel;
import com.xkl.repository.UserRepository;
... ... @@ -120,5 +118,4 @@ public class UserInfoController {
XklMemberEntity xklMemberEntity=xklMemberRespository.findOne(member_id);
return new ResponseEntity<>(ResultModel.ok(xklMemberEntity), HttpStatus.OK);
}
}
... ...
package com.xkl.controller.uspih;
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.manager.ITokenManager;
import com.xkl.authorization.model.TokenModel;
import com.xkl.config.Constants;
import com.xkl.config.ResultStatus;
import com.xkl.domain.XklAdminEntity;
import com.xkl.model.ResultModel;
import com.xkl.repository.AMPMachineRepository;
import com.xkl.repository.AdminRepository;
import com.xkl.security.AntiXSS;
import com.xkl.security.SecurityTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* USPIH软件登录及退出接口
* 获取和删除token的请求地址,在Restful设计中其实就对应着登录和退出登录的资源映射
*/
@RestController
@Api("USPIH admin account login and logout")
@RequestMapping("/uspih/account")
public class AdminAccountController {
@Autowired
private AdminRepository adminRepository;
@Autowired
private ITokenManager tokenManager;
public static final String USPIH_TOKEN_PREFIX = "USPIHTOKEN";
@AntiXSS
@RequestMapping(method = RequestMethod.POST)
@ApiOperation(value = "USPIH Login", notes = "login")
public ResponseEntity<ResultModel> login(@RequestParam String account, @RequestParam String password) {
Assert.notNull(account, "account can not be empty");
Assert.notNull(password, "password can not be empty");
XklAdminEntity admin = adminRepository.findByAccountAndStatus(account, Constants.STATUS_OK);
//未注册
if (admin == null) {
//提示用户名或密码错误
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND);
}
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);
}
//生成一个token,保存用户登录状态
TokenModel model = tokenManager.createToken(USPIH_TOKEN_PREFIX + admin.getId());
return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK);
}
@RequestMapping(method = RequestMethod.DELETE)
@Authorization
@ApiOperation(value = "USPIH logout")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "Input id and login token: userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> logout(@CurrentAdmin XklAdminEntity admin) {
tokenManager.deleteToken(USPIH_TOKEN_PREFIX + admin.getId());
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
}
}
... ...
package com.xkl.controller.uspih;
import com.wordnik.swagger.annotations.ApiImplicitParam;
import com.wordnik.swagger.annotations.ApiImplicitParams;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xkl.authorization.annotation.*;
import com.xkl.authorization.manager.ITokenManager;
import com.xkl.config.Constants;
import com.xkl.config.ResultStatus;
import com.xkl.domain.User;
import com.xkl.domain.XklAdminEntity;
import com.xkl.domain.XklMemberEntity;
import com.xkl.model.ResultModel;
import com.xkl.repository.UserRepository;
import com.xkl.repository.XklMemberRespository;
import com.xkl.security.AntiXSS;
import com.xkl.security.SecurityTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
/**
* @author zhaoyue
*/
@RestController
@RequestMapping("/uspihusr")
public class UserAccountController {
@Autowired
private UserRepository userRepository;
@RequestMapping(method = RequestMethod.GET)
@AntiXSS
@Authorization
@ApiOperation(value = "USPIH usr account check")
@LogAnnotation
public ResponseEntity<ResultModel> verifyUsrAccount(@CurrentAdmin XklAdminEntity admin, @RequestParam String usraccount) {
Assert.notNull(usraccount, "usraccount can not be empty");
User user = userRepository.findByLoginAccountAndStatus(usraccount, Constants.STATUS_OK2);
if (user == null) {//用户未找到
return new ResponseEntity<>(ResultModel.error(ResultStatus.USER_NOT_FOUND), HttpStatus.OK);
}
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
}
}
... ...
package com.xkl.controller.uspih;
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.domain.XklAdminEntity;
import com.xkl.model.ResultModel;
import com.xkl.repository.*;
import com.xkl.security.AntiXSS;
import com.xkl.service.IReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 上传报告及删除报告接口。
*/
@RestController
@RequestMapping("/uspih/report")
public class UspihReportController {
@Autowired
private UpSoftVersionRepository upSoftVersionRepository;
@Autowired
private IReportService reportService;
@Autowired
private ReportRepository reportRepository;
@Autowired
private ReportDetailRepository reportDetailRepository;
@Autowired
private UserRepository userRepository;
@Autowired
private AdminRepository adminRepository;
@RequestMapping(method = RequestMethod.POST)
@AntiXSS
@Authorization
@ApiOperation(value = "上传并存储报告/Upload and save report")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> save(@CurrentAdmin XklAdminEntity admin, @RequestParam String json_report) {
// 其中json_report格式为上传软件上传上来的原始report格式。
return reportService.save(admin, json_report);
}
@RequestMapping(method = RequestMethod.DELETE)
@AntiXSS
@Authorization
@ApiOperation(value = "删除报告/Delete report with report id")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> delete(@CurrentAdmin XklAdminEntity admin, @RequestParam long report_id) {
return reportService.delete(admin, report_id);
}
}
... ...
... ... @@ -388,4 +388,12 @@ public class XklAmpReportEntity {
public void setCompanyId(long companyId) {
this.companyId = companyId;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}
... ...
... ... @@ -7,4 +7,6 @@ import com.xkl.domain.User;
*/
public interface ILoginService {
public User check(String username, String password);
public User check(String username);
}
... ...
... ... @@ -29,4 +29,10 @@ public class LoginServiceImpl implements ILoginService{
}
return user;
}
@Override
public User check(String username) {
User user = userRepository.findByLoginAccountAndStatus(username.trim(), Constants.STATUS_OK2);
return user;
}
}
... ...