Skip to content

Commit

Permalink
Merge pull request #2 from Mehonoshin/master
Browse files Browse the repository at this point in the history
Возможность входа по моделям с отличным от User названием
  • Loading branch information
divineforest committed Mar 22, 2013
2 parents 81840ee + 742c878 commit 78df390
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/dev_log_in_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class DevLogInController < ApplicationController
class DevLogInController < ActionController::Base

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"
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -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 78df390

Please sign in to comment.