| | |
| | | package com.moral.api.controller; |
| | | |
| | | import com.moral.constant.Constants; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import com.moral.api.entity.Group; |
| | | import com.moral.api.entity.User; |
| | | import com.moral.api.service.GroupService; |
| | | import com.moral.api.service.UserService; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.constant.ResultMessage; |
| | | import com.moral.util.AESUtils; |
| | | import com.moral.util.MD5Utils; |
| | | import com.moral.util.TokenUtils; |
| | | import com.moral.util.WebUtils; |
| | | |
| | |
| | | @Autowired |
| | | private GroupService groupService; |
| | | |
| | | @Value("${AES.KEY}") |
| | | private String AESKey; |
| | | |
| | | @ApiOperation(value = "登陆", notes = "登陆") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "account", value = "账户", required = false, paramType = "query", dataType = "String"), |
| | |
| | | if (!(parameters.containsKey("account") && parameters.containsKey("password"))) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | //接收参数 |
| | | String password = parameters.get("password").toString(); |
| | | //密码解密 |
| | | password = AESUtils.decrypt(password, AESKey); |
| | | |
| | | User user = userService.selectUserInfo(parameters); |
| | | //校验账户 |
| | | if (user == null) { |
| | | return ResultMessage.fail(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode(), ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); |
| | | Map<String, Object> result = userService.login(parameters); |
| | | if (!result.containsKey("data")) { |
| | | return ResultMessage.fail(Integer.parseInt(result.get("code").toString()), result.get("msg").toString()); |
| | | } |
| | | //校验密码 |
| | | if (!MD5Utils.saltMD5Verify(password, user.getPassword())) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PASSWORD_INVALID.getCode(), ResponseCodeEnum.PASSWORD_INVALID.getMsg()); |
| | | } |
| | | //校验是否删除 |
| | | if (Constants.DELETE.equals(user.getIsDelete())) { |
| | | return ResultMessage.fail(ResponseCodeEnum.ACCOUNT_IS_DELETE.getCode(), ResponseCodeEnum.ACCOUNT_IS_DELETE.getMsg()); |
| | | } |
| | | //校验是否过期 |
| | | if (user.getExpireTime() != null && user.getExpireTime().getTime() < System.currentTimeMillis()) { |
| | | return ResultMessage.fail(ResponseCodeEnum.ACCOUNT_IS_EXPIRE.getCode(), ResponseCodeEnum.ACCOUNT_IS_EXPIRE.getMsg()); |
| | | } |
| | | Map<String, Object> result = userService.login(user); |
| | | if (!result.containsKey("token")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.TOKEN_CREATE_ERROR.getCode(), ResponseCodeEnum.TOKEN_CREATE_ERROR.getMsg()); |
| | | } |
| | | return ResultMessage.ok(); |
| | | return ResultMessage.ok(result.get("data")); |
| | | } |
| | | |
| | | @ApiOperation(value = "注销", notes = "注销") |
| | |
| | | if (!parameters.containsKey("uid")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | String userId = request.getParameter("uid"); |
| | | String userId = parameters.get("uid").toString(); |
| | | String token = request.getHeader("token"); |
| | | TokenUtils.destoryToken(userId, token); |
| | | return ResultMessage.ok(); |