summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2013-06-27 12:31:39 -0700
committerjessib <jessib@leap.se>2013-06-27 12:31:39 -0700
commita01e7686ea7c046a9cd544b618b30727f2a41b3b (patch)
treee00261ade269bfe6ddc843a728a4355807228ea9
parentba036558e47da53e86ccb8cb7fb4ee1db725b804 (diff)
Want to tweak some, but start to displaying base generic message via javascript.
-rw-r--r--app/views/layouts/_messages.html.haml2
-rw-r--r--app/views/layouts/application.html.haml2
-rw-r--r--users/app/assets/javascripts/users.js.coffee22
-rw-r--r--users/app/controllers/controller_extension/authentication.rb1
-rw-r--r--users/lib/warden/strategies/secure_remote_password.rb4
5 files changed, 23 insertions, 8 deletions
diff --git a/app/views/layouts/_messages.html.haml b/app/views/layouts/_messages.html.haml
index 80e34d4..6ec70a2 100644
--- a/app/views/layouts/_messages.html.haml
+++ b/app/views/layouts/_messages.html.haml
@@ -2,4 +2,4 @@
- if msg.is_a?(String)
%div{:class => "alert alert-#{name == :notice ? "success" : "error"}"}
%a.close{"data-dismiss" => "alert"} ×
- = content_tag :div, msg, :id => "flash_#{name}"
+ = content_tag :div, msg, :class => "flash_#{name}"
diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml
index e6d22f0..2b8206d 100644
--- a/app/views/layouts/application.html.haml
+++ b/app/views/layouts/application.html.haml
@@ -18,6 +18,6 @@
.content
.row
.span12
- = render 'layouts/messages'
+ #messages= render 'layouts/messages'
= yield
%footer
diff --git a/users/app/assets/javascripts/users.js.coffee b/users/app/assets/javascripts/users.js.coffee
index 955556c..b0b624c 100644
--- a/users/app/assets/javascripts/users.js.coffee
+++ b/users/app/assets/javascripts/users.js.coffee
@@ -14,13 +14,27 @@ srp.updated = ->
srp.error = (message) ->
if $.isPlainObject(message) && message.errors
- for field, error of message.errors
- element = $('form input[name$="['+field+']"]')
- next unless element
- element.trigger('element:validate:fail.ClientSideValidations', error).data('valid', false)
+ display_errors(message.errors)
else
alert(message)
+display_errors = (errors) ->
+ for field, error of errors
+ if field == 'base'
+ display_base_error(error);
+ else
+ display_field_error(field, error);
+
+display_field_error = (field, error) ->
+ element = $('form input[name$="['+field+']"]')
+ return unless element
+ element.trigger('element:validate:fail.ClientSideValidations', error).data('valid', false)
+
+display_base_error = (message) ->
+ messages = $('#messages')
+ messages.append "<div class=\"alert alert-error\"><a class=\"close\" \"data-dismiss\"=\"alert\">×</a><div class=\"flash_error\">" + message + "</div></div>"
+
+
pollUsers = (query, process) ->
$.get( "/users.json", query: query).done(process)
diff --git a/users/app/controllers/controller_extension/authentication.rb b/users/app/controllers/controller_extension/authentication.rb
index f0a6564..0dca29c 100644
--- a/users/app/controllers/controller_extension/authentication.rb
+++ b/users/app/controllers/controller_extension/authentication.rb
@@ -10,6 +10,7 @@ module ControllerExtension::Authentication
def authentication_errors
return unless attempted_login?
errors = get_warden_errors
+ #default response to get_warden_errors is not an enumerable, so won't work if default is used
errors.inject({}) do |translated,err|
translated[err.first] = I18n.t(err.last)
translated
diff --git a/users/lib/warden/strategies/secure_remote_password.rb b/users/lib/warden/strategies/secure_remote_password.rb
index f1b1a57..2dcd706 100644
--- a/users/lib/warden/strategies/secure_remote_password.rb
+++ b/users/lib/warden/strategies/secure_remote_password.rb
@@ -28,7 +28,7 @@ module Warden
if client = validate
success!(User.find_by_login(client.username))
else
- fail!({:login => "invalid_user_pass", :password => "invalid_user_pass"})
+ fail!(:base => "invalid_user_pass")
end
end
@@ -44,7 +44,7 @@ module Warden
session[:handshake] = SRP::Session.new(client, params['A'].hex)
custom! json_response(session[:handshake])
else
- fail!({:login => "invalid_user_pass", :password => "invalid_user_pass"})
+ fail! :base => 'invalid_user_pass'
end
end