Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign in from controller #494

Closed
nixv2 opened this issue Jan 8, 2016 · 1 comment
Closed

Sign in from controller #494

nixv2 opened this issue Jan 8, 2016 · 1 comment

Comments

@nixv2
Copy link

nixv2 commented Jan 8, 2016

hi, am using the this gem and it works great...
i just have one question is it possible to sign in a user from a controller??
am trying to do something like this:

class Api::V1::SessionsController < DeviseTokenAuth::SessionsController
    def create
        begin
            ldap_user = User.someService # Call a service with login data...
            if ldap_user
                # sing in user
            else
                render json: {:error => 'Invalid Login'}.to_json, status: :bad_request
            end
        rescue Exception => ex
            render json: {:error => ex.message}.to_json, status: :bad_request
        end
    end
end

so what am trying to do is:
before the user is sign in, get some external data and if the data is returned sing in the user (i have access to the user data)...
the problem is that am not sure how to sing in the user... is there a helper to sing in the user?? or do i have to overwrite the whole sessions controller??

any help will be appreciated and thanks in advance.

to handle my views am using angular with ng-token-auth

@zachfeldman
Copy link
Contributor

Hey @nixv2 , you can use the same helpers that devise uses to sign in users:
http://www.rubydoc.info/github/plataformatec/devise/Devise/Controllers/SignInOut

Going to close this but feel free reopen if you'd like!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants