×

Welcome to TagMyCode

Please login or create account to add a snippet.
1
0
 
1
Language: Ruby
Posted by: Adam Bedell
Added: Aug 16, 2013 1:22 AM
Views: 30
sessions_controller.rb example for rails-api 4.0 @ http://www.emilsoman.com/blog/2013/05/18/building-a-tested/
  1. module Api
  2.   module V1
  3.     module CustomDevise
  4.       class SessionsController < Devise::SessionsController
  5.         prepend_before_filter :require_no_authentication, :only => [:create ]
  6.         include Devise::Controllers::Helpers
  7.  
  8.         respond_to :json
  9.  
  10.         def create
  11.           self.resource = warden.authenticate!(auth_options)
  12.           sign_in(resource_name, resource)
  13.           resource.reset_authentication_token!
  14.           resource.save!
  15.           render json: {
  16.             auth_token: resource.reset_authentication_token,
  17.             user_role: resource.role
  18.           }
  19.         end
  20.  
  21.         def destroy
  22.           sign_out(resource_name)
  23.         end
  24.  
  25.       end
  26.     end
  27.   end
  28. end