Commit fd5a1f02 authored by Randall Leeds's avatar Randall Leeds

Propagate form errors to caller and flash for auth

Relates to #1200
parent 983b419f
......@@ -701,24 +701,35 @@ class Auth
code: null
this.$inject = [
'$scope', 'authentication',
'$scope', 'authentication', 'flash'
]
constructor: (
$scope, authentication
$scope, authentication, flash
) ->
_reset = =>
angular.copy @scope, $scope.model
for own _, ctrl of $scope when typeof ctrl?.$setPristine is 'function'
ctrl.$setPristine()
_success = ->
_reset()
$scope.$emit 'success', form.$name
_error = (response) ->
if response.errors
# TODO: show these messages inline with the form
for field, error of response.errors
console.log(field, error)
flash('error', error)
if response.reason
flash('error', reason)
$scope.$on '$reset', _reset
$scope.submit = (form) ->
angular.extend authentication, $scope.model
return unless form.$valid
authentication["$#{form.$name}"] ->
_reset()
$scope.$emit 'success', form.$name
authentication["$#{form.$name}"] _success, _error
class Editor
......
......@@ -55,7 +55,7 @@ flashInterceptor = ['$q', 'flash', ($q, flash) ->
if data.status is 'failure'
flash 'error', data.reason
$q.reject(data.reason)
$q.reject(data)
else if data.status is 'okay' and data.model
response.data = data.model
response
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment