Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Angular */
- import { Injectable } from '@angular/core';
- import { NavController, LoadingController, AlertController, Events } from 'ionic-angular';
- import { BackgroundMode } from '@ionic-native/background-mode';
- import { Http, RequestOptions, Headers } from '@angular/http';
- import { UrlBase } from '../models/UrlBase';
- import { Storage } from '@ionic/storage';
- @Injectable()
- export class AuthService {
- header = new Headers();
- options = new RequestOptions();
- public token = "";
- constructor(private events : Events, private storage : Storage, private http : Http, private backgroundMode: BackgroundMode ) {
- this.header.append('Content-Type', 'application/x-www-form-urlencoded');
- this.options = new RequestOptions({
- headers: this.header,
- });
- }
- verifyConnection(url){
- return this.http.get("http://" + url + ":8085/api/Core/VerifyConnectionPsiu");
- };
- authenticate(request, url){
- let urlFull = "http://" + url + ':8085/token';
- let data = "grant_type=password&username=" + request.Username + "&password=" + request.Password;
- return this.http.post(urlFull, data, this.options);
- }
- public userIsLogged(){
- return this.authInfo().then((data)=>{
- if(data !== undefined && data !== null){
- this.setToken(data.token);
- return true;
- }else{
- return false;
- }
- });
- }
- public authInfo(){
- return this.storage.get('authInfo');
- }
- public logout(){
- return this.storage.remove('authInfo').then(()=>{
- this.events.publish('logout');
- });
- }
- public setToken(token){
- this.token = token;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement