Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default class SecurityService {
- constructor($q, $http, $window) {
- "ngInject";
- this.$q = $q;
- this.$http = $http;
- this.$window = $window;
- this.currentUser = this.$window.sessionStorage["currentUser"] || {};
- this.allUsers = [];
- }
- logIn(username, password) {
- // console.log("im here");
- return this.$http.get("http://localhost:49889/api/account/login", {params: {username, password}})
- .then(response => {
- console.log(response);
- this.currentUser = response.data;
- this.$window.sessionStorage["currentUser"] = JSON.stringify(this.currentUser);
- })
- .catch(error => console.log(error));
- }
- //this.$http.get("localhost:49889/api/account/login?username="+username+"&password="+password)
- //this.$http.get("localhost:8080/api/account/login?username="+username+"&password="+password)
- //this.$http.get("/api/account/login?username="+username+"&password="+password)
- //this.$http.get("api/account/login?username="+username+"&password="+password)
- //this.$http.get("http://localhost:49889/api/account/login", {username,password})
- //this.$http.get("http://localhost:8080/api/account/login", {username,password})
- isAuthenticated() {
- // console.log(this.currentUser)
- // return !!this.currentUser.Username;
- return true;
- }
- getAllUsers() {
- console.log("service getAllusers");
- return this.$http.get("http://localhost:49889/api/account/getAllUsers")
- .then(response => {
- console.log("in then la getAllUsers");
- this.allUsers = response.data;
- })
- .catch(error => console.log("Eroare getAllUsers", error));
- }
- getUserRoles(id_user) {
- console.log("service getUserRoles");
- return this.$http.get("http://localhost:49889/api/userRole/getUserRoles", {params: {id_user}})
- .then(response => {
- this.allRoles = {id: id_user, data: response.data};
- })
- .catch(error => console.log("Eroare getUserRoles", error));
- }
- setUserRoles(id_user, roles) {
- console.log("service setUserRoles", id_user + " " + roles);
- return this.$http.get("http://localhost:49889/api/userRole/setUserRoles", {
- params: {
- id_user: id_user,
- roles: roles.toString()
- }
- })
- .then(response => {
- console.log("setUserRoles", response);
- })
- .catch(error => console.log("Eroare setUserRoles", error));
- }
- logOut() {
- this.currentUser = {};
- this.$window.sessionStorage["currentUser"] = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement