Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Возможность входа по моделям с отличным от User названием #2

Merged
merged 2 commits into from

2 participants

@Mehonoshin
  • не наследуем коллбеки от ApplicationController, тк среди них могут быть те, которые проверяют аутентификацию и не дадут гему работать
@divineforest divineforest merged commit 78df390 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 21, 2013
  1. @Mehonoshin
  2. @Mehonoshin

    Inherit DevLogInController directly from ActionController::Base to pr…

    Mehonoshin authored
    …event inheriting authentication before_filters from ApplicationController
This page is out of date. Refresh to see the latest.
View
4 README.md
@@ -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:
View
5 app/controllers/dev_log_in_controller.rb
@@ -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"
View
2  config/routes.rb
@@ -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
Something went wrong with that request. Please try again.