|
@ -3,12 +3,17 @@ package org.hlrj.duobao_demo.controller; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.hlrj.duobao_demo.entity.User; |
|
|
import org.hlrj.duobao_demo.entity.User; |
|
|
import org.hlrj.duobao_demo.service.IUserService; |
|
|
import org.hlrj.duobao_demo.service.IUserService; |
|
|
|
|
|
import org.hlrj.duobao_demo.tool.JwtUtils; |
|
|
import org.hlrj.duobao_demo.tool.Result; |
|
|
import org.hlrj.duobao_demo.tool.Result; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @program: duobao_demo |
|
|
* @program: duobao_demo |
|
|
* @ClassName LoginController |
|
|
* @ClassName LoginController |
|
@ -29,9 +34,14 @@ public class LoginController { |
|
|
log.info("登录操作:{}",user); |
|
|
log.info("登录操作:{}",user); |
|
|
User user1 = userService.login(user); |
|
|
User user1 = userService.login(user); |
|
|
if (user1 != null) { |
|
|
if (user1 != null) { |
|
|
return Result.error("用户名或者密码错误"); |
|
|
|
|
|
}else { |
|
|
|
|
|
return Result.success("登录成功"); |
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
|
map.put("userid",user1.getUserid()); |
|
|
|
|
|
map.put("username",user1.getUsername()); |
|
|
|
|
|
map.put("createTime",user1.getCreateTime()); |
|
|
|
|
|
//生成jwt令牌 |
|
|
|
|
|
String jwt = JwtUtils.generateJwt(map); |
|
|
|
|
|
return Result.success(jwt); |
|
|
} |
|
|
} |
|
|
|
|
|
return Result.error("用户名或者密码错误"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |