mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-14 04:31:38 +08:00
后端:用户登录、退出登录、获取用户状态相关功能完成;引入SessionManager;数据库:user_identity改为group;前端:添加登录页面、后台管理页面框架,axios POST请求Content-Type问题修复,引入md5、sha1 js库;小问题调整
This commit is contained in:
@@ -10,27 +10,70 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import plus.bookshelf.Common.Response.CommonReturnType;
|
||||
import plus.bookshelf.Common.SessionManager.LocalSessionManager;
|
||||
import plus.bookshelf.Common.SessionManager.SessionManager;
|
||||
import plus.bookshelf.Controller.VO.UserVO;
|
||||
import plus.bookshelf.Service.Impl.UserServiceImpl;
|
||||
import plus.bookshelf.Service.Model.UserModel;
|
||||
|
||||
import static plus.bookshelf.Controller.Controller.BaseController.CONTENT_TYPE_FORMED;
|
||||
|
||||
@Api(value = "用户")
|
||||
@Controller
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
public class UserController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
UserServiceImpl userService;
|
||||
|
||||
@ApiOperation(value = "用户登录",notes = "传入用户名,以及密码的MD5值,进行登录")
|
||||
@ApiOperation(value = "用户登录", notes = "传入用户名,以及密码的MD5值,进行登录")
|
||||
@RequestMapping(value = "login", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
public CommonReturnType login(@RequestParam(value = "username") String username,
|
||||
@RequestParam(value = "encryptpwd") String encryptPwd) {
|
||||
@RequestParam(value = "encryptpwd") String encryptPwd) {
|
||||
if (username == null || encryptPwd == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
UserModel userModel = userService.userLogin(username, encryptPwd);
|
||||
UserVO userVO = convertFromService(userModel);
|
||||
|
||||
if (userModel != null) {
|
||||
onLogin(userModel);
|
||||
}
|
||||
return CommonReturnType.create(userVO);
|
||||
}
|
||||
|
||||
// @ApiOperation(value = "用户注册", notes = "传入用户名,以及密码的MD5值,进行注册")
|
||||
// @RequestMapping(value = "register", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
// @ResponseBody
|
||||
// public CommonReturnType register(@RequestParam(value = "username") String username,
|
||||
// @RequestParam(value = "encryptpwd") String encryptPwd) {
|
||||
// if (username == null || encryptPwd == null) {
|
||||
// return null;
|
||||
// }
|
||||
// UserModel userModel = userService.userRegister(username, encryptPwd);
|
||||
// UserVO userVO = convertFromService(userModel);
|
||||
// return CommonReturnType.create(userVO);
|
||||
// }
|
||||
|
||||
@ApiOperation(value = "用户登出", notes = "用户退出登录")
|
||||
@RequestMapping(value = "logout", method = {RequestMethod.GET})
|
||||
@ResponseBody
|
||||
public CommonReturnType logout() {
|
||||
onLogout();
|
||||
return CommonReturnType.create("success");
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取用户登录状态", notes = "获取用户登录状态")
|
||||
@RequestMapping(value = "getUserStatus", method = {RequestMethod.GET})
|
||||
@ResponseBody
|
||||
public CommonReturnType getUserStatus() {
|
||||
Object userModelObject = LocalSessionManager.getInstance(httpServletRequest).getValue("user");
|
||||
if (userModelObject == null) {
|
||||
return CommonReturnType.create(null);
|
||||
}
|
||||
|
||||
UserModel userModel = (UserModel) userModelObject;
|
||||
UserVO userVO = convertFromService(userModel);
|
||||
return CommonReturnType.create(userVO);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user