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

How to add another parameter to validate a user? #1162

Closed
newfylox opened this issue May 4, 2018 · 3 comments
Closed

How to add another parameter to validate a user? #1162

newfylox opened this issue May 4, 2018 · 3 comments

Comments

@newfylox
Copy link

newfylox commented May 4, 2018

Hi guys,

I'm looking for a simple solution to add another parameter with email to register a user or find a user. Right now find_resource is only using email but I would like to do something like this

where(email: my_email, my_param: my_other_param)

so it would be a where clause on email AND my_param for every calls (register, login, logout, etc.)

Or a better solution would be to override that line

validates :email, uniqueness: { scope: :provider }, on: :create, if: :email_provider?

to make sure it's uniqueness with provider AND my_other_param.

I was thinking about relying on another column instead of email like username (so I would concatenate email and my_other_param as a username but it seems it does that validation before using my username. Am I wrong?

I don't want to override all the controllers or copy a whole file from your gem because I want to be sure that every time I update your gem, I stay up to date.

Thanks!

@MaicolBen
Copy link
Collaborator

Well, you can return false in email_provider?, and do your own validation. This isn't a login with multiple fields, it's more a special case, and this gem is already overloaded with special cases.

Let me know if I can help you in another way.

@newfylox
Copy link
Author

newfylox commented May 22, 2018

Welll to be honest, I would like a way to override that part

https://github.com/lynndylanhurley/devise_token_auth/blob/master/app/controllers/devise_token_auth/concerns/resource_finder.rb#L29

resource_class.where(MY_CUSTOM_CLAUSE).where(q, value).first

I would like to add another where clause based on a custom field (that could have been set in the initializer for example). I would like to override find_resource in a easy way. I would like to make that change permanent (not only when logging but also registering, token, reset password, etc.)

@MaicolBen
Copy link
Collaborator

@newfylox Sorry for the delay, you can override find_resource entirely. I don't see another easy way to do it

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

No branches or pull requests

2 participants