From 4a92bab4d8c231a17a14afc81c391f9a1f91c063 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 26 Feb 2013 11:42:19 +0100 Subject: api for sessions fixed * now we return the user id on login * allow a destroy request for logging out * added test for api sessions controller --- users/app/controllers/sessions_controller.rb | 2 -- users/app/controllers/v1/sessions_controller.rb | 10 +++++++++- users/app/views/v1/sessions/new.json.erb | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 users/app/views/v1/sessions/new.json.erb (limited to 'users/app') diff --git a/users/app/controllers/sessions_controller.rb b/users/app/controllers/sessions_controller.rb index 0345fbd..01ecff6 100644 --- a/users/app/controllers/sessions_controller.rb +++ b/users/app/controllers/sessions_controller.rb @@ -1,7 +1,5 @@ class SessionsController < ApplicationController - skip_before_filter :verify_authenticity_token - def new @session = Session.new if authentication_errors diff --git a/users/app/controllers/v1/sessions_controller.rb b/users/app/controllers/v1/sessions_controller.rb index 27d10fb..0551ca9 100644 --- a/users/app/controllers/v1/sessions_controller.rb +++ b/users/app/controllers/v1/sessions_controller.rb @@ -18,12 +18,20 @@ module V1 def update authenticate! - render :json => session.delete(:handshake) + render :json => login_response end def destroy logout redirect_to root_path end + + protected + + def login_response + handshake = session.delete(:handshake) + handshake.to_hash.merge(:id => current_user.id) + end + end end diff --git a/users/app/views/v1/sessions/new.json.erb b/users/app/views/v1/sessions/new.json.erb new file mode 100644 index 0000000..36154b8 --- /dev/null +++ b/users/app/views/v1/sessions/new.json.erb @@ -0,0 +1,3 @@ +{ +"errors": <%= raw @errors.to_json %> +} -- cgit v1.2.3 From a7722e57ee6e10b578457e880f04349f7f9a0f66 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 26 Feb 2013 11:33:11 -0800 Subject: Changes to valid format for usernames. --- users/app/models/user.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'users/app') diff --git a/users/app/models/user.rb b/users/app/models/user.rb index e41c2dc..b6e2bad 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -19,8 +19,8 @@ class User < CouchRest::Model::Base :if => :serverside? validates :login, - :format => { :with => /\A[A-Za-z\d_\.]+\z/, - :message => "Only letters, digits, . and _ allowed" } + :format => { :with => /\A[a-z][a-z\d_\.-]*[a-z\d]\z/, + :message => "Only lowercase letters, digits, . - and _ allowed. Login must have at least 2 characters, and begin with a letter, and end with a letter or digit" } validate :login_is_unique_alias -- cgit v1.2.3 From 26bce716526bfc6a59ffbc372d34215ce2242bfe Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 28 Feb 2013 10:36:24 -0800 Subject: Have specific error messages for usernames with incorrect formats. Signed-off-by: jessib --- users/app/models/user.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'users/app') diff --git a/users/app/models/user.rb b/users/app/models/user.rb index b6e2bad..c9b367f 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -18,9 +18,19 @@ class User < CouchRest::Model::Base :uniqueness => true, :if => :serverside? + # Have multiple regular expression validations so we can get specific error messages: validates :login, - :format => { :with => /\A[a-z][a-z\d_\.-]*[a-z\d]\z/, - :message => "Only lowercase letters, digits, . - and _ allowed. Login must have at least 2 characters, and begin with a letter, and end with a letter or digit" } + :format => { :with => /\A.{2,}\z/, + :message => "Login must have at least two characters"} + validates :login, + :format => { :with => /\A[a-z\d_\.-]+\z/, + :message => "Only lowercase letters, digits, . - and _ allowed."} + validates :login, + :format => { :with => /\A[a-z].*\z/, + :message => "Login must begin with a lowercase letter"} + validates :login, + :format => { :with => /\A.*[a-z\d]\z/, + :message => "Login must end with a letter or digit"} validate :login_is_unique_alias -- cgit v1.2.3 From 87c306ea212c01ecc8f98009def5971fc4d5af11 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 5 Mar 2013 13:26:56 +0100 Subject: minor: fixed logout link --- users/app/views/sessions/_nav.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'users/app') diff --git a/users/app/views/sessions/_nav.html.haml b/users/app/views/sessions/_nav.html.haml index 5306d0e..ac85bb5 100644 --- a/users/app/views/sessions/_nav.html.haml +++ b/users/app/views/sessions/_nav.html.haml @@ -5,7 +5,7 @@ %li = link_to current_user.login, edit_user_path(current_user) %li - = link_to t(:logout), logout_path + = link_to t(:logout), logout_path, :method => :delete - else %li = link_to t(:login), login_path -- cgit v1.2.3