|
@@ -1,49 +1,51 @@
|
|
|
package com.qxgmat.controller.api;
|
|
|
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.nuliji.tools.PageMessage;
|
|
|
import com.nuliji.tools.Response;
|
|
|
import com.nuliji.tools.ResponseHelp;
|
|
|
-import com.nuliji.tools.Transform;
|
|
|
import com.nuliji.tools.exception.ParameterException;
|
|
|
import com.nuliji.tools.exception.SystemException;
|
|
|
import com.qxgmat.data.dao.entity.User;
|
|
|
-import com.qxgmat.dto.request.UserLoginDto;
|
|
|
-import com.qxgmat.dto.request.UserValidInviteCodeDto;
|
|
|
-import com.qxgmat.dto.request.UserValidMobileDto;
|
|
|
-import com.qxgmat.dto.response.MyDto;
|
|
|
-import com.qxgmat.help.CaptchaHelp;
|
|
|
+import com.qxgmat.data.dao.entity.UserMessage;
|
|
|
+import com.qxgmat.dto.request.UserEmailDto;
|
|
|
+import com.qxgmat.dto.request.UserInfoDto;
|
|
|
+import com.qxgmat.dto.response.UserRealDto;
|
|
|
import com.qxgmat.help.ShiroHelp;
|
|
|
-import com.qxgmat.help.SmsHelp;
|
|
|
import com.qxgmat.service.UsersService;
|
|
|
+import com.qxgmat.service.inline.UserMessageService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
import javax.validation.Validator;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
|
|
|
* Created by GaoJie on 2017/10/31.
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/api/auth")
|
|
|
-@Api(tags = "用户验证", description = "登录注册找回密码", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+@Api(tags = "登录用户接口", description = "获取与操作当前用户信息", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
public class MyController {
|
|
|
|
|
|
- @Autowired
|
|
|
- private Validator validator;
|
|
|
+ @Value("${upload.local_path}")
|
|
|
+ private String localPath;
|
|
|
|
|
|
- @Autowired
|
|
|
- private CaptchaHelp captchaHelp;
|
|
|
+ @Value("${upload.web_url}")
|
|
|
+ private String webUrl;
|
|
|
|
|
|
@Autowired
|
|
|
- private SmsHelp smsHelp;
|
|
|
+ private Validator validator;
|
|
|
|
|
|
@Autowired
|
|
|
private ShiroHelp shiroHelp;
|
|
@@ -51,85 +53,74 @@ public class MyController {
|
|
|
@Autowired
|
|
|
private UsersService usersService;
|
|
|
|
|
|
- @RequestMapping(value = "/login", method = RequestMethod.POST)
|
|
|
- @ApiOperation(value = "登录/注册", httpMethod = "POST")
|
|
|
- public Response<MyDto> login(@RequestBody @Validated UserLoginDto userLoginDto, HttpSession session, HttpServletRequest request) {
|
|
|
- if (!smsHelp.verifyCode(userLoginDto.getMobile(), userLoginDto.getMobileVerifyCode(), session)) {
|
|
|
- throw new ParameterException("手机验证码错误!");
|
|
|
- }
|
|
|
- User oldUser = usersService.getByMobile(userLoginDto.getMobile());
|
|
|
- if(oldUser == null){
|
|
|
-
|
|
|
- User user = Transform.convert(userLoginDto, User.class);
|
|
|
- if (userLoginDto.getInviteCode() != null && !userLoginDto.getInviteCode().isEmpty()){
|
|
|
- User origin = usersService.getByInviteCode(userLoginDto.getInviteCode());
|
|
|
- user.setOriginId(origin.getId());
|
|
|
-
|
|
|
- }
|
|
|
- user = usersService.add(user);
|
|
|
- if(user == null)
|
|
|
- throw new SystemException("注册失败");
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private UserMessageService userMessageService;
|
|
|
|
|
|
- shiroHelp.getSession().login(shiroHelp.user(userLoginDto.getMobile(), ""));
|
|
|
- return ResponseHelp.success(Transform.convert(shiroHelp.getLoginUser(), MyDto.class));
|
|
|
+ @RequestMapping(value = "/email", method = RequestMethod.POST)
|
|
|
+ @ApiOperation(value = "绑定邮箱", httpMethod = "POST")
|
|
|
+ public Response<Boolean> email(@RequestBody @Validated UserEmailDto dto, HttpSession session, HttpServletRequest request) {
|
|
|
+ User user = (User) shiroHelp.getLoginUser();
|
|
|
+ usersService.edit(User.builder()
|
|
|
+ .id(user.getId())
|
|
|
+ .email(dto.getEmail())
|
|
|
+ .build());
|
|
|
+ return ResponseHelp.success(true);
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/logout", method = RequestMethod.POST)
|
|
|
- @ApiOperation(value = "登出", httpMethod = "POST")
|
|
|
- public Response<Boolean> logout(HttpSession session, HttpServletRequest request) {
|
|
|
- shiroHelp.logout();
|
|
|
+ @RequestMapping(value = "/info", method = RequestMethod.POST)
|
|
|
+ @ApiOperation(value = "修改用户信息", httpMethod = "POST")
|
|
|
+ public Response<Boolean> info(@RequestBody @Validated UserInfoDto dto){
|
|
|
+ User user = (User) shiroHelp.getLoginUser();
|
|
|
+ usersService.edit(User.builder()
|
|
|
+ .id(user.getId())
|
|
|
+ .nickname(dto.getNickname())
|
|
|
+ .avatar(dto.getAvatar())
|
|
|
+ .build());
|
|
|
return ResponseHelp.success(true);
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/bind", method = RequestMethod.POST)
|
|
|
- @ApiOperation(value = "绑定手机号", notes="第三方登录后可执行", httpMethod = "POST")
|
|
|
- public Response<Boolean> bind(@RequestBody @Validated UserValidMobileDto userValidMobileDto, HttpSession session) {
|
|
|
- if (!smsHelp.verifyCode(userValidMobileDto.getMobile(), userValidMobileDto.getMobileVerifyCode(), session)) {
|
|
|
- throw new ParameterException("手机验证码错误!");
|
|
|
+ @RequestMapping(value = "/real", produces = MediaType.IMAGE_JPEG_VALUE, method = RequestMethod.POST)
|
|
|
+ @ApiOperation(value = "实名认证", notes = "保存用户实名信息", httpMethod = "POST")
|
|
|
+ public Response<UserRealDto> real(@RequestParam("file") MultipartFile multipartFile) {
|
|
|
+ if (multipartFile.isEmpty()) {
|
|
|
+ throw new ParameterException("上传文件为空");
|
|
|
}
|
|
|
- User openUser = (User) shiroHelp.getLoginUser();
|
|
|
- if(openUser == null)
|
|
|
- throw new SystemException("第三方登录错误");
|
|
|
- if(openUser.getMobile().length() > 0)
|
|
|
- throw new SystemException("手机号已绑定");
|
|
|
-
|
|
|
- User user = usersService.getByMobile(userValidMobileDto.getMobile());
|
|
|
- boolean result = false;
|
|
|
- if(user == null){
|
|
|
-
|
|
|
- user = new User();
|
|
|
- user.setWechatOpenidPc(openUser.getWechatOpenidPc());
|
|
|
- user.setMobile(userValidMobileDto.getMobile());
|
|
|
- user.setNickname(openUser.getNickname());
|
|
|
- user = usersService.add(user);
|
|
|
- result = user != null;
|
|
|
- }else{
|
|
|
-
|
|
|
- throw new ParameterException("该手机号已注册,请通过手机号进行登录!");
|
|
|
+ String contentType = multipartFile.getContentType();
|
|
|
+ if (!contentType.contains("")) {
|
|
|
+ throw new ParameterException("文件类型错误");
|
|
|
}
|
|
|
- return ResponseHelp.success(result);
|
|
|
- }
|
|
|
+ User user = (User) shiroHelp.getLoginUser();
|
|
|
+ UserRealDto dto = new UserRealDto();
|
|
|
|
|
|
- @RequestMapping(value = "/valid/invite_code", method = RequestMethod.POST)
|
|
|
- @ApiOperation(value = "验证邀请码", notes="查询邀请码对应账号", httpMethod = "POST")
|
|
|
- public Response<String> ValidInviteCode(@RequestBody @Validated UserValidInviteCodeDto userValidInviteCodeDto){
|
|
|
- User user = usersService.getByInviteCode(userValidInviteCodeDto.getInviteCode());
|
|
|
- if(user == null){
|
|
|
- return ResponseHelp.success(null);
|
|
|
- }else{
|
|
|
- return ResponseHelp.success(user.getNickname());
|
|
|
+
|
|
|
+ String file = UUID.randomUUID().toString();
|
|
|
+ try {
|
|
|
+ File dest = new File(localPath + File.separator+file);
|
|
|
+ multipartFile.transferTo(dest);
|
|
|
+ dto.setPhoto(webUrl+file);
|
|
|
+ usersService.edit(User.builder()
|
|
|
+ .id(user.getId())
|
|
|
+ .realAddress(dto.getAddress())
|
|
|
+ .realName(dto.getName())
|
|
|
+ .realIdentity(dto.getIdentity())
|
|
|
+ .realPhoto(dto.getPhoto())
|
|
|
+ .build());
|
|
|
+ return ResponseHelp.success(dto);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResponseHelp.exception(new SystemException("图片上传失败"));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/valid/mobile", method = RequestMethod.POST)
|
|
|
- @ApiOperation(value = "验证手机号", notes="查询邀请码对应账号", httpMethod = "POST")
|
|
|
- public Response<String> ValidMobile(@RequestBody @Validated UserValidInviteCodeDto userValidInviteCodeDto){
|
|
|
- User user = usersService.getByInviteCode(userValidInviteCodeDto.getInviteCode());
|
|
|
- if(user == null){
|
|
|
- return ResponseHelp.success(null);
|
|
|
- }else{
|
|
|
- return ResponseHelp.success(user.getNickname());
|
|
|
- }
|
|
|
+ @RequestMapping(value = "/message", method = RequestMethod.GET)
|
|
|
+ @ApiOperation(value = "用户站内信", notes = "用户消息列表", httpMethod = "GET")
|
|
|
+ public Response<PageMessage<UserMessage>> message(
|
|
|
+ @RequestParam(required = false, defaultValue = "1") int page,
|
|
|
+ @RequestParam(required = false, defaultValue = "100") int size
|
|
|
+ ) {
|
|
|
+ User user = (User) shiroHelp.getLoginUser();
|
|
|
+ Page<UserMessage> p = userMessageService.select(page, size, user.getId());
|
|
|
+
|
|
|
+ return ResponseHelp.success(p, page, size, p.getTotal());
|
|
|
}
|
|
|
}
|