Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. private final UserRepository userRepository;
  2.  
  3. private boolean logined;
  4.  
  5. @Autowired
  6. public UserServiceImpl(UserRepository userRepository) {
  7. this.userRepository = userRepository;
  8. }
  9.  
  10.  
  11. public boolean login(String name, String password)
  12. {
  13. User user = userRepository.findOne(name);
  14. if(user == null)
  15. {
  16. return false;
  17. }
  18. boolean result = user.getPassword().equals(password);
  19. logined = result;
  20. return logined;
  21. }
  22.  
  23. public void logout()
  24. {
  25. logined = false;
  26. }
  27.  
  28. public boolean isLogined() {
  29. return logined;
  30. }
  31.  
  32. boolean login(String name, String password);
  33.  
  34. void logout();
  35.  
  36. boolean isLogined();
  37.  
  38. List<News> findAllNews();
  39.  
  40. @Id
  41. private String name;
  42.  
  43. private String password;
  44.  
  45. public String getName() {
  46. return name;
  47. }
  48.  
  49. public void setName(String name) {
  50. this.name = name;
  51. }
  52.  
  53. public String getPassword() {
  54. return password;
  55. }
  56.  
  57. public void setPassword(String password) {
  58. this.password = password;
  59. }
  60.  
  61. private long id;
  62. private String title;
  63. private String text;
  64.  
  65. @Id
  66. public long getId() {
  67. return id;
  68. }
  69.  
  70. public void setId(long id) {
  71. this.id = id;
  72. }
  73.  
  74. public String getTitle() {
  75. return title;
  76. }
  77.  
  78. public void setTitle(String title) {
  79. this.title = title;
  80. }
  81.  
  82. public String getText() {
  83. return text;
  84. }
  85.  
  86. public void setText(String text) {
  87. this.text = text;
  88. }
  89.  
  90. @Autowired
  91. private NewsRepository rep;
  92.  
  93. @RequestMapping("/news")
  94. public @ResponseBody
  95. java.util.List<News> index()
  96. {
  97. return rep.findAllNews();
  98. }
  99.  
  100. @Autowired
  101. private UserService userService;
  102.  
  103. @RequestMapping("/**")
  104. public Object index()
  105. {
  106. return new Error("no access");
  107. }
  108.  
  109. @RequestMapping("/rest/login")
  110. public Object login(@RequestParam("username") String username, @RequestParam("password") String password) {
  111.  
  112. String response;
  113.  
  114. if(userService.login(username, password))
  115. {
  116. response = Utitlity.constructJSON("login",true);
  117. return response;
  118. }
  119. return new Error("auth failed");
  120. }
  121.  
  122. @RequestMapping("/rest/logout")
  123. public Object logout() {
  124.  
  125. if(!userService.isLogined()){
  126. return new Error("no logined");
  127. }
  128. userService.logout();
  129. return new Response("loggedout");
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement