|
@@ -5,9 +5,7 @@ import com.jiayue.insu.common.core.util.R;
|
|
|
import com.jiayue.insu.incloud.entity.User;
|
|
|
import com.jiayue.insu.incloud.service.UserService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/login")
|
|
@@ -16,17 +14,27 @@ public class Login {
|
|
|
@Autowired
|
|
|
private UserService userService;
|
|
|
|
|
|
- @GetMapping("/doLogin")
|
|
|
- public R doLogin(String name,String pwd){
|
|
|
- User user = userService.findByNameAndPwd(name, pwd);
|
|
|
- if(user!=null){
|
|
|
- StpUtil.login(user.getName());
|
|
|
- return R.ok();
|
|
|
+ @PostMapping("/doLogin")
|
|
|
+ public R doLogin(@RequestBody User user ){
|
|
|
+ User userTar = userService.findByNameAndPwd(user.getUsername(), user.getPassword());
|
|
|
+ if(userTar!=null){
|
|
|
+ StpUtil.login(userTar.getUsername());
|
|
|
+ return R.ok(StpUtil.getTokenInfo());
|
|
|
}else{
|
|
|
- return R.failed();
|
|
|
+ return R.ok(null);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/logout")
|
|
|
+ public R logout() {
|
|
|
+ try {
|
|
|
+ StpUtil.logout();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
// 查询登录状态,浏览器访问: http://localhost:8081/user/isLogin
|
|
|
@GetMapping("/isLogin")
|
|
|
public R isLogin() {
|
|
@@ -42,4 +50,5 @@ public class Login {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|