Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. export default class SecurityService {
  2. constructor($q, $http, $window) {
  3. "ngInject";
  4. this.$q = $q;
  5. this.$http = $http;
  6. this.$window = $window;
  7.  
  8. this.currentUser = this.$window.sessionStorage["currentUser"] || {};
  9. this.allUsers = [];
  10. }
  11.  
  12. logIn(username, password) {
  13. // console.log("im here");
  14. return this.$http.get("http://localhost:49889/api/account/login", {params: {username, password}})
  15. .then(response => {
  16. console.log(response);
  17. this.currentUser = response.data;
  18. this.$window.sessionStorage["currentUser"] = JSON.stringify(this.currentUser);
  19. })
  20. .catch(error => console.log(error));
  21. }
  22.  
  23. //this.$http.get("localhost:49889/api/account/login?username="+username+"&password="+password)
  24. //this.$http.get("localhost:8080/api/account/login?username="+username+"&password="+password)
  25. //this.$http.get("/api/account/login?username="+username+"&password="+password)
  26. //this.$http.get("api/account/login?username="+username+"&password="+password)
  27. //this.$http.get("http://localhost:49889/api/account/login", {username,password})
  28. //this.$http.get("http://localhost:8080/api/account/login", {username,password})
  29. isAuthenticated() {
  30. // console.log(this.currentUser)
  31. // return !!this.currentUser.Username;
  32. return true;
  33. }
  34.  
  35. getAllUsers() {
  36. console.log("service getAllusers");
  37. return this.$http.get("http://localhost:49889/api/account/getAllUsers")
  38. .then(response => {
  39. console.log("in then la getAllUsers");
  40. this.allUsers = response.data;
  41. })
  42. .catch(error => console.log("Eroare getAllUsers", error));
  43. }
  44.  
  45. getUserRoles(id_user) {
  46. console.log("service getUserRoles");
  47. return this.$http.get("http://localhost:49889/api/userRole/getUserRoles", {params: {id_user}})
  48. .then(response => {
  49. this.allRoles = {id: id_user, data: response.data};
  50. })
  51. .catch(error => console.log("Eroare getUserRoles", error));
  52. }
  53.  
  54. setUserRoles(id_user, roles) {
  55. console.log("service setUserRoles", id_user + " " + roles);
  56. return this.$http.get("http://localhost:49889/api/userRole/setUserRoles", {
  57. params: {
  58. id_user: id_user,
  59. roles: roles.toString()
  60. }
  61. })
  62. .then(response => {
  63. console.log("setUserRoles", response);
  64. })
  65. .catch(error => console.log("Eroare setUserRoles", error));
  66. }
  67.  
  68. logOut() {
  69. this.currentUser = {};
  70. this.$window.sessionStorage["currentUser"] = null;
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement