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

undefined method 'login' Rails 5 #794

Closed
alextab93 opened this Issue Aug 30, 2016 · 6 comments

Comments

Projects
None yet
2 participants
@alextab93

alextab93 commented Aug 30, 2016

Hi, I have that sorcery.rb initializer

Rails.application.config.sorcery.submodules = [:reset_password, :activity_logging]
Rails.application.config.sorcery.configure do |config|
config.user_config do |user|
user.username_attribute_names = [:email, :username]
user.downcase_username_before_authenticating = true
user.reset_password_mailer = UserMailer
user.reset_password_expiration_period = 5 * 60
end
config.user_class = "User"
end

but, when I try to use login() in my session controller
def create
@user = login(params[:email], @pass)
if @user
@token = @user.get_token.token
else
render(:unprocessable, errors: ["Credenciales Invalidas"])
end
end

I get a undefined method error.

Thanks for helping.

@alextab93

This comment has been minimized.

alextab93 commented Aug 31, 2016

I just made this whole process but in Rails 4 and it works, then it is a problem only for Rails 5

@athix

This comment has been minimized.

Contributor

athix commented Aug 31, 2016

Hey @2l3x2nd3r, thanks for narrowing down the issue to Rails 5. Would you mind posting the full stack trace including the line numbers? That would help us figure out what file is causing the issue.

@alextab93

This comment has been minimized.

alextab93 commented Aug 31, 2016

{
"status": 500,
"error": "Internal Server Error",
"exception": "#<NoMethodError: undefined method login' for #<Api::V1::SessionsController:0x00000003ac9088>>", "traces": { "Application Trace": [ { "id": 0, "trace": "app/controllers/api/v1/sessions_controller.rb:6:in create'"
}
],
"Framework Trace": [
{
"id": 1,
"trace": "actionpack (5.0.0.1) lib/action_controller/metal/basic_implicit_render.rb:4:insend_action'" }, { "id": 2, "trace": "actionpack (5.0.0.1) lib/abstract_controller/base.rb:188:in process_action'"
}
],
"Full Trace": [
{
"id": 0,
"trace": "app/controllers/api/v1/sessions_controller.rb:6:increate'" }, { "id": 1, "trace": "actionpack (5.0.0.1) lib/action_controller/metal/basic_implicit_render.rb:4:in send_action'"
},
{
"id": 2,
"trace": "actionpack (5.0.0.1) lib/abstract_controller/base.rb:188:in`process_action'"
}
]
}
}

@athix

This comment has been minimized.

Contributor

athix commented Aug 31, 2016

Thanks! If you want to shorten the post, it looks like all the pertinent information is inside id's 0-2.
app/controllers/api/v1/sessions_controller.rb:6
I'll try and dig around in there and see what I find.

Edit: Are you sure that @pass is being set? It seems like our tests are using params[:password]

lib/sorcery/controller.rb#L33
lib/sorcery/model.rb#L101

Edit 2: Which line exactly is line 6 in your controller? If it's pointing at a specific function that could also help narrow down the exact issue.

@alextab93

This comment has been minimized.

alextab93 commented Aug 31, 2016

def create
puts "#{@pass} is the content of @pass"
@user = login(params[:email], @pass) -> line 6
if @user
@token = @user.get_token.token
else
renderJson(:unprocessable, errors: ["Credenciales Invalidas"])
end
end

@pass is set, you can see the puts.

app/controllers/api/v1/sessions_controller.rb:7:in `create'
Started POST "/api/v1/sessions" for 186.170.82.243 at 2016-08-31 08:49:02 +0000
Processing by Api::V1::SessionsController#create as JSON
Parameters: {"email"=>"sorcery", "password"=>"[FILTERED]", "session"=>{"email"=>"sorcery", "password"=>"[FILTERED]"}}

'sorcery' is the content of @pass ->>> HERE THE PUTS OF @pass

Completed 500 Internal Server Error in 4ms (ActiveRecord: 0.0ms)

@alextab93

This comment has been minimized.

alextab93 commented Aug 31, 2016

I found the problem, when you initialize a Rails 5 project with the flag --api doesn't works the core sorcery methods.

@alextab93 alextab93 closed this Sep 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment