<commit_before>import { Component } from '@angular/core';
import { NavController, NavParams, AlertController, LoadingController } from 'ionic-angular';
import { MykiProvider } from '../../providers/myki';
import { SavedLoginProvider } from '../../providers/saved-login';
import { LoadCardsPage } from '../load-cards/load-cards';

@Component({
  selector: 'page-login',
  templateUrl: 'login.html'
})
export class LoginPage {

  username = "";
  password = "";
  autologin = true;

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public alertCtrl: AlertController,
    public mykiProvider: MykiProvider,
    public savedLoginProvider: SavedLoginProvider,
    public loadingCtrl: LoadingController
  ) {
  }

  ionViewDidLoad() {
    // get saved login details
    this.savedLoginProvider.get().then(
      result => {

        // check if we have any stored login information
        if (!result[0] || !result[1]) {
          // show login
          this.autologin = false;

          // early exit
          return;
        }

        // login
        this.mykiProvider.login(result[0], result[1]).then(() =>
          this.goToLoadCards()
        ).catch(() => {
          // show error
          let alert = this.alertCtrl.create({
            title: 'Saved login invalid',
            subTitle: 'Could not log in with your saved login details. Please re-enter your username and password.',
            buttons: ['OK']
          })
          alert.present()

          // show login form
          this.autologin = false
        })
      })
  }

  logIn() {
    // check if username and password filled
    if (!this.username || !this.password) {
      let alert = this.alertCtrl.create({
        title: 'Username and password required',
        buttons: ['OK']
      })
      alert.present()
      return;
    }

    let loading = this.loadingCtrl.create({
      content: 'Logging in...'
    });

    loading.present()
<commit_msg>Handle keyboard enter on login fields<commit_after>import { Component } from '@angular/core';
import { NavController, NavParams, AlertController, LoadingController } from 'ionic-angular';
import { MykiProvider } from '../../providers/myki';
import { SavedLoginProvider } from '../../providers/saved-login';
import { LoadCardsPage } from '../load-cards/load-cards';
import * as $ from "jquery";

@Component({
  selector: 'page-login',
  templateUrl: 'login.html'
})
export class LoginPage {

  username = "";
  password = "";
  autologin = true;

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public alertCtrl: AlertController,
    public mykiProvider: MykiProvider,
    public savedLoginProvider: SavedLoginProvider,
    public loadingCtrl: LoadingController
  ) {
  }

  ionViewDidLoad() {
    // get saved login details
    this.savedLoginProvider.get().then(
      result => {

        // check if we have any stored login information
        if (!result[0] || !result[1]) {
          // show login
          this.autologin = false;

          // early exit
          return;
        }

        // login
        this.mykiProvider.login(result[0], result[1]).then(() =>
          this.goToLoadCards()
        ).catch(() => {
          // show error
          let alert = this.alertCtrl.create({
            title: 'Saved login invalid',
            subTitle: 'Could not log in with your saved login details. Please re-enter your username and password.',
            buttons: ['OK']
          })
          alert.present()

          // show login form
          this.autologin = false
        })
      })

    // handle login username ENTER behavior
    $("input[name=username]").on('keydown', (e) => {
      if (e.which == 13) {
        // focus to password
        $("input[name=password]").focus()
      }
    })

    // handle login password ENTER behavior
    $("input[name=password]").on('keydown', (e) => {
      if (e.which == 13) {
        // submit log in
        this.logIn()
      }
    })
  }

  logIn() {
    // check if username and password filled
    if (!this.username || !this.password) {
      let alert = this.alertCtrl.create({
        title: 'Username and password required',
        buttons: ['OK']
      })
      alert.present()
      return;
    }

    let loading = this.loadingCtrl.create({
      content: 'Logging in...'
    });

    loading.present()

{'fraction_non_alphanumeric': 0.13125568698817106, 'fraction_numerical': 0.00272975432211101, 'mean_word_length': 2.1816208393632417, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1041060', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1208, 'n_words': 329}