<commit_before>import { Component, OnDestroy, OnInit } from '@angular/core';
import { environment } from 'app-environment';

import { AppAuthentication, AppNavigator, ILoginError, ILoginResponse } from 'app-shared/kmc-shell';
import { BrowserService } from 'app-shared/kmc-shell';
import { TranslateService } from 'ng2-translate';
import { Observable } from 'rxjs/Observable';

export enum LoginScreens {
  Login,
  ForgotPassword,
  PasswordExpired,
  InvalidLoginHash
}

@Component({
  selector: 'kKMCLogin',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit, OnDestroy {
  public _username: string;
  public _errorMessage: string;
  public _errorCode: string;
  public _inProgress = false;
  public _showLogin = false;
  public _loginScreens = LoginScreens;
  public _currentScreen = LoginScreens.Login;
  public _passwordReset = false;

  constructor(private _appAuthentication: AppAuthentication,
              private _appNavigator: AppNavigator,
              private _translate: TranslateService,
              private _browserService: BrowserService) {

  }

  private _makeLoginRequest(username: string, password: string): Observable<ILoginResponse> {
    return this._appAuthentication.login(username, password, {
      privileges: environment.core.kaltura.privileges,
      expiry: environment.core.kaltura.expiry
    }).cancelOnDestroy(this);
  }

  private _handleLoginResponse(success: boolean, error: ILoginError, username: string): void {
    if (success) {
      this._appNavigator.navigateToDefault();
      return;
    }

    this._errorCode = error.code;

    if (error.passwordExpired) {
      this._username = username;
      return this._setScreen(LoginScreens.PasswordExpired);
    }

    if (!error.custom) {
      this._translate.get(error.message).subscribe(message => {
        this._errorMessage = message;
      });
    } else {
      this._errorMessage = error.message;
    }
  }

  ngOnInit() {
    if (this._appAuthentication.isLogged()) {
      this._appNavigator.navigateToDefault();
    } else {
      this._showLogin = true;
      this._username = this._browserService.getFromLocalStorage('login.username');
    }
  }

  ngOnDestroy() {
    // for cancelOnDestroy
  }

  public _login({ username, password }: { username: string, password: string }): void {
    this._errorMessage = '';
    this._inProgress = true;

    this._makeLoginRequest(username, password).subscribe(
      ({ success, error }) => {
        this._inProgress = false;
        this._handleLoginResponse(success, error, username);
      },
      (err) => {
        this._errorMessage = err.message;
        this._inProgress = false;
      }
    );
  }<commit_msg>fix(login): keep login button disabled during login process<commit_after>import { Component, OnDestroy, OnInit } from '@angular/core';
import { environment } from 'app-environment';

import { AppAuthentication, AppNavigator, ILoginError, ILoginResponse } from 'app-shared/kmc-shell';
import { BrowserService } from 'app-shared/kmc-shell';
import { TranslateService } from 'ng2-translate';
import { Observable } from 'rxjs/Observable';

export enum LoginScreens {
  Login,
  ForgotPassword,
  PasswordExpired,
  InvalidLoginHash
}

@Component({
  selector: 'kKMCLogin',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit, OnDestroy {
  public _username: string;
  public _errorMessage: string;
  public _errorCode: string;
  public _inProgress = false;
  public _showLogin = false;
  public _loginScreens = LoginScreens;
  public _currentScreen = LoginScreens.Login;
  public _passwordReset = false;

  constructor(private _appAuthentication: AppAuthentication,
              private _appNavigator: AppNavigator,
              private _translate: TranslateService,
              private _browserService: BrowserService) {

  }

  private _makeLoginRequest(username: string, password: string): Observable<ILoginResponse> {
    return this._appAuthentication.login(username, password, {
      privileges: environment.core.kaltura.privileges,
      expiry: environment.core.kaltura.expiry
    }).cancelOnDestroy(this);
  }

  private _handleLoginResponse(success: boolean, error: ILoginError, username: string): void {
    if (success) {
      this._appNavigator.navigateToDefault();
      return;
    }

    this._errorCode = error.code;

    if (error.passwordExpired) {
      this._username = username;
      return this._setScreen(LoginScreens.PasswordExpired);
    }

    if (!error.custom) {
      this._translate.get(error.message).subscribe(message => {
        this._errorMessage = message;
      });
    } else {
      this._errorMessage = error.message;
    }
    this._inProgress = false;
  }

  ngOnInit() {
    if (this._appAuthentication.isLogged()) {
      this._appNavigator.navigateToDefault();
    } else {
      this._showLogin = true;
      this._username = this._browserService.getFromLocalStorage('login.username');
    }
  }

  ngOnDestroy() {
    // for cancelOnDestroy
  }

  public _login({ username, password }: { username: string, password: string }): void {
    this._errorMessage = '';
    this._inProgress = true;

    this._makeLoginRequest(username, password).subscribe(
      ({ success, error }) => {
        this._handleLoginResponse(success, error, username);
      },
      (err) => {
        this._errorMessage = err.message;
        this._inProgress = false;
      }
    );
  }
{'fraction_non_alphanumeric': 0.11093073593073594, 'fraction_numerical': 0.00036075036075036075, 'mean_word_length': 3.457395498392283, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '7048684', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1583, 'n_words': 337}