Last active
August 7, 2017 08:05
-
-
Save okliv/dbdcbb52076beaa9523ea972ca301203 to your computer and use it in GitHub Desktop.
Changes to get trestle auth plugin work with Administrator < Sequel::Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: app/helpers/trestle/auth/user_helper.rb | |
def avatar_for(user) | |
- avatar { instance_exec(user, &Trestle.config.auth.avatar) } if Trestle.config.auth.avatar | |
+ Trestle::ApplicationController.helpers.avatar { instance_exec(user, &Trestle.config.auth.avatar) } if Trestle.config.auth.avatar | |
end | |
end | |
Index: app/views/trestle/auth/_userbox.html.erb | |
<div class="userbox pull-right dropdown"> | |
<%= link_to "#", class: 'dropdown-toggle', data: { toggle: 'dropdown' } do %> | |
<span class="name"> | |
- <%= format_user_name(current_user) %> | |
+ <%= ApplicationController.helpers.format_user_name(current_user) %> | |
<span class="caret"></span> | |
</span> | |
- <%= avatar_for(current_user) %> | |
+ <%= ApplicationController.helpers.avatar_for(current_user) %> | |
<% end %> | |
<ul class="dropdown-menu dropdown-menu-right"> | |
Index: lib/trestle/auth/configuration.rb | |
} | |
option :avatar, ->(user) { | |
- gravatar(user.email) | |
+ ApplicationController.helpers.gravatar(user.email) | |
}, evaluate: false | |
option :locale, ->(user) { | |
Index: lib/trestle/auth/controller_methods.rb | |
def current_user | |
@current_user ||= begin | |
if session[:trestle_user] | |
- Trestle.config.auth.user_scope.find_by(id: session[:trestle_user]) | |
+ Trestle.config.auth.user_scope.find(id: session[:trestle_user]) | |
elsif Trestle.config.auth.remember.enabled && token = cookies.signed[:trestle_remember_token] | |
user = Trestle.config.auth.remember.authenticate(token) | |
login!(user) if user | |
Index: lib/trestle/auth/model_methods.rb | |
module ClassMethods | |
def authenticate(identifier, password) | |
- user = find_by(Trestle.config.auth.authenticate_with => identifier) || NullUser.new | |
+ user = find(Trestle.config.auth.authenticate_with => identifier) || NullUser.new | |
user.authenticate(password) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in addition i had to add this sequel plugin https://github.com/mlen/sequel_secure_password to my application (and init it for Administrator model with
plugin :secure_password
) and define emptyhas_secure_password
class method (to eliminate trestle-auth's NoMethodError exception)i think, it better has to be managed at trestle-auth plugin side