<commit_before>import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, Params, Router} from '@angular/router';

import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/toPromise';
import {Response} from '@angular/http';
import {FacebookService} from './facebook.service';
import {UserService} from '../../user/user.service';
import {Settings} from '../../settings';

@Component({
  template: 'Authenticating...'
})
export class FacebookTokenHandlerComponent implements OnInit {
  constructor(private activatedRoute: ActivatedRoute,
              private router: Router,
              private facebookService: FacebookService,
              private userService: UserService) {}

  ngOnInit(): void {
    this.getFacebookToken();
  }

  private getFacebookToken() {
    this.activatedRoute.queryParams.subscribe((params: Params) => {
      this.facebookService.getToken(params['code'])
        .then(this.getAPIToken.bind(this));
    });
  }

  private getAPIToken(facebookToken: string) {
    this.userService.loginThroughToken(facebookToken, Settings.API_FACEBOOK_BACKEND)
      .then(this.saveAPIToken.bind(this));
  }

  private saveAPIToken(token: string) {
    console.log('Facebook auth successful!', token);
    this.userService.handleLogin(token);
    this.router.navigate(['/']);
  }
}<commit_msg>Don't log user in if API didn't return token<commit_after>import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, Params, Router} from '@angular/router';

import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/toPromise';
import {Response} from '@angular/http';
import {FacebookService} from './facebook.service';
import {UserService} from '../../user/user.service';
import {Settings} from '../../settings';
import {isUndefined} from 'util';

@Component({
  template: 'Authenticating...'
})
export class FacebookTokenHandlerComponent implements OnInit {
  constructor(private activatedRoute: ActivatedRoute,
              private router: Router,
              private facebookService: FacebookService,
              private userService: UserService) {}

  ngOnInit(): void {
    this.getFacebookToken();
  }

  private getFacebookToken() {
    this.activatedRoute.queryParams.subscribe((params: Params) => {
      this.facebookService.getToken(params['code'])
        .then(this.getAPIToken.bind(this));
    });
  }

  private getAPIToken(facebookToken: string) {
    this.userService.loginThroughToken(facebookToken, Settings.API_FACEBOOK_BACKEND)
      .then(this.saveAPIToken.bind(this));
  }

  private saveAPIToken(token: string) {
    if(token != undefined) {
      console.log('Facebook auth successful!', token);
      this.userService.handleLogin(token);
      this.router.navigate(['/']);
    }
    else {
      this.router.navigate(['/login']);
    }
  }
}
{'fraction_non_alphanumeric': 0.140673845085099, 'fraction_numerical': 0.0, 'mean_word_length': 4.026178010471204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4765367', 'n_tokens_mistral': 845, 'n_tokens_neox': 823, 'n_words': 170}