Advertisement
Guest User

Untitled

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