<commit_before>import $ from 'jquery';
import _ from 'underscore';

import View from 'girder/views/View';
import events from 'girder/events';
import { handleClose, handleOpen } from 'girder/dialog';
import { login } from 'girder/auth';
import UserModel from 'girder/models/UserModel';

import LoginDialogTemplate from 'girder/templates/layout/loginDialog.pug';

import 'girder/utilities/jquery/girderEnable';
import 'girder/utilities/jquery/girderModal';

/**
 * This view shows a login modal dialog.
 */
var LoginView = View.extend({
    events: {
        'submit #g-login-form': function (e) {
            e.preventDefault();

            login(this.$('#g-login').val(), this.$('#g-password').val());

            events.once('g:login.success', function () {
                this.$el.modal('hide');
            }, this);

            events.once('g:login.error', function (status, err) {
                this.$('.g-validation-failed-message').text(err.responseJSON.message);
                this.$('#g-login-button').girderEnable(true);
                if (err.responseJSON.extra === 'emailVerification') {
                    var html = err.responseJSON.message +
                        ' <a class="g-send-verification-email">Click here to send verification email.</a>';
                    $('.g-validation-failed-message').html(html);
                }
            }, this);

            this.$('#g-login-button').girderEnable(false);
            this.$('.g-validation-failed-message').text('');
        },<commit_msg>Make the login form more robust to failed logins<commit_after>import $ from 'jquery';
import _ from 'underscore';

import View from 'girder/views/View';
import events from 'girder/events';
import { handleClose, handleOpen } from 'girder/dialog';
import { login } from 'girder/auth';
import UserModel from 'girder/models/UserModel';

import LoginDialogTemplate from 'girder/templates/layout/loginDialog.pug';

import 'girder/utilities/jquery/girderEnable';
import 'girder/utilities/jquery/girderModal';

/**
 * This view shows a login modal dialog.
 */
var LoginView = View.extend({
    events: {
        'submit #g-login-form': function (e) {
            e.preventDefault();

            this.$('#g-login-button').girderEnable(false);
            this.$('.g-validation-failed-message').text('');

            const loginName = this.$('#g-login').val();
            const password = this.$('#g-password').val();
            login(loginName, password)
                .done(() => {
                    this.$el.modal('hide');
                })
                .fail((err) => {
                    this.$('.g-validation-failed-message').text(err.responseJSON.message);

                    if (err.responseJSON.extra === 'emailVerification') {
                        var html = err.responseJSON.message +
                            ' <a class="g-send-verification-email">Click here to send verification email.</a>';
                        $('.g-validation-failed-message').html(html);
                    }
                })
                .always(() => {
                    this.$('#g-login-button').girderEnable(true);
                });
        },
{'fraction_non_alphanumeric': 0.15665303554576912, 'fraction_numerical': 0.0, 'mean_word_length': 2.1547619047619047, 'pattern_counts': {'":': 0, '<': 7, '<?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': '119716', 'n_tokens_mistral': 897, 'n_tokens_neox': 870, 'n_words': 169}