<commit_before>LoginViewInlineForm      = require './loginviewinlineform'
LoginInputView           = require './logininputview'
LoginInputViewWithLoader = require './logininputwithloader'

module.exports = class RegisterInlineForm extends LoginViewInlineForm

  ENTER = 13

  constructor:(options={},data)->
    super options, data

    @emailIsAvailable = no
    @on 'EmailIsAvailable'   , => @emailIsAvailable = yes
    @on 'EmailIsNotAvailable', => @emailIsAvailable = no

    @on 'EmailValidationPassed', @bound 'callbackAfterValidation'

    @password?.destroy()
    @password = new LoginInputView
      inputOptions       :
        name             : "password"
        type             : "password"
        testPath         : "recover-password"
        placeholder      : "Password"
        focus            : => @password.icon.unsetTooltip()
        keydown          : (event) =>
          if event.which is ENTER
            @password.input.validate()
            @button.click event
        validate          :
          event           : 'blur'
          container       : this
          rules           :
            required      : yes
            minLength     : 8
          messages        :
            required      : "Please enter a password."
            minLength     : "Passwords should be at least 8 characters."
        decorateValidation: no

    @tfcode = @create2FAInput()
    @tfcode.hide()

    @email?.destroy()
    @email = new LoginInputViewWithLoader
      inputOptions        :
        name              : 'email'
        placeholder       : 'Email address'
        attributes        :
          testpath        : 'register-form-email'
        validate          : KD.utils.getEmailValidator
          container       : this
          password        : <PASSWORD>
          tfcode          : @tfcode
        decorateValidation: no
        focus             : => @email.icon.unsetTooltip()
        keydown           : (event) => @submitForm event  if event.which is ENTER
        blur              : => @fetchGravatarInfo @email.input.getValue()
        change            : => @emailIsAvailable = no


    {buttonTitle} = @getOptions()

    @button?.destroy()
    @button = new KDButtonView
      title         : buttonTitle or 'CREATE ACCOUNT'
      type          : 'button'
      style         : 'solid green medium'
      attributes    :
        testpath    : 'signup-button'
      loader        : yes
      callback      : @bound 'submitForm'

    @invitationCode = new LoginInputView
      cssClass      : 'hidden'
      inputOptions  :
        name        : 'inviteCode'
        type        : 'hidden'

    @on 'SubmitFailed', (msg) =>
      if msg is 'Wrong password'
        @passwordConfirm.input.setValue ''
        @password.input.setValue ''
        @password.input.validate()

      @button.hideLoader()

    @bind2FAEvents()

    KD.singletons.router.on 'RouteInfoHandled', =>
      @email.icon.unsetTooltip()
      @password.icon.unsetTooltip()


  create2FAInput: ->
    return new LoginInputView
      inputOptions    :
        name          : 'tfcode'
        placeholder   : 'Two-Factor Authentication Code'
        testPath      : 'register-form-tfcode'
        attributes    :
          testpath    : 'register-form-tfcode'


  bind2FAEvents: ->

    @on 'TwoFactorEnabled', =>
      @button.hideLoader()
      @tfcode.show()
      @tfcode.setFocus()


  reset: -><commit_msg>Listen enter key event for 2FA in register page.<commit_after>LoginViewInlineForm      = require './loginviewinlineform'
LoginInputView           = require './logininputview'
LoginInputViewWithLoader = require './logininputwithloader'

module.exports = class RegisterInlineForm extends LoginViewInlineForm

  ENTER = 13

  constructor:(options={},data)->
    super options, data

    @emailIsAvailable = no
    @on 'EmailIsAvailable'   , => @emailIsAvailable = yes
    @on 'EmailIsNotAvailable', => @emailIsAvailable = no

    @on 'EmailValidationPassed', @bound 'callbackAfterValidation'

    @password?.destroy()
    @password = new LoginInputView
      inputOptions       :
        name             : "password"
        type             : "password"
        testPath         : "recover-password"
        placeholder      : "Password"
        focus            : => @password.icon.unsetTooltip()
        keydown          : (event) =>
          if event.which is ENTER
            @password.input.validate()
            @button.click event
        validate          :
          event           : 'blur'
          container       : this
          rules           :
            required      : yes
            minLength     : 8
          messages        :
            required      : "Please enter a password."
            minLength     : "Passwords should be at least 8 characters."
        decorateValidation: no

    @email?.destroy()
    @email = new LoginInputViewWithLoader
      inputOptions        :
        name              : 'email'
        placeholder       : 'Email address'
        attributes        :
          testpath        : 'register-form-email'
        validate          : KD.utils.getEmailValidator
          container       : this
          password        : <PASSWORD>
          tfcode          : @tfcode
        decorateValidation: no
        focus             : => @email.icon.unsetTooltip()
        keydown           : (event) => @submitForm event  if event.which is ENTER
        blur              : => @fetchGravatarInfo @email.input.getValue()
        change            : => @emailIsAvailable = no


    {buttonTitle} = @getOptions()

    @button?.destroy()
    @button = new KDButtonView
      title         : buttonTitle or 'CREATE ACCOUNT'
      type          : 'button'
      style         : 'solid green medium'
      attributes    :
        testpath    : 'signup-button'
      loader        : yes
      callback      : @bound 'submitForm'

    @invitationCode = new LoginInputView
      cssClass      : 'hidden'
      inputOptions  :
        name        : 'inviteCode'
        type        : 'hidden'

    @on 'SubmitFailed', (msg) =>
      if msg is 'Wrong password'
        @passwordConfirm.input.setValue ''
        @password.input.setValue ''
        @password.input.validate()

      @button.hideLoader()

    @tfcode = @create2FAInput()
    @tfcode.hide()

    @bind2FAEvents()

    KD.singletons.router.on 'RouteInfoHandled', =>
      @email.icon.unsetTooltip()
      @password.icon.unsetTooltip()


  create2FAInput: ->
    return new LoginInputView
      inputOptions    :
        name          : 'tfcode'
        placeholder   : 'Two-Factor Authentication Code'
        testPath      : 'register-form-tfcode'
        attributes    :
          testpath    : 'register-form-tfcode'
        keydown       : (event) =>
          @button.click event  if event.which is ENTER


  bind2FAEvents: ->

    @on 'TwoFactorEnabled', =>
      @button.hideLoader()
      @tfcode.show()
      @tfcode.setFocus()


  reset: ->
{'fraction_non_alphanumeric': 0.09411259131929522, 'fraction_numerical': 0.002435181206130927, 'mean_word_length': 1.6598095238095238, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, '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': '3313491', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1812, 'n_words': 418}