<commit_before>##################
# Auth
#
# There are a number of forms that are displayed via the Auth component:
# - login
# - create account
# - create account via invitation (with fixed email address)
# - reset password
# - verify email
# - edit profile
#
# Each of these screens has some differences. We try to keep these differences
# clearly documented in the render method so that the method doesn't get
# too complicated to understand and modify. 

auth_gray = '#a1a1a1' # the gray color used through the auth forms

Auth = ReactiveComponent
  displayName: 'Auth'

  render: -> 
    current_user = fetch('/current_user')
    root = fetch('root')

    # When we switch to new auth_mode screens, wipe out all the old
    # errors, cause we're startin' fresh!
    if not @local.last_auth or @local.last_auth != root.auth
      @local.last_auth = root.auth
      current_user.errors = []
      save @local
      return SPAN null

    return SPAN null if !root.auth

    DIV null,
      if root.auth.form == 'edit profile'
        DashHeader(name: 'Edit Profile')

      DIV
        style:
          margin: "0 auto 0 #{if lefty then 300 else 'auto'}"
          padding: '2em 0'
          position: 'relative'
          zIndex: 0
          width: DECISION_BOARD_WIDTH

        @buildAuthForm()

  ####
  # buildAuthForm
  #
  # Constructs the correct form given the desired mode.
  # Builds the form from input and section components
  # defined further down the file. Intended to be as 
  # declarative as possible for making clear definitions
  # of different auth modes. 
  buildAuthForm : -> 
    root = fetch('root')
    current_user = fetch('/current_user')

    goal = if @root.auth.goal then "To #{@root.auth.goal}" else null

    switch root.auth.form

      # The LOGIN form, with easy switch to register
      when 'login'
        [ @headerAndBorder goal, 'Introduce Yourself', 
            @body [['Hi, I login as:', 
                    [ @inputBox('email', 'email@address'),
                      @inputBox('password', "password", 'password'),
                      @resetPasswordLink() ]]]
          @footerForRegistrationAndLogin() ]

      # The REGISTER form, with easy switch to log in
      #   ...or a slight variation for completing registration
      #      after invitation, where email is fixed and can't
      #      switch to log in. 
      when 'create account', 'create account via invitation'
        
        if avatar_field = @avatarInput()
          avatar_field = ['I look like:', avatar_field]

        if pledges = @pledgeInput()
          pledges_field = ['I pledge to:', pledges]

        if root.auth.form == 'create account'
          email_field = @inputBox('email', 'email@address')
          footer = @footerForRegistrationAndLogin()
        else
          email_field = DIV 
            style: {color: auth_gray, padding: '4px 8px'}, 
            current_user.email
          footer = @submitButton('Create new account')

        [ @headerAndBorder goal, 'Introduce Yourself', 
            @body [['Hi, I login as:', 
                      [ email_field,
                        @inputBox('password', "password", 'password')]],
                    ['My name is:', @inputBox('name', 'first and last name')],
                    avatar_field,
                    pledges_field]
          footer ]

      # The EDIT PROFILE form
      # We don't render an enclosing header and border, 
      # and add feedback when the user is updated.
      when 'edit profile'
        if avatar_field = @avatarInput()
          avatar_field = ['I look like:', avatar_field]

        [ @body [
            ['Hi, I login as:', 
              [ @inputBox('email', 'email@address'),
                @inputBox('password', "password", 'password')]
            ],
            ['My name is:', @inputBox('name', 'first and last name')],
            avatar_field]
          @submitButton('Update')
          if @local.saved_successfully
            SPAN style: {color: 'green'}, "Updated successfully"
        ]

      # The RESET PASSWORD form
      when 'reset password'
        [ @headerAndBorder null, 'Reset Your Password', 
            @body [['Code:', @inputBox('verification_code', 'verification code from email')],
                   ['New password:', @inputBox('password', "<PASSWORD>", 'password')]
                  ], 'We sent you a verification code via email.'
          @submitButton('Log in') ]

      # The email VERIFICATION form
      when 'verify email'
        [ @headerAndBorder goal, 'Verify Your Email', 
            @body [['Code:', @inputBox('verification_code', 'verification code from email')]], 
                  'We sent you a verification code via email.'
          @submitButton('Log in') ]

      else
        throw "Unrecognized authentication form #{root.auth.form}"

  #####
  # headerAndBorder
  #
  # Creates the header with bubble mouth and blue circle. 
  # Also creates an enclosure with blue dashed boarder. 
  # 
  # goal: The reason this auth form is being shown
  # task: The label for this auth form
  # body: Child nodes that will be rendered inside
  #
  headerAndBorder : (goal, task, body) -> 
    root = fetch('root')

    DIV null,
<commit_msg>.<commit_after>##################
# Auth
#
# There are a number of forms that are displayed via the Auth component:
# - login
# - create account
# - create account via invitation (with fixed email address)
# - reset password
# - verify email
# - edit profile
#
# Each of these screens has some differences. We try to keep these differences
# clearly documented in the render method so that the method doesn't get
# too complicated to understand and modify. 

auth_gray = '#a1a1a1' # the gray color used through the auth forms

Auth = ReactiveComponent
  displayName: 'Auth'

  render: -> 
    current_user = fetch('/current_user')
    root = fetch('root')

    # When we switch to new auth_mode screens, wipe out all the old
    # errors, cause we're startin' fresh!
    if not @local.last_auth or @local.last_auth != root.auth
      @local.last_auth = root.auth
      current_user.errors = []
      save @local
      return SPAN null

    return SPAN null if !root.auth

    DIV null,
      if root.auth.form == 'edit profile'
        DashHeader(name: 'Edit Profile')

      DIV
        style:
          margin: "0 auto 0 #{if lefty then 300 else 'auto'}"
          padding: '2em 0'
          position: 'relative'
          zIndex: 0
          width: DECISION_BOARD_WIDTH

        @buildAuthForm()

  ####
  # buildAuthForm
  #
  # Constructs the correct form given the desired mode.
  # Builds the form from input and section components
  # defined further down the file. Intended to be as 
  # declarative as possible for making clear definitions
  # of different auth modes. 
  buildAuthForm : -> 
    root = fetch('root')
    current_user = fetch('/current_user')

    goal = if @root.auth.goal then "To #{@root.auth.goal}" else null

    switch root.auth.form

      # The LOGIN form, with easy switch to register
      when 'login'
        [ @headerAndBorder goal, 'Introduce Yourself', 
            @body [['Hi, I login as:', 
                    [ @inputBox('email', 'email@address'),
                      @inputBox('password', "password", 'password'),
                      @resetPasswordLink() ]]]
          @footerForRegistrationAndLogin() ]

      # The REGISTER form, with easy switch to log in
      #   ...or a slight variation for completing registration
      #      after invitation, where email is fixed and can't
      #      switch to log in. 
      when 'create account', 'create account via invitation'
        
        if avatar_field = @avatarInput()
          avatar_field = ['I look like:', avatar_field]

        if pledges = @pledgeInput()
          pledges_field = ['I pledge to:', pledges]

        if root.auth.form == 'create account'
          email_field = @inputBox('email', 'email@address')
          footer = @footerForRegistrationAndLogin()
        else
          email_field = DIV 
            style: {color: auth_gray, padding: '4px 8px'}, 
            current_user.email
          footer = @submitButton('Create new account')

        [ @headerAndBorder goal, 'Introduce Yourself', 
            @body [['Hi, I login as:', 
                      [ email_field,
                        @inputBox('password', "password", 'password')]],
                    ['My name is:', @inputBox('name', 'first and last name')],
                    avatar_field,
                    pledges_field]
          footer ]

      # The EDIT PROFILE form
      # We don't render an enclosing header and border, 
      # and add feedback when the user is updated.
      when 'edit profile'
        if avatar_field = @avatarInput()
          avatar_field = ['I look like:', avatar_field]

        [ @body [
            ['Hi, I login as:', 
              [ @inputBox('email', 'email@address'),
                @inputBox('password', "password", 'password')]
            ],
            ['My name is:', @inputBox('name', 'first and last name')],
            avatar_field]
          @submitButton('Update')
          if @local.saved_successfully
            SPAN style: {color: 'green'}, "Updated successfully"
        ]

      # The RESET PASSWORD form
      when 'reset password'
        [ @headerAndBorder null, 'Reset Your Password', 
            @body [['Code:', @inputBox('verification_code', 'verification code from email')],
                   ['New password:', @inputBox('password', "<PASSWORD>", 'password')]
                  ], 'We sent you a verification code via email.'
          @submitButton('Log in') ]

      # The email VERIFICATION form
      when 'verify email'
        [ @headerAndBorder goal, 'Verify Your Email', 
            @body [['Code:', @inputBox('verification_code', 'verification code from email')]], 
                  'We sent you a verification code via email.'
          @submitButton('Verify') ]

      else
        throw "Unrecognized authentication form #{root.auth.form}"

  #####
  # headerAndBorder
  #
  # Creates the header with bubble mouth and blue circle. 
  # Also creates an enclosure with blue dashed boarder. 
  # 
  # goal: The reason this auth form is being shown
  # task: The label for this auth form
  # body: Child nodes that will be rendered inside
  #
  headerAndBorder : (goal, task, body) -> 
    root = fetch('root')

    DIV null,

{'fraction_non_alphanumeric': 0.10730724971231301, 'fraction_numerical': 0.002493287303413886, 'mean_word_length': 2.2079360196862505, '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': '80704', 'n_tokens_mistral': 2923, 'n_tokens_neox': 2753, 'n_words': 1005}