|
|
@@ -1,46 +1,64 @@
|
|
|
package com.example.hotel.controller.user;
|
|
|
|
|
|
import com.example.hotel.blImpl.user.AccountServiceImpl;
|
|
|
-import com.example.hotel.config.InterceptorConfiguration;
|
|
|
+import com.example.hotel.po.User;
|
|
|
+import com.example.hotel.util.TokenUtil;
|
|
|
import com.example.hotel.vo.UserForm;
|
|
|
import com.example.hotel.vo.ResponseVO;
|
|
|
+import com.example.hotel.vo.UserInfoVO;
|
|
|
import com.example.hotel.vo.UserVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import javax.servlet.http.HttpSession;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
@RestController()
|
|
|
@RequestMapping("/api")
|
|
|
public class AccountController {
|
|
|
- private final static String ACCOUNT_INFO_ERROR="用户名或密码错误";
|
|
|
+ private final static String ACCOUNT_INFO_ERROR = "用户名或密码错误";
|
|
|
@Autowired
|
|
|
private AccountServiceImpl accountService;
|
|
|
|
|
|
@PostMapping("/login")
|
|
|
- public ResponseVO login(@RequestBody UserForm userForm, HttpSession session){
|
|
|
- UserVO user = accountService.login(userForm);
|
|
|
- if(user==null){
|
|
|
- return ResponseVO.buildFailure(ACCOUNT_INFO_ERROR);
|
|
|
+ public ResponseVO login(@RequestBody UserForm userForm) {
|
|
|
+ User user = accountService.login(userForm);
|
|
|
+ if (user == null) {
|
|
|
+ return ResponseVO.buildFailure(ACCOUNT_INFO_ERROR);
|
|
|
}
|
|
|
- //注册session
|
|
|
- session.setAttribute(InterceptorConfiguration.SESSION_KEY,userForm);
|
|
|
- return ResponseVO.buildSuccess(user);
|
|
|
+ String token = TokenUtil.sign(user);
|
|
|
+ return ResponseVO.buildSuccess(token);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@PostMapping("/register")
|
|
|
- public ResponseVO registerAccount(@RequestBody UserForm userForm){
|
|
|
- return accountService.registerAccount(userForm);
|
|
|
+ public ResponseVO registerAccount(@RequestBody UserVO userVO) {
|
|
|
+ return accountService.registerAccount(userVO);
|
|
|
}
|
|
|
|
|
|
- @PostMapping("/logout")
|
|
|
- public String logOut(HttpSession session){
|
|
|
- session.removeAttribute(InterceptorConfiguration.SESSION_KEY);
|
|
|
- return "index";
|
|
|
+// @PostMapping("/logout")
|
|
|
+// public String logOut(HttpSession session) {
|
|
|
+// session.removeAttribute(InterceptorConfiguration.SESSION_KEY);
|
|
|
+// return "index";
|
|
|
+// }
|
|
|
+
|
|
|
+ @GetMapping("/userinfo")
|
|
|
+ public ResponseVO getUserInfo(HttpServletRequest httpServletRequest) {
|
|
|
+ String token = httpServletRequest.getHeader("token");
|
|
|
+ String email = TokenUtil.getEmail(token);
|
|
|
+ User user = accountService.getUserInfo(email);
|
|
|
+ if(user==null){
|
|
|
+ return ResponseVO.buildFailure(ACCOUNT_INFO_ERROR);
|
|
|
+ }
|
|
|
+ return ResponseVO.buildSuccess(user);
|
|
|
}
|
|
|
|
|
|
-// @GetMapping("/usertype")
|
|
|
-// public String getUserType()
|
|
|
+ @PostMapping("/userinfo/update")
|
|
|
+ public ResponseVO updateInfo(@RequestBody UserInfoVO userInfoVO, HttpServletRequest httpServletRequest){
|
|
|
+ String token = httpServletRequest.getHeader("token");
|
|
|
+ String email = TokenUtil.getEmail(token);
|
|
|
+ return accountService.updateUserInfo(email,userInfoVO.getPassword(),userInfoVO.getUserName(),userInfoVO.getPhoneNumber());
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|