Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Storage, LocalStorage} from 'ionic-angular';
- import {Inject} from 'angular2/core';
- import {Http} from 'angular2/http';
- import 'rxjs/add/operator/map';
- export class DAOLogin {
- static get parameters() {
- return [[Http]];
- }
- constructor(http) {
- this.http = http;
- // var url = 'http://api.themoviedb.org/3/search/movie?query=&query=' + encodeURI('titanic') + '&api_key=5fbddf6b517048e25bc3ac1bbeafb919';
- // this.http.get(url).map(res => res.json());
- }
- login(obj) {
- var username = obj.username;
- var password = obj.password;
- var creds = "username=" + username + "&password=" + password;
- var headers = new Headers();
- headers.append('Content-Type', 'application/x-www-form-urlencoded');
- this.http.post('http://localhost:3001/sessions/create', creds, {
- headers: headers
- })
- .map(res => res.json())
- .subscribe(
- data => this.saveJwt(data.id_token),
- err => this.logError(err),
- () => console.log('Authentication Complete')
- );
- // var body = "username=" + obj.username + "&password=" + obj.password;
- // var headers = new Headers();
- // headers.append('Content-Type', 'application/x-www-form-urlencoded');
- // this.http
- // .post('http://localhost:3001/sessions/create',
- // body, {
- // headers: headers
- // })
- // .map(response => response.json())
- // .subscribe(
- // response => this.storeToken(response.id_token),
- // this.logError,
- // () => console.log('Authentication Complete')
- // );
- }
- // login(obj) {
- // console.log('entrou - username: '+obj.username+', password:'+obj.password);
- // }
- // setTokenLocalStorage(token) {
- // this.local = new Storage(LocalStorage);
- // this.local.get('token').then((result) => {
- // if(!result){
- // this.local.set('token', token);
- // console.log('token criado em local storage: token => '+ token);
- // }
- // });
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement