<commit_before>
doneCallback = null

# Stub for right now
Accounts.onResetPasswordLink (token, done) ->
  Session.set "resetPasswordToken", token
  doneCallback = done



Template.resetPassword.onCreated ->

  self = @

  self.hasErrors = new ReactiveVar(false)

  self.password = new ReactiveVar({
    methods: null
    parent: self
  })

  self.confirmPassword = new ReactiveVar({
    methods: null
    parent: self
  })



Template.resetPassword.helpers

  "hasErrors": ->
    return Template.instance().hasErrors.get()

  "resetPasswordToken": ->
    return Session.get "resetPasswordToken"

  "password": ->
    return Template.instance().password

  "confirmPassword": ->
    return Template.instance().confirmPassword



Template.resetPassword.onRendered ->

  # use if navigating away from reset password page
  sessionReset = ->
    return


Template.resetPassword.events

  "submit #reset-password": (event, template) ->
    event.preventDefault()

    token = Session.get "resetPasswordToken"
    password = template.find("input[name=password]").value
    confirmPassword = template.find("input[name=confirmPassword]").value

    if not password
      template.hasErrors.set true
      passwordTemplate = template.password.get()
      passwordTemplate.methods.setStatus "Password cannot be empty", true
      return
    else if not confirmPassword
      template.hasErrors.set true
      confirmPasswordTemplate = template.confirmPassword.get()
      confirmPasswordTemplate.methods.setStatus "Password cannot be empty", true
      return
    else if password != confirmPassword
      template.hasErrors.set true
      confirmPasswordTemplate = template.confirmPassword.get()
      confirmPasswordTemplate.methods.setStatus "Passwords must match", true
      return

    Apollos.user.resetPassword token, password, (error) ->
      if error

        template.hasErrors.set true

        # token expired
        if error.error is 403
          passwordTemplate = template.password.get()
          passwordTemplate.methods.setStatus "This reset link has expired", true

      else
        Session.set "resetPasswordToken", ""
        doneCallback()
        Router.go "home"
<commit_msg>fix reset password form has errors on focus<commit_after>
doneCallback = null

# Stub for right now
Accounts.onResetPasswordLink (token, done) ->
  Session.set "resetPasswordToken", token
  doneCallback = done



Template.resetPassword.onCreated ->

  self = @

  self.hasErrors = new ReactiveVar(false)

  self.password = new ReactiveVar({
    methods: null
    parent: self
  })

  self.confirmPassword = new ReactiveVar({
    methods: null
    parent: self
  })



Template.resetPassword.helpers

  "hasErrors": ->
    return Template.instance().hasErrors.get()

  "resetPasswordToken": ->
    return Session.get "resetPasswordToken"

  "password": ->
    return Template.instance().password

  "confirmPassword": ->
    return Template.instance().confirmPassword



Template.resetPassword.onRendered ->

  # use if navigating away from reset password page
  sessionReset = ->
    return


Template.resetPassword.events

  "focus input": (event, template) ->
    template.hasErrors.set false

  "submit #reset-password": (event, template) ->
    event.preventDefault()

    token = Session.get "resetPasswordToken"
    password = template.find("input[name=password]").value
    confirmPassword = template.find("input[name=confirmPassword]").value

    if not password
      template.hasErrors.set true
      passwordTemplate = template.password.get()
      passwordTemplate.methods.setStatus "Password cannot be empty", true
      return
    else if not confirmPassword
      template.hasErrors.set true
      confirmPasswordTemplate = template.confirmPassword.get()
      confirmPasswordTemplate.methods.setStatus "Password cannot be empty", true
      return
    else if password != confirmPassword
      template.hasErrors.set true
      confirmPasswordTemplate = template.confirmPassword.get()
      confirmPasswordTemplate.methods.setStatus "Passwords must match", true
      return

    Apollos.user.resetPassword token, password, (error) ->
      if error

        template.hasErrors.set true

        # token expired
        if error.error is 403
          passwordTemplate = template.password.get()
          passwordTemplate.methods.setStatus "This reset link has expired", true

      else
        Session.set "resetPasswordToken", ""
        doneCallback()
        Router.go "home"

{'fraction_non_alphanumeric': 0.091273374888691, 'fraction_numerical': 0.0013357079252003562, 'mean_word_length': 3.21087160262418, 'pattern_counts': {'":': 11, '<': 3, '<?xml version=': 0, '>': 24, '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': '537795', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1142, 'n_words': 305}