<commit_before>import { Component, View, Inject, CORE_DIRECTIVES, FORM_DIRECTIVES, ControlGroup, FormBuilder, Validators } from 'angular2/angular2';
import { Router, RouteParams, RouterLink } from 'angular2/router';
import { MindsTitle } from '../../../services/ux/title';
import { Material } from '../../../directives/material';
import { Client } from '../../../services/api';
import { SessionFactory } from '../../../services/session';
import { Register } from '../register/register';

@Component({
  selector: 'minds-login',
  viewBindings: [ Client ],
  bindings: [ MindsTitle ]
})
@View({
  templateUrl: 'src/controllers/home/login/login.html',
  directives: [ CORE_DIRECTIVES, FORM_DIRECTIVES, Material, Register, RouterLink]
})

export class Login {

	session = SessionFactory.build();
  errorMessage : string = "";
  twofactorToken : string = "";
  hideLogin : boolean = false;
  inProgress : boolean = false;
  referrer : string;

  form : ControlGroup;

	constructor(public client : Client, public router: Router, public params: RouteParams, public title: MindsTitle, fb: FormBuilder){
		if(this.session.isLoggedIn())
      router.navigate(['/Newsfeed']);

    this.title.setTitle("Login");

    this.form = fb.group({
      username: ['', Validators.required],
      password: ['', Validators.required]
    });

    if(params.params['referrer'])
      this.referrer = params.params['referrer'];
	}

	login(){
    this.errorMessage = "";
    this.inProgress = true;
		var self = this; //this <=> that for promises
		this.client.post('api/v1/authenticate', {username: this.form.value.username, password: this.form.value.password})
			.then((data : any) => {
				this.form.value = null;
        this.inProgress = false;
				self.session.login(data.user);
        if(this.referrer)
          self.router.navigateByUrl(this.referrer);
        else
				  self.router.navigate(['/Newsfeed', {}]);
			})
			.catch((e) => {

        this.inProgress = false;
        if(e.status == 'failed'){
          //incorrect login details
          self.errorMessage = "Incorrect username/password. Please try again.";
          self.session.logout();
        }

        if(e.status == 'error'){
          //two factor?
          self.twofactorToken = e.message;
          self.hideLogin = true;
        }<commit_msg>(fix): prevents doulbe login sending out multiple two factor keys<commit_after>import { Component, View, Inject, CORE_DIRECTIVES, FORM_DIRECTIVES, ControlGroup, FormBuilder, Validators } from 'angular2/angular2';
import { Router, RouteParams, RouterLink } from 'angular2/router';
import { MindsTitle } from '../../../services/ux/title';
import { Material } from '../../../directives/material';
import { Client } from '../../../services/api';
import { SessionFactory } from '../../../services/session';
import { Register } from '../register/register';

@Component({
  selector: 'minds-login',
  viewBindings: [ Client ],
  bindings: [ MindsTitle ]
})
@View({
  templateUrl: 'src/controllers/home/login/login.html',
  directives: [ CORE_DIRECTIVES, FORM_DIRECTIVES, Material, Register, RouterLink]
})

export class Login {

	session = SessionFactory.build();
  errorMessage : string = "";
  twofactorToken : string = "";
  hideLogin : boolean = false;
  inProgress : boolean = false;
  referrer : string;

  form : ControlGroup;

	constructor(public client : Client, public router: Router, public params: RouteParams, public title: MindsTitle, fb: FormBuilder){
		if(this.session.isLoggedIn())
      router.navigate(['/Newsfeed']);

    this.title.setTitle("Login");

    this.form = fb.group({
      username: ['', Validators.required],
      password: ['', Validators.required]
    });

    if(params.params['referrer'])
      this.referrer = params.params['referrer'];
	}

	login(){
    if(this.inProgress)
      return;

    this.errorMessage = "";
    this.inProgress = true;
		var self = this; //this <=> that for promises
		this.client.post('api/v1/authenticate', {username: this.form.value.username, password: <PASSWORD>})
			.then((data : any) => {
				this.form.value = null;
        this.inProgress = false;
				self.session.login(data.user);
        if(this.referrer)
          self.router.navigateByUrl(this.referrer);
        else
				  self.router.navigate(['/Newsfeed', {}]);
			})
			.catch((e) => {

        this.inProgress = false;
        if(e.status == 'failed'){
          //incorrect login details
          self.errorMessage = "Incorrect username/password. Please try again.";
          self.session.logout();
        }

        if(e.status == 'error'){
          //two factor?
          self.twofactorToken = e.message;
          self.hideLogin = true;
        }
{'fraction_non_alphanumeric': 0.15768165352652888, 'fraction_numerical': 0.0017046665246111229, 'mean_word_length': 3.0361134995700776, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1443989', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1415, 'n_words': 307}