postData(data){
   let headers = new Headers();
   headers.append('Content-Type', 'application/x-www-form-urlencoded');
   console.log("called get req")
   let httpGetPromise = new Promise((resolve, reject) => {
     console.log("called get req")
     this._http.post('/', data, {headers: headers})
       .map(res => res.json())
       .subscribe(
         data => {
           console.log("data from promise: ", data)
           resolve(data)
         },
         err => reject(err),
         () => console.log('data recieved')
         )
       })
   return httpGetPromise
 }
  onRegister(): void {
	var data = "korisnicko_ime="+this.registerForm.value.korisnicko_ime+"&sifra="+this.registerForm.value.sifra+"&email="+this.registerForm.value.email;
	var headers = new Headers();
	headers.append('Content-Type', 'application/x-www-form-urlencoded');
	this.http.post('http://localhost/it255/php/registracija.php',data, {headers:headers})
    .map(res => res)
    .subscribe( data => this.postResponse = data,
	err => alert(JSON.stringify(err)),
	() => {
	 if(this.postResponse._body == "ok"){
	 alert("Uspesna registracija");
	    this.router.parent.navigate(['./app']);
	 }else{
		alert("Neuspesna registracija");
	 }
	 }
	);

  }
Example #3
0
  login(user: User) {
    var headers = new Headers();
    headers.append("Content-Type", "application/json");

    return this._http.post(
      Config.apiUrl + "oauth/token",
      JSON.stringify({
        username: user.email,
        password: user.password,
        grant_type: "password"
      }),
      { headers: headers }
    )
    .map(response => response.json())
    .do(data => {
      Config.token = data.Result.access_token;
    })
    .catch(this.handleErrors);
  }
 onAddRoom(): void {
	var data = "newRoomName="+this.signupForm.value.newRoomName+"&tv="+this.signupForm.value.tv+"&beds="+this.signupForm.value.beds+"&kvadratura="+this.signupForm.value.kvadratura;
	var headers = new Headers();
	headers.append('Content-Type', 'application/x-www-form-urlencoded');
	this.http.post('http://localhost/php/addroom.php',data, {headers:headers})
    .map(res => res)
    .subscribe( data => this.postResponse = data,
	err => alert(JSON.stringify(err)),
	() => { 
	 if(this.postResponse._body.indexOf("error") === -1){
		alert("Uspesno dodavanje sobe");
	    this.router.parent.navigate(['./Home']);
	 }else{
		alert("Neuspesno dodavanje sobe");
	 }
	 }
	);
	
  }
 signin(username:string, password:string) {      
     var creds = "username=" + username + "&password=" + password;
     
     var headers = new Headers();
     headers.append('Content-Type', 'application/x-www-form-urlencoded');
 
     this.http.post('http://localhost:8080/account/token', creds, {
         headers: headers
     })
     .map(res => res.json())
     .subscribe(
         data => { 
             this.saveJwt(data.access_token);
             this._router.navigate(['Dashboard']);
         },
         err => console.error(err),
         () => console.log('Authentication Complete')
     );
 }
Example #6
0
    public sendNotification(RestaurantEmail:string, TableNr:string) {


        let parameters = JSON.stringify({
            restaurant: RestaurantEmail,
            tableNr: TableNr
        });


        let header:Headers = new Headers();

        header.append('Content-Type', 'application/json');
        header.append('AnonymousToken', ConfigBackand.anonymous_token);

        return this.http.get(ConfigBackand.api_url + '1/objects/action/Order/?name=SendRealtimeEvent&parameters=' + encodeURI(parameters), {headers: header})
            .map(res => res.json())


    }
Example #7
0
    public getTables(restaurantId) {

        if (restaurantId != null || restaurantId != "") {
            let filter = JSON.stringify([{"fieldName": "RestaurantId", "operator": "equals", "value": restaurantId}]);

            let header:Headers = new Headers();

            header.append('AnonymousToken', ConfigBackand.anonymous_token);

            return this.http.get(ConfigBackand.api_url + '1/objects/Tables?filter=' + encodeURI(filter), {
                headers: header
            })
                .retry(3)
                .map(res => res.json().data.map(r => r))
        }
        else {

        }
    }
Example #8
0
	/**
  *
	* @method
	* @name Courses_GetCourses
	* @param {string} q - 
	* 
	*/
	public Courses_GetCourses(q: string) {
		let payload = {};	
		let queryParameters = new URLSearchParams();
		let headers = new Headers();
		headers.append('Content-Type', 'application/json');
		
      
		if(q !== undefined){
			queryParameters.set('q', q);
		}
			
		let uri = `/api/courses`;
	  
		return this.http
			.get(this.domain + uri, { headers: headers, search: queryParameters })
			.map((res: Response) => {
        return res;
      });
	}
Example #9
0
    save() {
        var headers = new Headers();
        headers.append('Content-Type', 'application/json');

        var _this = this;
        this.loading = true;
        var json = JSON.stringify(this.catToEdit);
        console.log(json);
        _this._http.post('/api/Category', json,
            { headers: headers }).map(r => r.json()).subscribe(x => {
                _this.loading = true;
                _this.load();
            },
            error => {
                _this._errorHandler.handleError(error);
                _this.loading = false;
            });

    }
Example #10
0
 public login(user: User): Observable<Response>{
     var headers = new Headers();
     headers.append('Content-Type', 'application/json');
     
     return this._http.post(
         Config.apiUrl + 'oauth/token',
         JSON.stringify({
             username: user.email,
             password: user.password,
             grant_type: 'password'
         }),
         { headers: headers }
     )
     .map(response => response.json())
     .do(data => {
         Config.token = data.Result.access_token;
     })
     .catch(this.handleErrors);
 }
Example #11
0
    public addOrder(RestaurantEmail:string, TableNumber:string, orders:any) {


        let header:Headers = new Headers();

        header.append('Content-Type', 'application/json');
        header.append('AnonymousToken', ConfigBackand.anonymous_token);


        let order_details = {
            RestaurantEmail: RestaurantEmail,
            TableNumber: TableNumber,
            Processing: false,
            Done: false
        }

        return this.http.post(ConfigBackand.api_url + "1/objects/Order", JSON.stringify(order_details), {headers: header})

            .map(res => res.json().__metadata.id)


            .map(orderId => {
                orders.map(product => {

                    let order_product = {
                        ProductId: product.id,
                        Quantity: 1,
                        OrdersId: orderId
                    };

                    console.log(order_product)

                    this.http.post(ConfigBackand.api_url + "1/objects/OrdersProducts", JSON.stringify(order_product), {headers: header})
                        .subscribe();
                });

                return 'done'

            })


    }
Example #12
0
    /**update a question*/
    public update(entity:T, onComplete?:() => void) {
        var headers:Headers = SecurityUtils.tokenHeaders();
        headers.append('Content-Type', 'application/json');

        this.http.patch(BaseService.getServerUrl() + this.getUrl()+"/"+this.getId(entity), JSON.stringify(entity), {
                headers: this.getSecurityHeaders()
            })
            .map(res => res.json())
            .subscribe(
                data => console.log('data = ' + data),
                err => console.log(err),
                () => {
                    console.log('Patch complete');
                    if (onComplete) {
                        onComplete();
                    };
                }
            );
        console.log('Question saved');
    }
Example #13
0
  login(event, username, password) {
    event.preventDefault();
    let authHeader = new Headers();
    let encodedUsernamePassword = btoa(username + ':' + password);

    authHeader.append('Authorization', 'Basic ' + encodedUsernamePassword);
    //TODO: Fix response to match what is returned on rest client, save user on local storage
    this.http.get('https://jira.platform.dev.sdt.ericsson.se/rest/api/2/user/search?username=' +
      username, { headers: authHeader })
        .subscribe(
            response => {
              localStorage.setItem('credentials', encodedUsernamePassword);
              this._router.navigate(['Home']);
          },
          error => {
            //TODO: Display errors on log in page
            console.log('error ' + error.text());
          }
        );
  }
Example #14
0
 onAddRoom(): void {
     var data =
         "roomName="+this.registerForm.value.roomName+"&hasTV="+this.registerForm.value.hasTV+"&beds="
         +this.registerForm.value.beds;
     var headers = new Headers();
     headers.append('Content-Type', 'application/x-www-form-urlencoded');
     this.http.post('http://localhost/php/addroomservice.php',data, {headers:headers})
         .map(res => res)
         .subscribe( data => this.postResponse = data,
             err => alert(JSON.stringify(err)),
             () => {
                 if(this.postResponse._body == "ok"){
                     alert("Uspesno dodavanje sobe");
                     this.router.parent.navigate(['./MainPage']);
                 }else{
                     alert("Neuspesno dodavanje sobe");
                 }
             }
         );
 }
	doLogin() {
		// post data naar reqres.in API
		let url  = 'http://reqres.in/api/login';
		let data = {
			"email"   : this.email,
			"password": this.password
		};

		let headers = new Headers();
		headers.append('Content-Type', 'application/json');

		this.http.post(url, JSON.stringify(data),
			{ headers : headers})
			.map(res => res.json())
			.subscribe(res => this.response = res,
				err => console.log('FOUT:', err),
				() => console.log('Login complete')
			);
		this.email = this.password = '';
	}
Example #16
0
  checkBalance() {
    let header = new Headers();
    header.append('Authorization', this._authJwtToken.getToken());

    return new Promise<boolean>((resolve, reject) => {
      oboe({
        url     : CONFIG.hostName + '/api_v1/user/balance',
        method  : 'GET',
        headers : header
      })
      .done(user => {
        if (user.data) {
          resolve(user);
        }
      })
      .fail(error => {
        reject(error);
      });
    })
  }
    getMapping(config) {
        var headers = new Headers({ 'withCredentials': 'true' });
        headers.append('Authorization', "Basic " + btoa(config.username + ':' + config.username));
        
        var options = new RequestOptions( { headers: headers});
        
        return this.http.get(config.url +'/'+config.appname + '/_mapping', options)
                    .map((res: Response) => res.json())
                    .catch(this.handleError);

        // return Observable.fromPromise($.ajax({
        //     type: 'GET',
        //         beforeSend: function(request) {
        //             request.setRequestHeader("Authorization", "Basic " + btoa(config.username + ':' + config.password));
        //             },
        //         url: config.url+'/'+config.appname+'/_mapping',
        //         xhrFields: {
        //                 withCredentials: true
        //         })).map(this.mapper);                    
    }
Example #18
0
 login(user) {
     var headers = new Headers();
     var creds = "name=" + user.email + "&password=" + user.password;
     headers.append('Content-Type', 'application/x-www-form-urlencoded');
     
     return new Promise(resolve => {
     
         this.http.post('http://localhost:8000/api/authenticate', creds, {headers: headers}).subscribe(data => {
         
         if(data.json().success){
             window.localStorage.setItem('raja', data.json().token);
         this.isLoggedin = true; }   
         resolve(this.isLoggedin);
             
     }); 
         
     });
     
     
 }
Example #19
0
    submitInfo(a, b){
        let url = 'http://localhost:8000/api/auth?email='+a+'&password='+b;
        console.log(url);
        var headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');

        var creds = "email=" + a + "&password=" + b;

        this.http.post(url, creds, {
                headers: headers
            })
            .subscribe(
                data => {
                    localStorage.setItem('jwt', data.json().token);
                    this.router.parent.navigateByUrl("/home");
                },
                err => console.log(err)

            );
    };
  getTransactions() {
    this.transactions = [];

    let headers = new Headers();
    headers.append('Content-Type', 'application/json');
    headers.append('Access-Control-Allow-Origin', '*');
    headers.append('sessionId', this._globalService.sessionId);

    this.http.get('http://localhost:8080/ds-finance-bank-web/customertrans?ID=' + this._globalService.getEffectiveCustomer(), {
          headers: headers
        })
        .subscribe(
            data => {
              this.transactions = JSON.parse(data._body);
              this.effectiveTransactions = this.transactions;
            },
            err => console.log('ERROR')
        );
    return this.transactions;
  }
Example #21
0
  transferBalancePT(amount, gameType, bankType) {
    let header = new Headers();
    header.append('Authorization', this._authJwtToken.getToken());

    return new Promise<boolean>((resolve, reject) => {
      oboe({
        url     : CONFIG.hostName + '/api_v1/user/transfer/balance/PT/' + gameType + '?amount=' + amount + '&bankType=' + bankType,
        method  : 'GET',
        headers : header
      })
      .done(user => {
        if (user.data) {
          resolve(user);
        }
      })
      .fail(error => {
        reject(error);
      });
    })
  }
Example #22
0
  gameLauncher(provider) {
    let header = new Headers();
    header.append('Authorization', this._authJwtToken.getToken());

    return new Promise<boolean>((resolve, reject) => {
      oboe({
        url     : CONFIG.hostName + '/api_v1/user/launch/game/' + provider,
        method  : 'POST',
        headers : header
      })
      .done(user => {
        if (user.data) {
          resolve(user);
        }
      })
      .fail(error => {
        reject(error);
      });
    });
  }
Example #23
0
    save() {
        var headers = new Headers();
        headers.append('Content-Type', 'application/json');

        var _this = this;
        this.loading = true;
        var json = JSON.stringify(this.editingPlaylist );
        
        _this._http.post('/api/SavePlayList', json,
            { headers: headers }).map(r => r.json()).subscribe(x => {
                _this.editingPlaylist.id = x;
                _this.loading = true;
                _this.load();
                
            },
            error => {
                _this._errorHandler.handleError(error);
                _this.loading = true;
            });
    }
Example #24
0
  authenticate(username, password) {

    let creds = JSON.stringify({ username: username.value, password: password.value });

    let headers = new Headers();
    headers.append('Content-Type', 'application/json');

    this.http.post('http://localhost:3005/sessions/create', creds, {
      headers: headers
      })
      .subscribe(
        data => {
          this.saveJwt(data.json().id_token);
          username.value = null;
          password.value = null;
        },
        err => this.logError(err.json().message),
        () => console.log('Authentication Complete')
      );
  }
    onLogin(): void {
        var data = "username=" + this.loginForm.value.username + "&password=" + this.loginForm.value.password;
        var headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');
        this.http.post('http://localhost/it255-dz12-luka-kotur-2399/php/login.php', data, { headers: headers })
            .map(res => res)
            .subscribe(data => this.postResponse = data,
            err => {
                var obj = JSON.parse(err._body);
                document.getElementsByClassName("alert")[0].style.display = "block";
                document.getElementsByClassName("alert")[0].innerHTML = obj.error.split("\\r\\n").join("<br/>").split("\"").join("");
            },
            () => {
                var obj = JSON.parse(this.postResponse._body);
                localStorage.setItem('token', obj.token);
                this.router.parent.navigate(['./Home']);
            }
            );

    }
Example #26
0
    public getTrip(tripRequest:TripRequest) {
        const API_KEY = 'AIzaSyCgILgw9s6w_9zPNTTyXN1w6x_9zKsrFEU';
        const URL = 'https://www.googleapis.com/qpxExpress/v1/trips/search';

        let body = JSON.stringify(tripRequest);

        let headers = new Headers();
        headers.set('Content-Type', 'application/json; charset=utf-8');

        let search = new URLSearchParams();
        search.set('key', API_KEY);

        return this._http
            .post(URL, '', {
                headers: headers,
                search: search,
                body: body,
            })
            .map((res:Response) => res.json());
    }
Example #27
0
 this._authenticationService.getToken().then(token => {
   let headers = new Headers()
   headers.append('Content-Type', 'application/json')
   let options = {
     headers : headers
   }
   this._settingsService.getUrl().then(url => {
     let joined = this._utilsService.pathJoin([
       url, path
     ])
     this._http.post(joined, body, options)
       .subscribe(
         data => {
           resolve(data.json())
         }, error => {
           reject(this.handleError(error))
         }
       )
   })
 })
	postData(posturl, data) {
		let url = posturl;
		let datatobepost = data;
		let headers = new Headers();
		headers.append('Content-Type', 'application/x-www-form-urlencoded');
		return new Promise(resolve => {
			this.http.post(url, datatobepost, {
				headers: headers
			})
				.map(res => res.json())
				.subscribe(
				data => {
					resolve(data);
				},
				err => {
					resolve('Error');
				}
				);
		});
	}
    update(model: Object) {
        console.log(`PUT: ${this._getBase()}`);

        var params = new URLSearchParams();
        params.set('token', this.jwt);

        var headers = new Headers();
        headers.append('Content-Type', 'application/json');

        var body: any = {};
        body[this.type] = model;
        var bodyString = JSON.stringify(body);

        this.http.put(this._getBase(), bodyString, {search: params, headers: headers})
            .subscribe(
                //data => this.randomQuote = data,
                err => this._logError(err),
                () => console.log('Update Complete')
            );
    }
Example #30
0
    private onLoginButton(event) {
        var objectToSend = JSON.stringify(this.loginForm.value);

        var headers = new Headers();
        headers.append('Content-Type', 'application/json');
        this.http.post('http://localhost:64347/api/Login', objectToSend, { headers: headers })
            .subscribe(res => {
                var data = JSON.parse(res.json());
                console.log(data);
                console.log("~~~~~~~~");
                console.log(data.Value);
                localStorage.setItem("dramazonToken", data.Value);
                localStorage.setItem("dramazonAlias", data.User.Alias);

                console.log("Local storage: " + localStorage.getItem("dramazonToken"));
                location.reload();
            });

        event.preventDefault();
    }