<commit_before>/**
  A modal view for handling user logins

  @class LoginView
  @extends Discourse.ModalBodyView
  @namespace Discourse
  @module Discourse
**/
Discourse.LoginView = Discourse.ModalBodyView.extend({
  templateName: 'modal/login',
  siteBinding: 'Discourse.site',
  title: Em.String.i18n('login.title'),
  authenticate: null,
  loggingIn: false,

  showView: function(view) {
    return this.get('controller').show(view);
  },

  newAccount: function() {
    return this.showView(Discourse.CreateAccountView.create());
  },

  forgotPassword: function() {
    return this.showView(Discourse.ForgotPasswordView.create());
  },

  loginButtonText: (function() {
    if (this.get('loggingIn')) {
      return Em.String.i18n('login.logging_in');
    }
    return Em.String.i18n('login.title');
  }).property('loggingIn'),

  loginDisabled: (function() {
    if (this.get('loggingIn')) {
      return true;
    }
    if (this.blank('loginName') || this.blank('loginPassword')) {
      return true;
    }
    return false;
  }).property('loginName', 'loginPassword', 'loggingIn'),

  login: function() {
    var _this = this;
    this.set('loggingIn', true);
    $.post("/session", {
      login: this.get('loginName'),
      password: this.get('loginPassword')
    }).success(function(result) {
      if (result.error) {
        _this.set('loggingIn', false);
        if( result.reason === 'not_activated' ) {
          return _this.showView(Discourse.NotActivatedView.create({username: _this.get('loginName'), sentTo: result.sent_to_email, currentEmail: result.current_email}));
        }
        _this.flash(result.error, 'error');
      } else {
        // Trigger the browser's password manager using the hidden static login form:
        $('#hidden-login-form input[name=username]').val(_this.get('loginName'));
        $('#hidden-login-form input[name=password]').val(_this.get('loginPassword'));
        $('#hidden-login-form input[name=redirect]').val(window.location.href);
        $('#hidden-login-form').submit();
      }
    }).fail(function(result) {
      _this.flash(Em.String.i18n('login.error'), 'error');
      return _this.set('loggingIn', false);
    });
    return false;
  },

  authMessage: (function() {
    if (this.blank('authenticate')) {
      return "";
    }
    return Em.String.i18n("login." + (this.get('authenticate')) + ".message");
  }).property('authenticate'),

  twitterLogin: function() {
    var left, top;
    this.set('authenticate', 'twitter');
    left = this.get('lastX') - 400;
    top = this.get('lastY') - 200;
    return window.open("/auth/twitter", "_blank", "menubar=no,status=no,height=400,width=800,left=" + left + ",top=" + top);
  },

  facebookLogin: function() {
    var left, top;
    this.set('authenticate', 'facebook');
    left = this.get('lastX') - 400;<commit_msg>Keep a jQuery object of hidden login form<commit_after>/**
  A modal view for handling user logins

  @class LoginView
  @extends Discourse.ModalBodyView
  @namespace Discourse
  @module Discourse
**/
Discourse.LoginView = Discourse.ModalBodyView.extend({
  templateName: 'modal/login',
  siteBinding: 'Discourse.site',
  title: Em.String.i18n('login.title'),
  authenticate: null,
  loggingIn: false,

  showView: function(view) {
    return this.get('controller').show(view);
  },

  newAccount: function() {
    return this.showView(Discourse.CreateAccountView.create());
  },

  forgotPassword: function() {
    return this.showView(Discourse.ForgotPasswordView.create());
  },

  loginButtonText: (function() {
    if (this.get('loggingIn')) {
      return Em.String.i18n('login.logging_in');
    }
    return Em.String.i18n('login.title');
  }).property('loggingIn'),

  loginDisabled: (function() {
    if (this.get('loggingIn')) {
      return true;
    }
    if (this.blank('loginName') || this.blank('loginPassword')) {
      return true;
    }
    return false;
  }).property('loginName', 'loginPassword', 'loggingIn'),

  login: function() {
    var _this = this;
    this.set('loggingIn', true);
    $.post("/session", {
      login: this.get('loginName'),
      password: this.get('<PASSWORD>')
    }).success(function(result) {
      if (result.error) {
        _this.set('loggingIn', false);
        if( result.reason === 'not_activated' ) {
          return _this.showView(Discourse.NotActivatedView.create({username: _this.get('loginName'), sentTo: result.sent_to_email, currentEmail: result.current_email}));
        }
        _this.flash(result.error, 'error');
      } else {
        // Trigger the browser's password manager using the hidden static login form:
        var $hidden_login_form = $('#hidden-login-form');
        $hidden_login_form.find('input[name=username]').val(_this.get('loginName'));
        $hidden_login_form.find('input[name=password]').val(_<PASSWORD>('<PASSWORD>'));
        $hidden_login_form.find('input[name=redirect]').val(window.location.href);
        $hidden_login_form.submit();
      }
    }).fail(function(result) {
      _this.flash(Em.String.i18n('login.error'), 'error');
      return _this.set('loggingIn', false);
    });
    return false;
  },

  authMessage: (function() {
    if (this.blank('authenticate')) {
      return "";
    }
    return Em.String.i18n("login." + (this.get('authenticate')) + ".message");
  }).property('authenticate'),

  twitterLogin: function() {
    var left, top;
    this.set('authenticate', 'twitter');
    left = this.get('lastX') - 400;
    top = this.get('lastY') - 200;
    return window.open("/auth/twitter", "_blank", "menubar=no,status=no,height=400,width=800,left=" + left + ",top=" + top);
  },

  facebookLogin: function() {
    var left, top;
    this.set('authenticate', 'facebook');
    left = this.get('lastX') - 400;
{'fraction_non_alphanumeric': 0.1753381893860562, 'fraction_numerical': 0.008671522719389525, 'mean_word_length': 3.5373721479150277, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '1369283', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1803, 'n_words': 328}