ApiLoginController.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package io.renren.modules.app.controller;
  2. import io.renren.common.utils.R;
  3. import io.renren.common.validator.Assert;
  4. import io.renren.modules.app.service.UserService;
  5. import io.renren.modules.app.utils.JwtUtils;
  6. import io.swagger.annotations.Api;
  7. import io.swagger.annotations.ApiOperation;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.web.bind.annotation.PostMapping;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RestController;
  12. import java.util.HashMap;
  13. import java.util.Map;
  14. /**
  15. * APP登录授权
  16. *
  17. * @author chenshun
  18. * @email sunlightcs@gmail.com
  19. * @date 2017-03-23 15:31
  20. */
  21. @RestController
  22. @RequestMapping("/app")
  23. @Api("APP登录接口")
  24. public class ApiLoginController {
  25. @Autowired
  26. private UserService userService;
  27. @Autowired
  28. private JwtUtils jwtUtils;
  29. /**
  30. * 登录
  31. */
  32. @PostMapping("login")
  33. @ApiOperation("登录")
  34. public R login(String mobile, String password){
  35. Assert.isBlank(mobile, "手机号不能为空");
  36. Assert.isBlank(password, "密码不能为空");
  37. //用户登录
  38. long userId = userService.login(mobile, password);
  39. //生成token
  40. String token = jwtUtils.generateToken(userId);
  41. Map<String, Object> map = new HashMap<>();
  42. map.put("token", token);
  43. map.put("expire", jwtUtils.getExpire());
  44. return R.ok(map);
  45. }
  46. }