Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private final UserRepository userRepository;
- private boolean logined;
- @Autowired
- public UserServiceImpl(UserRepository userRepository) {
- this.userRepository = userRepository;
- }
- public boolean login(String name, String password)
- {
- User user = userRepository.findOne(name);
- if(user == null)
- {
- return false;
- }
- boolean result = user.getPassword().equals(password);
- logined = result;
- return logined;
- }
- public void logout()
- {
- logined = false;
- }
- public boolean isLogined() {
- return logined;
- }
- boolean login(String name, String password);
- void logout();
- boolean isLogined();
- List<News> findAllNews();
- @Id
- private String name;
- private String password;
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- private long id;
- private String title;
- private String text;
- @Id
- public long getId() {
- return id;
- }
- public void setId(long id) {
- this.id = id;
- }
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public String getText() {
- return text;
- }
- public void setText(String text) {
- this.text = text;
- }
- @Autowired
- private NewsRepository rep;
- @RequestMapping("/news")
- public @ResponseBody
- java.util.List<News> index()
- {
- return rep.findAllNews();
- }
- @Autowired
- private UserService userService;
- @RequestMapping("/**")
- public Object index()
- {
- return new Error("no access");
- }
- @RequestMapping("/rest/login")
- public Object login(@RequestParam("username") String username, @RequestParam("password") String password) {
- String response;
- if(userService.login(username, password))
- {
- response = Utitlity.constructJSON("login",true);
- return response;
- }
- return new Error("auth failed");
- }
- @RequestMapping("/rest/logout")
- public Object logout() {
- if(!userService.isLogined()){
- return new Error("no logined");
- }
- userService.logout();
- return new Response("loggedout");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement