<commit_before>_ = require 'underscore'
Networking = require './networking'
URLs = require './urls'
EventEmitter2 = require 'eventemitter2'

ERROR_CODES =
  pin_not_correct: 'Invalid PIN code'
  no_pin_confirmation_attempts_remaining: 'Too many PIN attempts'

class Email extends EventEmitter2

  constructor: (@user, attrs) ->
    super()
    _.extend(@, attrs)

  sendVerification: (pin, successCallBack) ->
    @makeRequest('confirm_by_pin', {pin}).then((resp) =>
      if resp.status is 204
        delete @error
        @is_verified = true
        successCallBack(@)
      else
        code = _.first(resp.data?.errors)?.code
        console.log(code)
        @error = ERROR_CODES[code]
        if code is 'no_pin_confirmation_attempts_remaining'
          @verificationFailed = true
      @emit('change')
    )


  sendConfirmation: ->
    @makeRequest('resend_confirmation', {send_pin: true}).then (resp) =>
      @verifyInProgress = (resp.status is 204)
      @emit('change')

  makeRequest: (type, data = {}) ->
    @requestInProgress = true

    afterRequest = (resp) =>

      @requestInProgress = false
      @emit('change')
      resp
    Networking.perform(
      method: 'PUT',<commit_msg>remove console.log<commit_after>_ = require 'underscore'
Networking = require './networking'
URLs = require './urls'
EventEmitter2 = require 'eventemitter2'

ERROR_CODES =
  pin_not_correct: 'Invalid PIN code'
  no_pin_confirmation_attempts_remaining: 'Too many PIN attempts'

class Email extends EventEmitter2

  constructor: (@user, attrs) ->
    super()
    _.extend(@, attrs)

  sendVerification: (pin, successCallBack) ->
    @makeRequest('confirm_by_pin', {pin}).then (resp) =>
      if resp.status is 204
        delete @error
        @is_verified = true
        successCallBack(@)
      else
        code = _.first(resp.data?.errors)?.code
        @error = ERROR_CODES[code]
        if code is 'no_pin_confirmation_attempts_remaining'
          @verificationFailed = true
      @emit('change')


  sendConfirmation: ->
    @makeRequest('resend_confirmation', {send_pin: true}).then (resp) =>
      @verifyInProgress = (resp.status is 204)
      @emit('change')

  makeRequest: (type, data = {}) ->
    @requestInProgress = true

    afterRequest = (resp) =>
      @requestInProgress = false
      @emit('change')
      resp
    Networking.perform(
      method: 'PUT',
{'fraction_non_alphanumeric': 0.12352941176470589, 'fraction_numerical': 0.007563025210084034, 'mean_word_length': 3.09106529209622, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '2201958', 'n_tokens_mistral': 760, 'n_tokens_neox': 738, 'n_words': 166}