Permalink
Browse files

Authentication by model with name other, than User

  • Loading branch information...
1 parent 81840ee commit 21529f34de3bd5caee17fad56d3457202483a224 @Mehonoshin Mehonoshin committed Mar 21, 2013
Showing with 7 additions and 2 deletions.
  1. +4 −0 README.md
  2. +2 −1 app/controllers/dev_log_in_controller.rb
  3. +1 −1 config/routes.rb
View
@@ -12,6 +12,10 @@ or
/dev/log_in/admin for "admin@*.*"
```
+
+Go to http://myproject.local/dev/log_in/john/admin to log in, if your
+model has a different from User name
+
# Installation
Just add to your Gemfile:
@@ -2,7 +2,8 @@ class DevLogInController < ApplicationController
def log_in
if Rails.env.development? || Rails.env.test?
- user = User.where(User.arel_table[:email].matches("#{params[:login]}@%")).first!
+ model_class = params[:model].present? ? params[:model].classify.constantize : User
+ user = model_class.where(model_class.arel_table[:email].matches("#{params[:login]}@%")).first!
sign_in_and_redirect(user)
else
raise "Works only in development or test env"
View
@@ -1,5 +1,5 @@
Rails.application.routes.draw do
- get 'dev/log_in/:login' => "dev_log_in#log_in"
+ get 'dev/log_in/:login(/:model)' => "dev_log_in#log_in"
end

0 comments on commit 21529f3

Please sign in to comment.