Revisions
-
evanbeard revised this gist
May 13, 2012 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ class Api::SessionsController < Api::BaseController before_filter :authenticate_user!, :except => [:create, :destroy] before_filter :ensure_params_exist @@ -9,7 +8,7 @@ def create return invalid_login_attempt unless resource if resource.valid_password?(params[:user_login][:password]) sign_in(:user, resource) resource.ensure_authentication_token! render :json=> {:success=>true, :auth_token=>resource.authentication_token, :email=>resource.email} return -
evanbeard revised this gist
May 11, 2012 . 1 changed file with 9 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ class Api::SessionsController < Api::BaseController before_filter :authenticate_user!, :except => [:create, :destroy] before_filter :ensure_params_exist respond_to :json def create @@ -10,15 +10,18 @@ def create if resource.valid_password?(params[:user_login][:password]) sign_in("user", resource) resource.ensure_authentication_token! render :json=> {:success=>true, :auth_token=>resource.authentication_token, :email=>resource.email} return end invalid_login_attempt end def destroy resource = User.find_for_database_authentication(:email => params[:user_login][:email]) resource.authentication_token = nil resource.save render :json=> {:success=>true} end protected @@ -30,4 +33,4 @@ def ensure_params_exist def invalid_login_attempt render :json=> {:success=>false, :message=>"Error with your login or password"}, :status=>401 end end -
evanbeard revised this gist
May 11, 2012 . 1 changed file with 6 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,22 @@ class Api::SessionsController < Api::BaseController before_filter :authenticate_user!, :except => [:create] before_filter :ensure_params_exist respond_to :json def create resource = User.find_for_database_authentication(:email => params[:user_login][:email]) return invalid_login_attempt unless resource if resource.valid_password?(params[:user_login][:password]) sign_in("user", resource) render :json=> {:success=>true, :auth_token=>resource.authentication_token, :login=>resource.login, :email=>resou\ rce.email} return end invalid_login_attempt end def destroy sign_out(resource_name) end @@ -30,7 +28,6 @@ def ensure_params_exist end def invalid_login_attempt render :json=> {:success=>false, :message=>"Error with your login or password"}, :status=>401 end end -
jwo revised this gist
Jan 24, 2012 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ class Api::RegistrationsController < Api::BaseController respond_to :json def create user = User.new(params[:user]) if user.save render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201 return else warden.custom_failure! render :json=> user.errors, :status=>422 end end end -
jwo revised this gist
Jan 19, 2012 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,6 @@ def create invalid_login_attempt end def destroy sign_out(resource_name) end -
jwo revised this gist
Jan 19, 2012 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ class Api::SessionsController < Api::BaseController prepend_before_filter :require_no_authentication, :only => [:create ] include Devise::Controllers::InternalHelpers @@ -21,8 +21,7 @@ def create # GET /resource/sign_out def destroy sign_out(resource_name) end protected -
jwo created this gist
Sep 30, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ class Api::V1::SessionsController < Api::V1::BaseController prepend_before_filter :require_no_authentication, :only => [:create ] include Devise::Controllers::InternalHelpers before_filter :ensure_params_exist respond_to :json def create build_resource resource = User.find_for_database_authentication(:login=>params[:user_login][:login]) return invalid_login_attempt unless resource if resource.valid_password?(params[:user_login][:password]) sign_in("user", resource) render :json=> {:success=>true, :auth_token=>resource.authentication_token, :login=>resource.login, :email=>resource.email} return end invalid_login_attempt end # GET /resource/sign_out def destroy set_flash_message :notice, :signed_out if signed_in?(resource_name) sign_out_and_redirect(resource_name) end protected def ensure_params_exist return unless params[:user_login].blank? render :json=>{:success=>false, :message=>"missing user_login parameter"}, :status=>422 end def invalid_login_attempt warden.custom_failure! render :json=> {:success=>false, :message=>"Error with your login or password"}, :status=>401 end end