Sha256: 3da6cd8b2c7f88e82d94b757ea248a7eca567811621873f7c3f0c86acb983b85

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

angular.module('EssayApp.services')
  .factory('RestorePasswordService', ["$http", "$q", "ngProgress", ($http, $q, ngProgress) ->
    api =
      active: false
      email: undefined
      mail_sent: false
      pending: false
      data: {
        email: undefined
      }

      activate: (email)->
        @email = email
        @active = true
        @mail_sent = false

      cancel: ->
        @email = undefined
        @active = false
        @mail_sent = false

      submit: (e, form, apply_to_form) ->
        e?.preventDefault?()
        if form.$valid
          ngProgress.start()
          @pending = true
          @reset_password(@email).then(
            =>
              @mail_sent = true
              @active = false
              @pending = false
              if apply_to_form?['account[email]']?
                _remote = apply_to_form['account[email]']
                _remote.$setViewValue(@email)
                _remote.$render()

              ngProgress.complete()
            , (errors)=>
              @mail_sent = false
              $.each errors, (key, val)->
                form["restore_pass[#{key}]"].$setTouched()
                form["restore_pass[#{key}]"].$setValidity('server', false, if angular.isArray(val) then val[0] else val)
                $("[name=\"restore_pass[#{key}]\"]").trigger('focusout')
              @pending = false
              ngProgress.complete()
            )
          # form.$setSubmitted(true)

      reset_password: (email)->
        $q (resolve, reject)->
          $http(
            method: 'POST'
            url: '/auth/password/reset.json'
            data: $.param(account: { email: email })
          ).then(
            (data) ->
              resolve()
            , (err) ->
              reject err?.data?.errors
          )

    return api
])

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 app/assets/javascripts/app/services/restore_password_service.js.coffee