Skip to content

Commit

Permalink
Authentication by model with name other, than User
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehonoshin committed Mar 21, 2013
1 parent 81840ee commit 21529f3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -12,6 +12,10 @@ or
/dev/log_in/admin for "admin@*.*" /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 # Installation


Just add to your Gemfile: Just add to your Gemfile:
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/dev_log_in_controller.rb
Expand Up @@ -2,7 +2,8 @@ class DevLogInController < ApplicationController


def log_in def log_in
if Rails.env.development? || Rails.env.test? 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) sign_in_and_redirect(user)
else else
raise "Works only in development or test env" raise "Works only in development or test env"
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
@@ -1,5 +1,5 @@
Rails.application.routes.draw do 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 end

0 comments on commit 21529f3

Please sign in to comment.