Showing
9 changed files
with
230 additions
and
9 deletions
@@ -4,14 +4,14 @@ package com.xkl.config; | @@ -4,14 +4,14 @@ package com.xkl.config; | ||
4 | * 自定义请求状态码 | 4 | * 自定义请求状态码 |
5 | */ | 5 | */ |
6 | public enum ResultStatus { | 6 | public enum ResultStatus { |
7 | - SUCCESS(100, "成功"), | 7 | + SUCCESS(100, "成功/Success"), |
8 | SIGN_ERROR(-100, "签名错误或者客户端时间有误"), | 8 | SIGN_ERROR(-100, "签名错误或者客户端时间有误"), |
9 | 9 | ||
10 | USER_REGISTER(1000,"用户注册成功"), | 10 | USER_REGISTER(1000,"用户注册成功"), |
11 | USER_LOGOUT(1001,"退出登录成功"), | 11 | USER_LOGOUT(1001,"退出登录成功"), |
12 | USER_MODPASS_LOGOUT(1002,"修改密码成功,请重新登录"), | 12 | USER_MODPASS_LOGOUT(1002,"修改密码成功,请重新登录"), |
13 | - USERNAME_OR_PASSWORD_ERROR(-1001, "用户名或密码错误"), | ||
14 | - USER_NOT_FOUND(-1002, "用户不存在"), | 13 | + USERNAME_OR_PASSWORD_ERROR(-1001, "用户名或密码错误/Account or Password is wrong"), |
14 | + USER_NOT_FOUND(-1002, "用户不存在/User is not exist"), | ||
15 | USER_NOT_LOGIN(-1004, "用户未登录"), | 15 | USER_NOT_LOGIN(-1004, "用户未登录"), |
16 | USER_IS_EXIT(-1005, "用户已注册"), | 16 | USER_IS_EXIT(-1005, "用户已注册"), |
17 | 17 |
1 | package com.xkl.controller; | 1 | package com.xkl.controller; |
2 | 2 | ||
3 | -import com.xkl.authorization.annotation.Authorization; | ||
4 | -import com.xkl.authorization.annotation.CurrentUser; | ||
5 | -import com.xkl.authorization.annotation.LogAnnotation; | ||
6 | -import com.xkl.authorization.annotation.Sign; | 3 | +import com.xkl.authorization.annotation.*; |
7 | import com.xkl.authorization.manager.ITokenManager; | 4 | import com.xkl.authorization.manager.ITokenManager; |
8 | import com.xkl.config.Constants; | 5 | import com.xkl.config.Constants; |
9 | import com.xkl.config.ResultStatus; | 6 | import com.xkl.config.ResultStatus; |
10 | import com.xkl.domain.User; | 7 | import com.xkl.domain.User; |
8 | +import com.xkl.domain.XklAdminEntity; | ||
11 | import com.xkl.domain.XklMemberEntity; | 9 | import com.xkl.domain.XklMemberEntity; |
12 | import com.xkl.model.ResultModel; | 10 | import com.xkl.model.ResultModel; |
13 | import com.xkl.repository.UserRepository; | 11 | import com.xkl.repository.UserRepository; |
@@ -120,5 +118,4 @@ public class UserInfoController { | @@ -120,5 +118,4 @@ public class UserInfoController { | ||
120 | XklMemberEntity xklMemberEntity=xklMemberRespository.findOne(member_id); | 118 | XklMemberEntity xklMemberEntity=xklMemberRespository.findOne(member_id); |
121 | return new ResponseEntity<>(ResultModel.ok(xklMemberEntity), HttpStatus.OK); | 119 | return new ResponseEntity<>(ResultModel.ok(xklMemberEntity), HttpStatus.OK); |
122 | } | 120 | } |
123 | - | ||
124 | } | 121 | } |
1 | +package com.xkl.controller.uspih; | ||
2 | + | ||
3 | +import com.wordnik.swagger.annotations.Api; | ||
4 | +import com.wordnik.swagger.annotations.ApiImplicitParam; | ||
5 | +import com.wordnik.swagger.annotations.ApiImplicitParams; | ||
6 | +import com.wordnik.swagger.annotations.ApiOperation; | ||
7 | +import com.xkl.authorization.annotation.Authorization; | ||
8 | +import com.xkl.authorization.annotation.CurrentAdmin; | ||
9 | +import com.xkl.authorization.manager.ITokenManager; | ||
10 | +import com.xkl.authorization.model.TokenModel; | ||
11 | +import com.xkl.config.Constants; | ||
12 | +import com.xkl.config.ResultStatus; | ||
13 | +import com.xkl.domain.XklAdminEntity; | ||
14 | +import com.xkl.model.ResultModel; | ||
15 | +import com.xkl.repository.AMPMachineRepository; | ||
16 | +import com.xkl.repository.AdminRepository; | ||
17 | +import com.xkl.security.AntiXSS; | ||
18 | +import com.xkl.security.SecurityTool; | ||
19 | +import org.springframework.beans.factory.annotation.Autowired; | ||
20 | +import org.springframework.http.HttpStatus; | ||
21 | +import org.springframework.http.ResponseEntity; | ||
22 | +import org.springframework.util.Assert; | ||
23 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
24 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
25 | +import org.springframework.web.bind.annotation.RequestParam; | ||
26 | +import org.springframework.web.bind.annotation.RestController; | ||
27 | + | ||
28 | +/** | ||
29 | + * USPIH软件登录及退出接口 | ||
30 | + * 获取和删除token的请求地址,在Restful设计中其实就对应着登录和退出登录的资源映射 | ||
31 | + */ | ||
32 | +@RestController | ||
33 | +@Api("USPIH admin account login and logout") | ||
34 | +@RequestMapping("/uspih/account") | ||
35 | +public class AdminAccountController { | ||
36 | + | ||
37 | + @Autowired | ||
38 | + private AdminRepository adminRepository; | ||
39 | + | ||
40 | + @Autowired | ||
41 | + private ITokenManager tokenManager; | ||
42 | + | ||
43 | + public static final String USPIH_TOKEN_PREFIX = "USPIHTOKEN"; | ||
44 | + | ||
45 | + | ||
46 | + @AntiXSS | ||
47 | + @RequestMapping(method = RequestMethod.POST) | ||
48 | + @ApiOperation(value = "USPIH Login", notes = "login") | ||
49 | + public ResponseEntity<ResultModel> login(@RequestParam String account, @RequestParam String password) { | ||
50 | + Assert.notNull(account, "account can not be empty"); | ||
51 | + Assert.notNull(password, "password can not be empty"); | ||
52 | + | ||
53 | + | ||
54 | + XklAdminEntity admin = adminRepository.findByAccountAndStatus(account, Constants.STATUS_OK); | ||
55 | + //未注册 | ||
56 | + if (admin == null) { | ||
57 | + //提示用户名或密码错误 | ||
58 | + return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND); | ||
59 | + } | ||
60 | + String salt = admin.getSalt(); | ||
61 | + String pass_in_db = admin.getPwd(); | ||
62 | + String calcuPass = SecurityTool.getPassword(account, password, salt); | ||
63 | + if (!calcuPass.equals(pass_in_db) ||//密码错误 | ||
64 | + admin.getStatus() != 1) {//用户无效 | ||
65 | + //提示用户名或密码错误 | ||
66 | + return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND); | ||
67 | + } | ||
68 | + | ||
69 | + //生成一个token,保存用户登录状态 | ||
70 | + TokenModel model = tokenManager.createToken(USPIH_TOKEN_PREFIX + admin.getId()); | ||
71 | + return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK); | ||
72 | + } | ||
73 | + | ||
74 | + @RequestMapping(method = RequestMethod.DELETE) | ||
75 | + @Authorization | ||
76 | + @ApiOperation(value = "USPIH logout") | ||
77 | + @ApiImplicitParams({ | ||
78 | + @ApiImplicitParam(name = "authorization", value = "Input id and login token: userId_tokens", required = true, dataType = "string", paramType = "header"), | ||
79 | + }) | ||
80 | + public ResponseEntity<ResultModel> logout(@CurrentAdmin XklAdminEntity admin) { | ||
81 | + tokenManager.deleteToken(USPIH_TOKEN_PREFIX + admin.getId()); | ||
82 | + return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK); | ||
83 | + } | ||
84 | +} |
1 | +package com.xkl.controller.uspih; | ||
2 | + | ||
3 | +import com.wordnik.swagger.annotations.ApiImplicitParam; | ||
4 | +import com.wordnik.swagger.annotations.ApiImplicitParams; | ||
5 | +import com.wordnik.swagger.annotations.ApiOperation; | ||
6 | +import com.xkl.authorization.annotation.*; | ||
7 | +import com.xkl.authorization.manager.ITokenManager; | ||
8 | +import com.xkl.config.Constants; | ||
9 | +import com.xkl.config.ResultStatus; | ||
10 | +import com.xkl.domain.User; | ||
11 | +import com.xkl.domain.XklAdminEntity; | ||
12 | +import com.xkl.domain.XklMemberEntity; | ||
13 | +import com.xkl.model.ResultModel; | ||
14 | +import com.xkl.repository.UserRepository; | ||
15 | +import com.xkl.repository.XklMemberRespository; | ||
16 | +import com.xkl.security.AntiXSS; | ||
17 | +import com.xkl.security.SecurityTool; | ||
18 | +import org.springframework.beans.factory.annotation.Autowired; | ||
19 | +import org.springframework.http.HttpStatus; | ||
20 | +import org.springframework.http.ResponseEntity; | ||
21 | +import org.springframework.util.Assert; | ||
22 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
23 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
24 | +import org.springframework.web.bind.annotation.RequestParam; | ||
25 | +import org.springframework.web.bind.annotation.RestController; | ||
26 | + | ||
27 | +import javax.servlet.http.HttpServletRequest; | ||
28 | + | ||
29 | +/** | ||
30 | + * @author zhaoyue | ||
31 | + */ | ||
32 | +@RestController | ||
33 | +@RequestMapping("/uspihusr") | ||
34 | +public class UserAccountController { | ||
35 | + @Autowired | ||
36 | + private UserRepository userRepository; | ||
37 | + | ||
38 | + | ||
39 | + @RequestMapping(method = RequestMethod.GET) | ||
40 | + @AntiXSS | ||
41 | + @Authorization | ||
42 | + @ApiOperation(value = "USPIH usr account check") | ||
43 | + @LogAnnotation | ||
44 | + public ResponseEntity<ResultModel> verifyUsrAccount(@CurrentAdmin XklAdminEntity admin, @RequestParam String usraccount) { | ||
45 | + Assert.notNull(usraccount, "usraccount can not be empty"); | ||
46 | + User user = userRepository.findByLoginAccountAndStatus(usraccount, Constants.STATUS_OK2); | ||
47 | + if (user == null) {//用户未找到 | ||
48 | + return new ResponseEntity<>(ResultModel.error(ResultStatus.USER_NOT_FOUND), HttpStatus.OK); | ||
49 | + } | ||
50 | + return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK); | ||
51 | + } | ||
52 | + | ||
53 | + | ||
54 | +} |
1 | +package com.xkl.controller.uspih; | ||
2 | + | ||
3 | +import com.wordnik.swagger.annotations.ApiImplicitParam; | ||
4 | +import com.wordnik.swagger.annotations.ApiImplicitParams; | ||
5 | +import com.wordnik.swagger.annotations.ApiOperation; | ||
6 | +import com.xkl.authorization.annotation.Authorization; | ||
7 | +import com.xkl.authorization.annotation.CurrentAdmin; | ||
8 | +import com.xkl.domain.XklAdminEntity; | ||
9 | +import com.xkl.model.ResultModel; | ||
10 | +import com.xkl.repository.*; | ||
11 | +import com.xkl.security.AntiXSS; | ||
12 | +import com.xkl.service.IReportService; | ||
13 | +import org.springframework.beans.factory.annotation.Autowired; | ||
14 | +import org.springframework.http.ResponseEntity; | ||
15 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
16 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
17 | +import org.springframework.web.bind.annotation.RequestParam; | ||
18 | +import org.springframework.web.bind.annotation.RestController; | ||
19 | + | ||
20 | + | ||
21 | +/** | ||
22 | + * 上传报告及删除报告接口。 | ||
23 | + */ | ||
24 | +@RestController | ||
25 | +@RequestMapping("/uspih/report") | ||
26 | +public class UspihReportController { | ||
27 | + | ||
28 | + @Autowired | ||
29 | + private UpSoftVersionRepository upSoftVersionRepository; | ||
30 | + | ||
31 | + @Autowired | ||
32 | + private IReportService reportService; | ||
33 | + | ||
34 | + @Autowired | ||
35 | + private ReportRepository reportRepository; | ||
36 | + | ||
37 | + @Autowired | ||
38 | + private ReportDetailRepository reportDetailRepository; | ||
39 | + | ||
40 | + | ||
41 | + @Autowired | ||
42 | + private UserRepository userRepository; | ||
43 | + | ||
44 | + @Autowired | ||
45 | + private AdminRepository adminRepository; | ||
46 | + | ||
47 | + @RequestMapping(method = RequestMethod.POST) | ||
48 | + @AntiXSS | ||
49 | + @Authorization | ||
50 | + @ApiOperation(value = "上传并存储报告/Upload and save report") | ||
51 | + @ApiImplicitParams({ | ||
52 | + @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"), | ||
53 | + }) | ||
54 | + public ResponseEntity<ResultModel> save(@CurrentAdmin XklAdminEntity admin, @RequestParam String json_report) { | ||
55 | + // 其中json_report格式为上传软件上传上来的原始report格式。 | ||
56 | + return reportService.save(admin, json_report); | ||
57 | + } | ||
58 | + | ||
59 | + @RequestMapping(method = RequestMethod.DELETE) | ||
60 | + @AntiXSS | ||
61 | + @Authorization | ||
62 | + @ApiOperation(value = "删除报告/Delete report with report id") | ||
63 | + @ApiImplicitParams({ | ||
64 | + @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"), | ||
65 | + }) | ||
66 | + public ResponseEntity<ResultModel> delete(@CurrentAdmin XklAdminEntity admin, @RequestParam long report_id) { | ||
67 | + return reportService.delete(admin, report_id); | ||
68 | + } | ||
69 | + | ||
70 | +} |
@@ -388,4 +388,12 @@ public class XklAmpReportEntity { | @@ -388,4 +388,12 @@ public class XklAmpReportEntity { | ||
388 | public void setCompanyId(long companyId) { | 388 | public void setCompanyId(long companyId) { |
389 | this.companyId = companyId; | 389 | this.companyId = companyId; |
390 | } | 390 | } |
391 | + | ||
392 | + public int getStatus() { | ||
393 | + return status; | ||
394 | + } | ||
395 | + | ||
396 | + public void setStatus(int status) { | ||
397 | + this.status = status; | ||
398 | + } | ||
391 | } | 399 | } |
@@ -7,4 +7,6 @@ import com.xkl.domain.User; | @@ -7,4 +7,6 @@ import com.xkl.domain.User; | ||
7 | */ | 7 | */ |
8 | public interface ILoginService { | 8 | public interface ILoginService { |
9 | public User check(String username, String password); | 9 | public User check(String username, String password); |
10 | + public User check(String username); | ||
11 | + | ||
10 | } | 12 | } |
@@ -29,4 +29,10 @@ public class LoginServiceImpl implements ILoginService{ | @@ -29,4 +29,10 @@ public class LoginServiceImpl implements ILoginService{ | ||
29 | } | 29 | } |
30 | return user; | 30 | return user; |
31 | } | 31 | } |
32 | + | ||
33 | + @Override | ||
34 | + public User check(String username) { | ||
35 | + User user = userRepository.findByLoginAccountAndStatus(username.trim(), Constants.STATUS_OK2); | ||
36 | + return user; | ||
37 | + } | ||
32 | } | 38 | } |
-
Please register or login to post a comment