后台登陆功能完善
This commit is contained in:
parent
0078c8cbd6
commit
b024e1a128
|
@ -1,14 +1,15 @@
|
||||||
package com.yzdx.AiInterviewer.controller;
|
package com.yzdx.AiInterviewer.controller;
|
||||||
|
|
||||||
import com.yzdx.AiInterviewer.comment.R;
|
import com.yzdx.AiInterviewer.comment.R;
|
||||||
|
import com.yzdx.AiInterviewer.entity.User;
|
||||||
import com.yzdx.AiInterviewer.service.UserService;
|
import com.yzdx.AiInterviewer.service.UserService;
|
||||||
|
import com.yzdx.AiInterviewer.utiles.JWT;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.http.HttpRequest;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,5 +32,19 @@ public class UserController {
|
||||||
return userService.adminLogin(phone, encoding, password);
|
return userService.adminLogin(phone, encoding, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getuserinfo")
|
||||||
|
public R getUserInfo(HttpServletRequest request) {
|
||||||
|
|
||||||
|
String Token = request.getHeader("Authorization");
|
||||||
|
|
||||||
|
Integer userId = JWT.getTokenId(Token);
|
||||||
|
|
||||||
|
User findUser = userService.getUserById(userId);
|
||||||
|
if (findUser == null) {
|
||||||
|
return R.error(401, "非法访问,请重新登陆");
|
||||||
|
}
|
||||||
|
return R.success(findUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,4 +14,7 @@ public interface UserService extends IService<User> {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
R adminLogin(String phone, String encoding, String password);
|
R adminLogin(String phone, String encoding, String password);
|
||||||
|
|
||||||
|
User getUserById(Integer userid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,4 +73,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||||
|
|
||||||
return R.success(data);
|
return R.success(data);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public User getUserById(Integer userid) {
|
||||||
|
|
||||||
|
LambdaQueryWrapper<User> queryWrapper =new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(User::getId,userid);
|
||||||
|
return userMapper.selectOne(queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue