@RequestMapping("users")
@RestController
public class UsersController {
@Autowired
private UsersService userService;
@Autowired
private TokenService tokenService;
@IgnoreAuth
@RequestMapping(value = "/login")
public R login(String username, String password, String captcha, HttpServletRequest request) {
UsersEntity user = userService.selectOne(new EntityWrapper<UsersEntity>().eq("username", username));
if (user == null || !user.getPassword().equals(password)) {
return R.error("账号或密码不正确");
}
String token = tokenService.generateToken(user.getId(), username, "users", user.getRole());
return R.ok().put("token", token);
}
}