CARVIEW |
Every repository with this icon (

Every repository with this icon (

Description: | A simple model based ruby authentication solution. edit |
-
Love your work. Incredibly useful.
Some suggested features and/or tutorials:
Users creates a session before creating their account, and retains their session data through the process. For example, user adds items to shopping cart before creating account, then creates account in order to buy.
System sends confirmation email to user when they create account. User clicks link in confirmation email to complete account registration process.
User edit page asks for old password before allowing user to create new password.
Comments
-
Does Authlogic could to working with Mongomapper (a wrapper to MongoDB)?
https://railstips.org/2009/6/27/mongomapper-the-rad-mongo-wrapper
Comments
activestylus Fri Sep 11 04:26:00 -0700 2009 | link
It doesnt work right now, would be cool if it did!
vicentemundim Fri Nov 13 08:09:08 -0800 2009 | link
+1 This would be really great
-
https://github.com/binarylogic/authlogic/blob/81af95e639570822667ec817f42aaad54f8865ed/lib/authlogic/random.rb#L16
By default SecureRandom [1] uses 16 bytes (which has an entropy of 128 bits [2]), so:
SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
should be:
SecureRandom.base64().tr('+/=', '-_ ').rstrip
[1] https://api.rubyonrails.org/classes/ActiveSupport/SecureRandom.html#M001107
[2] https://bitbucket.org/ares/cryha/src/tip/doc/sym_crypto.txt#cl-113
https://github.com/binarylogic/authlogic/blob/81af95e639570822667ec817f42aaad54f8865ed/lib/authlogic/random.rb#L11
SecureRandom.hex(64)
Why do use 64 bytes?
It shoulds be
SecureRandom.hex()
which uses 16 random bytes to return them into a hexadecimal string.
Use hash instead of encrypted
Another thing. I've seen that it's used 'encrypted' or 'crypted' to refer to the hashs. An hash is not a cryptographic algorithm, they are both different. Please use 'hash' to refer a SHA and any term related to crypto. to refer to AES.
Comments
thedarkone Thu Jul 23 10:10:35 -0700 2009 | link
Hey kless,
I wrote the code in question. Good call with
rstrip
instead ofstrip
. I also kinda missed thatSecureRandom
already does.delete("\n")
, so that is also redundant. The reason I only use 15 bytes is because I wanted to be fully compatible with the previous ad-hoc implementation that always produced 20 character tokens.Same thing with
hex_token
, the original implementation returned 64 bytes (128 characters).Hi thedarkone,
thanks for contributing to this great plugin. This is the great thing respect to open software; whatever person to can check the code and make it better. In my case I know anything about security and I'm very strict respect to it.
Today it's very common (and recommended) to use an entropy of 128 bits (16 bytes) which it's used too in the initialization vectors (IV) of criptogaphic algorithms, and I'm sure that it's by that reason because SecureRandom returns 16 bytes by default.
So, at least for me, I think that the security is more important that the compatibility, and in this case I think that the change doesn't hurts.
In the next documents is explained any basic things about criptography and hashes:
https://bitbucket.org/ares/cryha/src/tip/doc/hash.txt
https://bitbucket.org/ares/cryha/src/tip/doc/sym_crypto.txtGreetings!
-
Store bytes instead of string encoded in hexa./base64
0 comments Created 4 months ago by klessThe salt is being saved in base64 getting 22 chars but If it's stored as bytes strings it were only 16 chars. The difference is very great when you have 100K o 1M of users.
The same happens with the hashes which are being saved in hexadecimal, althought the difference is a lot of great.
Digest::SHA512.hexdigest => 128 chars.
instead of
Digest::SHA512.digest => 64 chars.
Comments
-
Login authentication encounters an error running Passenger 2.1.2 and Rails 2.3.3
2 comments Created 4 months ago by jdutilI am not sure if this bug is related to authlogic not being compatible with rails 2.3.3 or not, but I encounter an undefined method 'rewind' for # error when attempting to login using authlogic. This only occurs for me when attempting to use Rails 2.3.3. Once I switch back to 2.3.2 everything works fine. Here is a backtrace:
Status: 500 Internal Server Error undefined method `rewind' for #<TCPSocket:0x2536630>
/Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/request.rb:150:in `POST' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/methodoverride.rb:15:in `call' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/params_parser.rb:15:in `call' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/session/cookie_store.rb:93:in `call' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/reloader.rb:29:in `call' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/failsafe.rb:26:in `call' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `call' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `synchronize' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `call' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/dispatcher.rb:106:in `call' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/rack/request_handler.rb:65:in `process_request' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/abstract_request_handler.rb:197:in `main_loop' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/railz/application_spawner.rb:340:in `start_request_handler' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/railz/application_spawner.rb:298:in `handle_spawn_application' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/utils.rb:176:in `safe_fork' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/railz/application_spawner.rb:296:in `handle_spawn_application' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/abstract_server.rb:332:in `__send__' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/abstract_server.rb:332:in `main_loop' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/abstract_server.rb:182:in `start_synchronously' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/abstract_server.rb:149:in `start' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/railz/application_spawner.rb:192:in `start' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/spawn_manager.rb:260:in `spawn_rails_application' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/abstract_server_collection.rb:121:in `lookup_or_add' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/spawn_manager.rb:254:in `spawn_rails_application' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/abstract_server_collection.rb:75:in `synchronize' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/abstract_server_collection.rb:74:in `synchronize' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/spawn_manager.rb:253:in `spawn_rails_application' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/spawn_manager.rb:148:in `spawn_application' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/spawn_manager.rb:285:in `handle_spawn_application' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/abstract_server.rb:332:in `__send__' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/abstract_server.rb:332:in `main_loop' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/lib/phusion_passenger/abstract_server.rb:182:in `start_synchronously' /Library/Ruby/Gems/1.8/gems/passenger-2.1.2/bin/passenger-spawn-server:50
Comments
-
I can't seem to find any information in the docs on how to remove the "_ is not valid" validations on the user session fields. generalize_credentials_error_messages did not seem to return the results I was looking for. Is there a way to remove the validations completely for email/login/password and only use the validates_presence_of. Thank you.
Comments
-
Comments
-
It would be really great with a dead simple example showing how to create an Authlogic "add on".
Comments
-
@Ben Johnsonxfrom-lighthousex|S| newx
Hi
With 2.3.3 I started to see strange ’A copy of ApplicationController has been removed from the module tree but is still active!’ errors every few requests. Switching back to 2.3.2 removed the problem.
I think I was able to locate the problem somewhere within authlogic.
It might have something to do with this outstanding ticket (https://rails.lighthouseapp.com/projects/8994/tickets/1339-arbase-should-not-be-nuking-its-children-just-because-it-lost-interest), but so far I haven’t seen any activity in it.
The problem can be reproduced by fetching my fork of the authlogic example application:
- https://github.com/retoo/authlogic_example/tree/rails233bug
- cp config/database.yml{-bug-example,} (or use your own, shoudln’t matter)
- rake db:migrate
- start server
- register a user
- fetch the page right after the registration (users/show) repeatedly and fast (keep reload button pressed)
- The error should occour withhin 10-30 requests,
Now if you like you can switch back to 2.3.2 and repeat the test, with 2.3.2 nothing happens.
Attached you can find the full backtrace.
Thanks!
Cheers,
RetoThis ticket has 1 attachment(s).
Comments
binarylogic Fri Aug 07 15:10:23 -0700 2009 | link
rails 2.3.3 problem ’ApplicationController removed from tree but still active ’
I used git bisect to locate the change within rails, and it looks like its the following change. Ben, can you judge if this is really authlogic fault or not? I think you just trigger it...
bc2c4a4 is first bad commit
commit bc2c4a4
Author: Hongli Lai (Phusion) hongli@phusion.nl
Date: Mon Jul 6 14:11:28 2009 +0200Cleanup application after #close has been called on the Rack response body, not when AC::Reload#call is done. The Rack body might lazily evaluate its output, which is for example the case if one calls ’render :text => lambda { ... }’. The code which lazily evaluates the output might use other application classes. So we will want to defer cleanup until the Rack request is completely finished. Signed-off-by: Michael Koziarski <michael@koziarski.com>
:040000 040000 da0577a a75eb4b M actionpack
by Reto
binarylogic Fri Aug 07 15:10:25 -0700 2009 | link
rails 2.3.3 problem ’ApplicationController removed from tree but still active ’
Alright, looking for this commit id revealed the following two lighthouse tickets:
- https://rails.lighthouseapp.com/projects/8994/tickets/2873-application-reloading-should-be-deferred-to-end-of-request-currently-interferes-with-render-text-lambda-streaming
- https://rails.lighthouseapp.com/projects/8994/tickets/2948-exception-a-copy-of-actorscontroller-has-been-removed-from-the-module-tree-but-is-still-active
Which in turn shows to be fixed in https://github.com/rails/rails/commit/d37ac7958fc88fdbf37a8948102f6b4e45c530b3.
>Hmm, I think you can close this bug.. but I fear for me 2.3.3 is broken :(.
by Reto
-
@Ben Johnsonxerrorsxfrom-lighthousexvalidationx|S| newx
My User class has a boolean field named "enabled". I’d like to prevent the login if that field is set to false. I found here an example code:
https://rdoc.info/rdoc/binarylogic/authlogic/blob/72992b9effaea12f109465fc904fa5431538775a/Authlogic/Session/Validation/Errors.htmlclass UserSession
validate :check_if_awesome private def check_if_awesome errors.add(:login, "must contain awesome") if login && !login.include?("awesome") errors.add(:base, "You must be awesome to log in") unless attempted_record.awesome? end
end
that I’ve adapted into this:
class UserSession < Authlogic::Session::Base
validate :check_if_user_enabled private def check_if_user_enabled debugger # User.find_by_login(object.login).enabled end
end
so, why does UserSession doesn’t inherit from Authlogic::Session::Base ?
Moreover, using the debugger I can’t see the "errors" object, I can only access to it by "object.errors".so, if I’m not doing anything wrong, the problem in this ticket should only be about syncing this to the documentation.
Maurizio De Magnis
This ticket has 0 attachment(s).
Comments
binarylogic Fri Aug 07 15:10:57 -0700 2009 | link
custom validation
Shame on me, it seems that only in the debugger context "errors" and the other fields are accessible through "object"..
by maurizio.demagnis (at gmail)
-
@Ben Johnsonxfrom-lighthousex|S| newx
I have a fairly generic setup of Authlogic using all defaults against a User table in my primary DB.
I have a 2nd separate database setup in my database.yml/models ala something like..
In database.yml ... a second_db entry
In an example model...
class ModelInOtherDB < ActiveRecord::Base
establish_connection :second_db ... endWhenever I use this MonelInOtherDB .. it works but when I reload the authlogic tries hitting the 2nd database not the primary DB with the User in it and faults with a ...
Could not find table ’user’ error
Authlogic(2.1.1)
Ruby version 1.9.1 (i386-darwin9.6.0)
RubyGems version 1.3.3This ticket has 0 attachment(s).
Comments
-
@Ben Johnsonxcookiesxfrom-lighthousexsessionx|S| openx
View
@@@ - if current_user %p= "Signed in as " << current_user.email << "!" %p= current_user_session.remember_me? - else %h1 Login %p
- form_for :login_info, :url => login_path do |f| = f.label :email = f.text_field :email = f.label :password = f.password_field :password = f.submit "Submit" = f.check_box :remember_me = f.label :remember_me
@@@
Controller
@@@ class UserSessionsController < ApplicationController
before_filter :require_no_user, :only => :create before_filter :require_user, :only => :destroydef create
user_session = UserSession.new(params[:login_info]) if user_session.save flash[:notice] = "Logged in!" redirect_to home_path else flash[:error] = "Error: Login unsuccessful!" redirect_to home_path end
end
def destroy
current_user_session.destroy flash[:notice] = "Logged out!" redirect_to home_path
end end
@@@Problem
Now when I login with the option ’Remember me?’ checked, Rails passes:
@@@ Processing UserSessionsController#create (for 127.0.0.1 at 2009-07-11 03:39:15) [POST]
Parameters: {"commit"=>"Submit", "action"=>"create", "controller"=>"user_sessions", "login_info"=>{"password"=>"[FILTERED]", "remember_me"=>"1", "email"=>"c00lryguy@gmail.com"}} @@@But the View displays:
@@@ Signed in as c00lryguy@gmail.com!
false
@@@No matter how hard I try I can’t get the current_user_session to remember the remember_me option.
This ticket has 0 attachment(s).
Comments
binarylogic Fri Aug 07 15:11:46 -0700 2009 | link
:remember_me option not saving with UserSession.new
That’s strange. The remember_me feature uses a cookie. Are you sure that cookies are properly being created? Try doing a simple test where you expire a cookie in the future, close your browser, and see if you can still retrieve that cookie. I can’t tell you how many times people have an issue with authlogic when their cookies aren’t working properly.
I’m using the remember_me function on a number of sites I manage and all are working great.
Hope this helps.
by Ben Johnson
binarylogic Fri Aug 07 15:11:55 -0700 2009 | link
:remember_me option not saving with UserSession.new
While logged with with the Remember me? option checked, I viewed my cookies in Firefox and there’s nothing no ’remember_me’ cookie. I see no reason why it wouldn’t create the ’remember_me’ cookie since it also creates session and user_credentials cookies.
by c00lryguy
binarylogic Fri Aug 07 15:11:58 -0700 2009 | link
:remember_me option not saving with UserSession.new
Do you have some sort of example app using the remember_me option?
by c00lryguy
binarylogic Fri Aug 07 15:12:00 -0700 2009 | link
:remember_me option not saving with UserSession.new
I’m having the same problem here but I can get the remember_me to be true on the current_user_session.
I don’t have any remeber_me cookie created either.... will keep work on it...
Thanks
by Philippe René
binarylogic Fri Aug 07 15:12:04 -0700 2009 | link
:remember_me option not saving with UserSession.new
I have a related problem that is puzzling me.
I decided to keep things simple and have every session ’remembered’. I added a line to my UserSession model:
class UserSession < Authlogic::Session::Base
remember_me true endThis works great in development, but doesn’t seem to work in production. I see the cookie, but it is set to expire at the end of the browser session.
Any thoughts??
Thanks
by Phil McT
binarylogic Fri Aug 07 15:12:06 -0700 2009 | link
:remember_me option not saving with UserSession.new
Sorry, the code snipped there is:
@@@ class UserSession < Authlogic::Session::Base remember_me true end @@@
by Phil McT
binarylogic Fri Aug 07 15:12:10 -0700 2009 | link
:remember_me option not saving with UserSession.new
Oh for an post edit feature!!
Last try:
@@@ class UserSession < Authlogic::Session::Base remember_me true end
@@@by Phil McT
binarylogic Fri Aug 07 15:12:14 -0700 2009 | link
:remember_me option not saving with UserSession.new
I messed around for a bit. Looks like unpacking the gem fixed the problem. My host has authlogic installed, looks like the same version, so I don’t know exactly what happened. But it’s working for me now.
Thanks for the plugin, cool stuff.
by Phil McT
-
from-lighthousex|S| newx
I’m using authlogic_openid version 1.0.4 because of problems with the current version of authlogic_openid. The error exists in the demo at https://authlogicexample.binarylogic.com/ as well.
Visit the demo. Enter https://google.com (or some other non-OpenID aware URL).
The problem is that the save block never gets yielded to. Here is the Mongrel output from my development environment:
[OPENID] No usable OpenID services were found for "https://google.com/"A similar problem exists when a URL to a non-existing server is entered:
[OPENID] Failed to fetch identity URL https://b.com/ : Error fetching https://b.com/: getaddrinfo: Name or service not knownBest,
Daniel
This ticket has 0 attachment(s).
Comments
binarylogic Fri Aug 07 15:12:39 -0700 2009 | link
Authlogic_openid fails with URL that doesn’t lead to an OpenID aware server
I have similar bug.
by petRUShka
-
@Ben Johnsonxfrom-lighthousexhttp_basic_authenticationx|S| newx
HTTP Basic authentication works when going through curl, but not when using a browser (safari or firefox). In firefox, the attached dialog shows up. This happens in all of my projects using authlogic and the authlogic_example application from github. It’s the same whether I use mongrel or passenger.
This ticket has 2 attachment(s).
Comments
It's because when you doing the request using curl, curl is sending the username and password in the request headers and not in the url. To make it work in the browser you also have to send it in the headers like "Authorization: Basic Z3VzdGF2OmZvb2Jhcg==" where the username and password is Base64 encoded.
-
@Ben Johnsonxfrom-lighthousex|S| openx
I added a translations file for AuthLogic to my rails app. This correctly resulted in error messages for users being translated into the default locale. However, when I change the locale in a before filter, AuthLogic keeps returning error messages in the default locale while AR starts providing validation errors in the current locale. It seems like the call to I18n translate (t) is being made only once with the default locale when the AuthLogic gem is loaded.
This ticket has 0 attachment(s).
Comments
binarylogic Fri Aug 07 15:13:17 -0700 2009 | link
I18n locale changes work for AR but not AL
I see what you are saying. This should only be an issue for configuration items. What I’ll do instead is store the key and have authlogic process this upon request.
by Ben Johnson
binarylogic Fri Aug 07 15:13:20 -0700 2009 | link
I18n locale changes work for AR but not AL
Could you give an update on the status of this bug? I’m having similar problems.
by Tom-Eric
robeastham Tue Oct 06 11:44:37 -0700 2009 | link
I think I've run into this too. Any news?
Would very much like you to implement this behaviour as well
-
@Ben Johnsonxauthlogici18nxdocumentationxfrom-lighthousexi18nxrdocx|S| newx
Hey there.
Ran into a couple of problems customising the error messages that Authlogic raises using the I18n functionality, stemming from a couple of inaccuracies in your RDOC.
Firstly, this example (from https://rdoc.info/rdoc/binarylogic/authlogic/blob/81af95e639570822667ec817f42aaad54f8865ed/Authlogic/I18n.html):
>START CODE
module MyAuthlogicI18nAdapter
def t(key, options = {})
# you will have key which will be something like: "error_messages.password_invalid" # you will also have options[:default], which will be the default english version of the message # do whatever you want here with the arguments passed to you.
end
end
Authlogic::I18n.extend MyAuthlogicI18nAdapter
END CODE
..contains a subtle misunderstanding of how Object#extend works, and of Ruby’s OO semantics in general. In a nutshell, extend places the module with which your object is being extended in the inheritance tree above it, rather than overriding the methods on the object itself (The object in this place being the Authlogic::I18n singleton class). In practical terms, this means that if your object already has a method of the same name as one defined by the module (as is true in this case - Authlogic::I18n defines its own self.t method), the object’s own implementation will still be called, as it is lower down in the inheritance tree than that in the module with which it is being extended.
However, this is pretty much a moot point, as, looking at the source in i18n.rb - the built-in Authlogic::I18n.t attempts to call the t method on a top-level class called I18n, so a simpler method of overriding auth messages is simply to define that top-level I18n class itself, with a t method (no need for that extend). As a further improvement, i might suggest making this top-level classname configurable, as I18n seems pretty generic and potentially prone to namespace clashes. However, if the documentation for this feature could be updated to correct this, that’d be great.
Cheers!
Tim
This ticket has 0 attachment(s).
Comments
-
@Ben Johnsonxfrom-lighthousexi18nx|S| newx
Hello, I think there still are some keys missing.
I can’t translate during validation :
model names :
user_session user
attributes :
all the attributes for user
The rest is working just fine.
I’m using the latest gem.
This ticket has 0 attachment(s).
Comments
binarylogic Fri Aug 07 15:14:10 -0700 2009 | link
some i18n keys missing?
My locale file looks like this :
@@@ fr:
authlogic:error_messages: login_blank: ne peut ĂŞtre vide login_not_found: n’existe pas login_invalid: ne doit utiliser que des lettres, des chiffres, des espaces et .-_@ consecutive_failed_logins_limit_exceeded: Trop d’Ă©checs d’authentification consĂ©cutifs, le compte est dĂ©sactivĂ©. email_invalid: "doit ressembler Ă une adresse email. Ex : votre-nom@lefigaro.fr" password_blank: ne peut ĂŞtre vide password_invalid: n’est pas valide not_active: Votre compte n’est pas actif not_confirmed: Votre compte n’est pas validĂ© not_approved: Votre compte n’est pas approuvĂ© no_authentication_details: Vous n’avez fourni aucune information permettant votre authentification models: user_session: UserSession user: User attributes: user_session: username: le nom d’utilisateur login: le nom d’utilisateur email: l’email password: le mot de passe remember_me: "se souvenir de moi" user: username: le nom d’utilisateur email: "l’email" password: le mot de passe
@@@
My two AuthLogic related models are :
UserSession & User
by Benoit B.
fadhlirahim Wed Oct 14 06:23:24 -0700 2009 | link
Hi, I have also having trouble with model: user_session translation.
It seems that it does not want to translate user_session at all.
I am using Rails2.3.4 & Ruby1.9
-
@Ben Johnsonxauthlogicxfrom-lighthousexstix|S| openx
Using authlogic with models that extend the User class (using Single Table Inheritance)
seems to break things since you end up with nil objects for @current_user in your controllers@@@ ruby class User < ActiveRecord::Base
acts_as_authentic
end
class NormalUser < User;end
class SpecialUser < User;end
@@@Is it possible to use authlogic with STI?
This ticket has 0 attachment(s).
Comments
binarylogic Fri Aug 07 15:14:29 -0700 2009 | link
Using authlogic with STI User models
I’m not sure, but I dont think it would be difficult to support. What are the specific errors?
by Ben Johnson
binarylogic Fri Aug 07 15:14:32 -0700 2009 | link
Using authlogic with STI User models
I’m using authlogic with STI right now and everything seems to work fine under development, but when I run it in production mode and attempt to update a model, this is what I get:
NoMethodError (undefined method `=’ for #<Patient:0xb34032c>): authlogic (2.1.1) [v] lib/authlogic/acts_as_authentic/password.rb:229:in `send’ authlogic (2.1.1) [v] lib/authlogic/acts_as_authentic/password.rb:229:in `password=’
Here’s the current setup for the models:
class User < ActiveRecord::Base acts_as_authentic end class Patient < User;end class Doctor < User;end
I looked at the password method, but I’m not sure what is happening or what to look for, is authlogic actually passing the whole model to the password method. Any help would be much appreciated.
Thanks!
- Vannby Vann
binarylogic Fri Aug 07 15:14:39 -0700 2009 | link
Using authlogic with STI User models
It looks like:
Patient.crypted_password_field
Is returning nil. What does Patient.column_names return for you?
by Ben Johnson
binarylogic Fri Aug 07 15:14:44 -0700 2009 | link
Using authlogic with STI User models
Here’s what it returns:
>> Patient.column_names
Patient Columns (3.2ms) SHOW FIELDS FROM `users` => ["id", "login", "name", "email", "crypted_password", "salt", "created_at", "updated_at", "remember_token", "remember_token_expires_at", "first_name", "last_name", "ssn", "address", "city", "state", "zip", "drivers_license", "home_phone", "cell_phone", "fax", "employer", "insurance_co", "insurance_type", "insurance_id", "allergies", "medications", "operations", "chronic_conditions", "family_history", "immunizations", "visits_count", "appointments_count", "login_count", "getting_started", "type"]
by Vann
I was about to use STI user models too, but don't really looking for trouble right now. What's the status on this? 8)
@binarylogic what version of rails are you using? I am using authlogic with STI and it works beautifully on rails 2.3.2.
Actually there is one thing that I am having trouble with and that is the password reset feature when using STI. It wants the param user. However my params for :user are nil. If I change to the appropriate STI class name it works fine but I have multiple STI sub class names. Any idea how I would fix that?
Thanks to rsl, he showed me https://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002334. In the form_for rather than using @user use @user.becomes(User) and it works beautifully again. Thanks again rsl.
-
The regex in regex.rb for the login field currently is:
/\A\w[\w.+-_@ ]+\z/
This requires the login field to be a minimum of two characters. Shouldn't the first \w be removed or the + be changed to a *? I figure it makes most sense to remove the \w.
Comments
josephruscio Sun Nov 08 13:19:43 -0800 2009 | link
It also allows both the '+' and even worse a ' ' in any other character except the first. So "joe+ + +" is a valid user name.
-
HTTP Basic Auth Fails if "logout_on_timeout true"
2 comments Created 3 months ago by jnimetyIf I enable logout_on_timeout and try to use HTTP Basic Auth then Authlogic will not validate the session (JosUserSession.find.record returns nil)
User and UserSession models below. I'm using the the ApplicationController methods as shown in the tutorials.
class UserSession < Authlogic::Session::Base login_field :username verify_password_method :valid_credentials? logout_on_timeout true allow_http_basic_auth true end class User < ActiveRecord::Base acts_as_authentic do |c| c.validate_password_field = false c.login_field = :username c.logged_in_timeout = 30.minutes end def valid_credentials?(password_plaintext) valid_jos_user_credentials?(password_plaintext) end def valid_jos_user_credentials?(password_plaintext) salt = password.split(':')[1] encrypted = Digest::MD5.hexdigest("#{password_plaintext}#{salt}") password.eql? "#{encrypted}:#{salt}" end end
Comments
Yes I have had this problem too, HTTP auth will work in this situation if you create a session by logging in through the web application, but when the session times out due to logout_on_timeout, it prevents further HTTP auth. Haven't had time yet to diagnose the issue.
I ran into this issue with a single_access_token...
in lib/sessions/timeout.rb, you need to replace:
before_persisting :reset_stale_state after_persisting :enforce_timeout
with
before_persisting :reset_stale_state, :unless => :single_access? after_persisting :enforce_timeout, :unless => :single_access?
I was going to open another issue for this... but I bet this will also fix this basic http auth issue
-
I change a user's password through the console, then reload that user and the valid_password? returns false for the new password.
Any ideas where to look from here before I end up deep into the authlogic code?
Here's a console dump:
?> u.password = "foobar" => "foobar"
u.password_confirmation = "foobar" => "foobar" u.save! => true u.reload => # u.valid_password?("foobar") => false
Comments
-
Is there an easy way to merge validation options for all validations? I would like to disable validations when a user is registered as a guest and currently have to do this.
acts_as_authentic do |c| c.merge_validates_confirmation_of_password_field_options :unless => :guest? c.merge_validates_length_of_password_field_options :unless => :guest? c.merge_validates_length_of_password_confirmation_field_options :unless => :guest? c.merge_validates_length_of_login_field_options :unless => :guest c.merge_validates_format_of_login_field_options :unless => :guest c.merge_validates_uniqueness_of_login_field_options :unless => :guest c.merge_validates_format_of_email_field_options :unless => :guest c.merge_validates_length_of_email_field_options :unless => :guest c.merge_validates_uniqueness_of_email_field_options :unless => :guest end
It would be nice if there was one
merge_validation_options
config method which merged all of them. Or is there a better way to do this?Comments
binarylogic Thu Aug 27 22:55:32 -0700 2009 | link
Hey Ryan, there was in v1, but I decided to kind of start with a clean slate with v2. I've yet to come up with a nice way to hook into authlogic's validations and easily change the options. This, in my opinion, is the part of authlogic that I do not like. I think the names are way too long. Also, because of this, I made authlogic configurable with a block instead of a hash. I felt this gave you more freedom to elegantly do the things like you are doing above. Ex: loop through options and set them, merge hashes, etc.
Anyways, to answer your question, there isn't anything currently built into authlogic to do this. I planned to do some clean up with authlogic in the next few weeks. Part of that cleanup was going to be this, as well as looking at a way to integrate with DataMapper. That also effect how validations are configured since both AR and DataMapper accept different options.
-
to add email field do i just modify create_users.rb file and then run migration.Or are there other steps?
sorry I am a complete newbieComments
-
#<AccountSession: no credentials provided> adds errors to the form on :new action
2 comments Created 2 months ago by gavinhughesCreating a new instance automatically loads errors into @base and populates those errors on my sign in form:
(rdb:1) @account_session = AccountSession.new
<AccountSession: no credentials provided>
(rdb:1) @account_session.errors
<Authlogic::Session::Validation::Errors:0x213cc78 @errors={}, @base=#<AccountSession: no credentials provided>>
Is this correct behavior or am I missing something?
Gavin
Comments
You should do something like that:
@account_session = AccountSession.new(:username => 'my_username', :password => 'password')gavinhughes Sat Sep 05 18:33:01 -0700 2009 | link
Doing that on the :new action will populate the form with (incorrect) data, which is not what we want on :new. We want the form to be blank. Calling AccountSession.new(:username => ' ', :password => ' ') gives the same "no credentials..." error. I'm sure the solution is simple, but I don't see it.
-
irb> require 'rubygems' => true irb> require 'authlogic' NameError: uninitialized constant ActiveRecord
from ... from /path/to/authlogic-2.1.1/lib/authlogic/session/validation.rb:16 from ...
Authlogic::Session::Validation::Errors
inherits from::ActiveRecord::Errors
, but norequire "active_record"
can be found in the code and no dependency has been added to the gemspec.Please note: In Rails 3, ActiveRecord::Errors has been moved to ActiveModel, so it might be better to roll your own Errors class.
Comments
-
Hi,
There are problem with UserSessions on rails 2.3.4. code in view like this<% form_for @user_session, :url => login_path do |f| -%>
<%= f.error_messages %> <%= f.text_field :login %> <%= f.password_field :password %> <%= f.check_box :remember_me %> <%= submit_tag 'Login' %> <% end %>causes ActionView::TemplateError (can't convert ActiveRecord::Error into String) on line <%= f.error_messages %>
Comments
It seems I have the same issue.
In my test to check that 'email' is required; I get :
test_should_require_email(UserTest):
ArgumentError: interning empty stringWith 2.3.3, user.errors is:
#<ActiveRecord::Errors:0xb6110164 @errors={"email"=>["est trop court (au moins 6 caractères)", "doit être une adresse électronique (...@...)"]}, @base=#<User ...>>
But with 2.3.4 it becomes:
#<ActiveRecord::Errors:0xb6030c80 @errors={"email"=>[#<ActiveRecord::Error:0xb6030820 @message=:too_short, @type=:too_short, @options={:count=>6}, @attribute=:email, @base=#<User ...>>, #<ActiveRecord::Error:0xb603058c @message="doit être une adresse électronique (...@...)", @type=:invalid, @options={:value=>nil}, @attribute=:email, @base=#<User ...>>]}, @base=#<User ...>>
So instead of a message/string, we get an Error instance.
-
It is missing there.
Comments
-
the template is not valid ruby => breaks pre-commit syntax check
0 comments Created 2 months ago by jlecourHi,
I'm a happy user of Authlogic.
In my projects, manaed with Git, I have a pre-commit hook that checks all the modified files to see if they are valid. They go through Ruby or ERB syntax check and the commit is aborted if an error is raised.When I pack my gems in "vendor/gems", they are added to the next commit checked.
This process stumbles upon the session template which ends on *.rb and so is checked by Ruby and so is not valid because it's in fact an ERB template.
Maybe this file could be renamed into something either .erb or .tpl, …
The exact file is : authlogic-2.1.1/generators/session/templates/session.rb
I'll try to fork and make a patch, but I'm not sure that's in my reach ;-)
Thanks for Authlogic and everything else that you make. It's great.
Cheers
JeremyComments
-
Authlogic::Session::Validation::Errors#[] Doesn't funtion as Rails does
0 comments Created 2 months ago by mitchlloydNormally Rails would do this:
@object.errors[:non_existent_attribute] # => nil
Authlogic returns
[]
This is because of the following method:
class Errors < ::ActiveRecord::Errors def [](key) value = super value.is_a?(Array) ? value : [value].compact end end
as an example:
nil.is_a?(Array) ? nil : [nil].compact # => []
This causes issues when using the Formtastic plugin which expects nil when there are no errors for a given attribute.
This would be a fix:
class Errors < ::ActiveRecord::Errors def [](key) value = super return nil if value.is_nil? value.is_a?(Array) ? value : [value].compact end end
Comments
-
generalize_credentials_error_messages with custom string
3 comments Created 2 months ago by moiristoThe doc specifies that instead of the value 'true' a string can be specified like this:
generalize_credentials_error_messages I18n.t('authlogic.error_messages.login_credentials_invalid')
However, this does not seem to work: when passing a string the whole statement is ignored.
Comments
IronDigital Wed Sep 16 06:48:18 -0700 2009 | link
I tested this and it seems to work fine. Did this get fixed and this issue not closed? I don't see a commit that mentions this, so I'm inclined to think it has always worked.
I was experiencing this problem with ruby 1.8.7. Now I've switched to REE 1.8.6 it is indeed working as it should be.
-
Using Ruby 1.9.1 and Rails 2.3.4 i got that error
NoMethodError (undefined method
^' for "a":String):<br/> authlogic (2.1.1) lib/authlogic/session/session.rb:46:in
session_credentials' authlogic (2.1.1) lib/authlogic/session/session.rb:33:inpersist_by_session' authlogic (2.1.1) lib/authlogic/session/callbacks.rb:78:in
persist' authlogic (2.1.1) lib/authlogic/session/persistence.rb:55:inpersisting?' authlogic (2.1.1) lib/authlogic/session/persistence.rb:39:in
find' app/controllers/application_controller.rb:16:in `current_user_session'Comments
This appears to be a Rails 2.3.4 issue. See https://groups.google.com/group/authlogic/browse_thread/thread/519a124e0df73141
-
Security: AuthLogic leaks valid usernames when logging in by default
4 comments Created 2 months ago by jj05AuthLogic helps an attacker by letting them know if a username is valid or not while logging in.
A more secure (but slightly less user-friendly) behavior would be not letting the user know whether the login or password (or both) is wrong.
I think the secure behavior should be enabled by default, and have a configuration parameter to behave in the current mode.
(note that information might also be leaked from the register and forgotten password page)
Comments
IronDigital Wed Sep 16 06:32:36 -0700 2009 | link
I agree with you, so I've forked and changed that default. The configuration option is still the same.
I'll send a pull request and we'll see what BinaryLogic thinks.
Isn't this already supported by setting #generalize_credentials_error_messages in your Session model?
IronDigital Mon Nov 16 06:34:15 -0800 2009 | link
It is, but the argument was that it isn't on by default.
-
Logout works on my local machine (mac os x leopard, rails 2.3.4, mongral) but fails on Production in Heroku. Authlogic is integrated into my app in the same way that the railscast episode on authlogic suggests - the only difference is that I included all of the authlogic database columns.
Comments
-
Authlogic is very great, but I'm not alone being confused by how the act_as_authentic DSL is designed - it's quite confusing as it's not really follow some Ruby patterns. Not a bug but... Example: c.validates_length_of_password_field_options is both a method and a setter, but c.merge_validates_format_of_email_field_options is only a method - very confusing. The first one should be either a property or a method to make the API more clean. Same as perishable_token_valid_for = 5.days, should be perishable_token_valid_for 5.days should not both work. It's too much magic making especially newbies confused. I'm not a newbie, but I tend to check the docs like all the time - the old DSL made a bit more sense.
My point is that too many ways of doing the identical thing leads to "the paradox of choice" which is not good for APIs.
Comments
-
I'm using Authlogic 2.1.2, Shoulda 2.10.2, FactoryGirl 1.2.2.
I included require "authlogic/test_case" in the test_helper.rb
and added the following
class ActionController::TestCase setup :activate_authlogic end
so that it runs before each functional test
Now, A test like the following fails
context "A guest - for an already activated account - " do setup {@user = Factory.create(:activated_user)} context "requesting the activation mail (POST to create)" do setup { post :create, :email => @user.email} should_set_flash_of_to :error, "The account is already activated" should_redirect_to("login_path") { login_path } end end
It fails because there's a user in the session...As you can see, the code above did not login the user created. It just created it.
If I instead remove
class ActionController::TestCase setup :activate_authlogic end
and add the activate_authlogic call right after creating the user, everything works fine.
I've debugged and inspected some code and my observation is that
If you activate_authlogic and then create users, the first user created will have a session without the need to call UserSession.create. This is a wrong behaviorComments
This doesn't seem wrong as much as it seems unexpected especially when your factories are creating users through associations and stuff. Is there any way we could disable session_maintenance temporarily?
This is odd and has certainly caused me some head-scratching (and moderate swearing) this morning. As scudco asks, is there a way to disable this behaviour? What's the rationale for
:activate_authlogic
automatically creating a session?activate_authlogic does not create the session. whenever you create an instance of a model (usually through a factory) that in turn creates a user it will create the UserSession. This is the intended, default behavior of authlogic, but yes it would be nice if it could be disabled for factories or other model creating tools.
Ah, OK scudco, thanks for clarifying that.
You say this is the default behaviour, implying that this is optional? Is there a way I can turn this behaviour off all together? The app I'm currently building doesn't allow for self-registration as it's invite only and so shouldn't have any need for this. I had a look through the docs but couldn't see anything.
Cheers.
I haven't successfully done this, but you can disable session_maintenance. However, I am unsure what disabling this actually does things like persistence_tokens, login attempts, etc. I would give it a shot and see how it goes.
The README says:
Also, sessions are automatically maintained. You can switch this on and off with configuration, but the following will automatically log a user in after a successful registration:User.create(params[:user])
This also updates the session when the user changes his/her password.
and I think it must mean this config option: https://rdoc.info/rdoc/binarylogic/authlogic/blob/0ac308808914e6ddcac8ba26cc8c28d2146597b4/Authlogic/ActsAsAuthentic/SessionMaintenance/Config.html
-
Validation errors "no credentials provided" before .valid? or .save
0 comments Created 2 months ago by jj05AuthLogic doesn't behave like ActiveRecord.
With ActiveRecord, the @errors array is filled only after running .valid? or .save
With AuthLogic it is run automatically and there is no way to disable it.AuthLogic will therefore mark the fields login and password as error. As these are added to the base errors, there's no way to clear those errors. This is especially an issue if AuthLogic is used in conjunction with Formtastic. In that case those fields will always be highlighted as errors.
AuthLogic shouldn't check for errors until the .valid? or .save methods are called.
To reproduce, modify the authlogic example as follows,
class UserSessionsController < ApplicationController def new @user_session = UserSession.new raise @user_session.inspect # will always show an error end end
Comments
-
Redundant validations and unhelpful validations presented to the user
1 comment Created 2 months ago by jj05e.g. when doing a signup, and leaving all the fields blank, the user gets the following errors:
* Password confirmation is too short (minimum is 4 characters) * Password is too short (minimum is 4 characters) * Password doesn't match confirmation * Login is too short (minimum is 3 characters) * Login should use only letters, numbers, spaces, and .-_@ please. * Email is too short (minimum is 6 characters) * Email should look like an email address.
Instead they should be getting:
* Login can't be blank * Email can't be blank * Password can't be blank * Password confirmation can't be blank
Comments
darkhelmet Fri Oct 16 12:54:27 -0700 2009 | link
This is just what I was looking for. Maybe I'll hack it in. It's really only a couple extra options to the validations (I'm assuming there is a validates_foo_of block somewhere...I'll have to look)
-
undefined method `login_changed?' for #<User:0x10324f578> with self.primary_key = 'login"
2 comments Created about 1 month ago by macinuxI got the following error when i use: self.primary_key = 'login" in the user model .
WARNING: Can't mass-assign these protected attributes: login
NoMethodError (undefined method `login_changed?' for #<User:0x10324f578>):
app/controllers/users_controller.rb:12:in `create'
The exception is thrown in the create method (@user.save) when i trying to create a new account:
def create@user = User.new(params[:user]) if @user.save flash[:notice] = "Account registered!" redirect_back_or_default account_url else render :action => :new end end
Thanks,
James
Comments
IronDigital Mon Oct 05 05:33:28 -0700 2009 | link
Why would you do that? Leave the primary key as it was by default. Authlogic has a uniqueness validation on the logic field by default.
-
All fields are shown on serialize (to_xml and to_json, etc)
0 comments Created about 1 month ago by mrflipAll fields in a user object are shown by default, including the persistence-token, crypted password, salt, email address and openid.
You can disable the formatted routes, or you can sanitize these fields by overriding to_xml, to_json, etc to always use the
:only => [...whitelisted fields...]
flag. (The attr_visible plugin https://github.com/mrflip/attr_visible helps implement the latter)
Comments
-
Seems like there are no git tags for any of the released versions on github, make sure to push them with
git push --tags
Comments
-
Impossible to use open_id & oauth extensions at the same time.
0 comments Created about 1 month ago by marcandreIt appears that some extensions are mutually incompatible. I think it is because of the way authlogic is made and not really the extensions' fault (I might be wrong).
The #save scheme with block does not work correctly the way it is now implemented. If you have two extensions that need it (e.g. open_id and oauth extensions), then both extensions will yield to the block. Yielding twice is not the right thing to do (since some logic could be in that block) and will automatically result in (at best) a DoubleRender error.
Maybe authlogic's #save itself should yield to the block; this way the extensions won't have to do it themselves?
Comments
-
undefined method `generate_best_match=' for ActionController::Routing:Module (NoMethodError)
0 comments Created about 1 month ago by NevynxxxGet the following issue with a brand new app on ruby 1.9.1p243 (2009-07-16 revision 24175), and rails 2.3.3, and authlogic 2.1.2.
Steps went:
sudo gem install authlogic
rails authlogic_test
cd authlogic_test/
vim config/environment.rb
added - config.gem "authlogic" set - RAILS_GEM_VERSION = '2.3.3' unless defined? RAILS_GEM_VERSION script/generate session user_session
/home/nevyn/rails/authlogic_test/config/initializers/new_rails_defaults.rb:14:in<top (required)>': undefined method
generate_best_match=' for ActionController::Routing:Module (NoMethodError)from /home/nevyn/.gem/ruby/1.9.1/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:145:in `load' from /home/nevyn/.gem/ruby/1.9.1/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:145:in `block in load_with_new_constant_marking' from /home/nevyn/.gem/ruby/1.9.1/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:521:in `new_constants_in' from /home/nevyn/.gem/ruby/1.9.1/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:145:in `load_with_new_constant_marking' from /usr/lib/ruby19/gems/1.9.1/gems/rails-2.3.3/lib/initializer.rb:622:in `block in load_application_initializers' from /usr/lib/ruby19/gems/1.9.1/gems/rails-2.3.3/lib/initializer.rb:621:in `each' from /usr/lib/ruby19/gems/1.9.1/gems/rails-2.3.3/lib/initializer.rb:621:in `load_application_initializers' from /usr/lib/ruby19/gems/1.9.1/gems/rails-2.3.3/lib/initializer.rb:176:in `process' from /usr/lib/ruby19/gems/1.9.1/gems/rails-2.3.3/lib/initializer.rb:113:in `run' from /home/nevyn/rails/authlogic_test/config/environment.rb:9:in `<top (required)>' from /usr/lib/ruby19/gems/1.9.1/gems/rails-2.3.3/lib/commands/generate.rb:1:in `require' from /usr/lib/ruby19/gems/1.9.1/gems/rails-2.3.3/lib/commands/generate.rb:1:in `<top (required)>' from script/generate:3:in `require' from script/generate:3:in `<main>'
Comments
-
Hello,
I have a rack filter that dynamically sets the session cookie domain using env['rack.session.options'][:domain]. This seems to correctly update the domain for rails session cookies but not for authlogic cookies.
Is there a preferred method for setting dynamic (rather than static in environment.rb) cookie domains that would work with authlogic as well?
Thanks!
OmarComments
We have the same issue on an app that supports cross-subdomain logins. We see that the AuthLogic cookie always gets set to www.domain.com instead of the expected .domain.com (note the prefixing dot).
We can login fine, but logging out is not possible at all.
-
Authlogic can make some usernames impossible to log in to
0 comments Created about 1 month ago by anime4christAuthlogic allows people to register with the same login plus a trailing space. I don't know about other databases, but this makes it impossible to log in with the second login using MySQL. Example:
User1 signs up with login "John"
User2 signs up with login "John "first(:conditions => ["LOWER(users.login) = ?", "John ".downcase])
returns User1 rather than User2.Also, Authlogic allows the login to be an email address by default, which can cause problems if you enable email or login to log in.
Comments
-
Hi all, I'm getting the following error in my application that uses Authlogic:
ActionView::TemplateError (undefined method `password' for #<User:0x2af83ebffa98>) on line <a href="/binarylogic/authlogic/issues/#issue/7" class="internal">#7</a> of app/views/users/_form.html.erb: 4: <br /> 5: 6: <%= form.label :password, form.object.new_record? ? nil : "Change password" %><br /> 7: <%= form.password_field :password %><br /> 8: 9: <br /> 10:
It works perfectly locally, but when I run it on Heroku it stops working. I see that others have this issue, but no-one has been given an answer. All of the migrations are run, and I do have acts_as_authentic in my User model.
Thanks!
Comments
-
Hey,
Currently the persistence order of Authlogic is this:
[:persist_by_params, :persist_by_cookie, :persist_by_session, :persist_by_http_auth]This - according to me - is not logically correct. persistence by session should come before persistence by cookie.
:persist_by_cookie is enabling the "remember me" functionality, and could be perceived as an "automated re-login" system. There are many possible use cases where a client would want to track these "automated logins". Currently this can be done by overriding (or chaining) the persist_by_cookie method. However it is always called.
By moving the :persist_by_session callback up one spot, the :persist_by_cookie will only be called if there is no session available and can then be truly seen as "automated login"
Comments
-
timeout and single_access_token don't work together
1 comment Created 27 days ago by skippyhey,
if you have the timeout logic enabled as well as the column 'last_request_at', then a single_access_token will be flagged as 'stale' because logged_out will return true (which is because last_request_at is not set or is old).
to fix this, one needs to replace (in lib/session/timeout.rb)
before_persisting :reset_stale_state after_persisting :enforce_timeout
to
before_persisting :reset_stale_state, :unless => :single_access? after_persisting :enforce_timeout, :unless => :single_access?
thanks!
AdamComments
patch submitted here:
https://github.com/skippy/authlogic/commit/c01a32a21353c15b9e06541199214074f7bf1ff9
-
uninitialized constant ActiveSupport::Multibyte::Chars::Encoding
1 comment Created 20 days ago by boriscyI have installed the version 2.1.2 and it gives me this error when I try to login:
NameError (uninitialized constant ActiveSupport::Multibyte::Chars::Encoding): authlogic (2.1.2) lib/authlogic/acts_as_authentic/login.rb:121:in
find_with_case' authlogic (2.1.2) lib/authlogic/acts_as_authentic/login.rb:110:infind_by_smart_case_login_field' authlogic (2.1.2) lib/authlogic/session/scopes.rb:95:in
send' authlogic (2.1.2) lib/authlogic/session/scopes.rb:95:insearch_for_record' authlogic (2.1.2) lib/authlogic/session/scopes.rb:94:in
send' authlogic (2.1.2) lib/authlogic/session/scopes.rb:94:insearch_for_record' authlogic (2.1.2) lib/authlogic/session/password.rb:183:in
validate_by_password' authlogic (2.1.2) lib/authlogic/session/callbacks.rb:72:invalidate' authlogic (2.1.2) lib/authlogic/session/validation.rb:64:in
valid?' authlogic (2.1.2) lib/authlogic/session/existence.rb:65:insave' app/controllers/usuario_sessiones_controller.rb:14:in
create'`Comments
-
At the time of this writing authlogic/acts_as_authentic/base.rb does inclusion of many methods in ActiveRecord::Base.
Would it be possible to improve this part to not include those methods in all objects inheriting from ActiveRecord::Base since it compromises code stability?
Comments
Here is a patch:
--- authlogic/acts_as_authentic/base.rb.orig 2009-11-12 17:48:58.000000000 +0100 +++ authlogic/acts_as_authentic/base.rb 2009-11-12 17:51:23.000000000 +0100 @@ -6,6 +6,17 @@
klass.class_eval do extend Config end
klass.send :include, Authlogic::ActsAsAuthentic::Email
klass.send :include, Authlogic::ActsAsAuthentic::LoggedInStatus
klass.send :include, Authlogic::ActsAsAuthentic::Login
klass.send :include, Authlogic::ActsAsAuthentic::MagicColumns
klass.send :include, Authlogic::ActsAsAuthentic::Password
klass.send :include, Authlogic::ActsAsAuthentic::PerishableToken
klass.send :include, Authlogic::ActsAsAuthentic::PersistenceToken
klass.send :include, Authlogic::ActsAsAuthentic::RestfulAuthentication
klass.send :include, Authlogic::ActsAsAuthentic::SessionMaintenance
klass.send :include, Authlogic::ActsAsAuthentic::SingleAccessToken
klass.send :include, Authlogic::ActsAsAuthentic::ValidationsScope
end
module Config @@ -92,16 +103,16 @@ end end
-::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::Base -::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::Email -::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::LoggedInStatus -::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::Login -::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::MagicColumns -::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::Password -::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::PerishableToken -::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::PersistenceToken -::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::RestfulAuthentication -::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::SessionMaintenance -::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::SingleAccessToken -::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::ValidationsScope +#::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::Base +#::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::Email +#::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::LoggedInStatus +#::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::Login +#::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::MagicColumns +#::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::Password +#::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::PerishableToken +#::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::PersistenceToken +#::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::RestfulAuthentication +#::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::SessionMaintenance +#::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::SingleAccessToken +#::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::ValidationsScope
This then makes it mandatory to do the inclusion at the model level like that, but this is cleaner:
class User < ActiveRecord::Base
include Authlogic::ActsAsAuthentic::Base
Could you consider doing so in a future version please?
I realize that would require every existing project relying on authlogic to add this line but again this improves code separation and stability with ActiveRecord and this improves clarity making it easier to understand the magic involved.
And finally thanks for the authlogic code, sharing and maintaining it!
Since I can't manage to have a clean code formating in the github issue tracker (couldn't find any help) for the patch, here is a link to a nice-formated version: https://pastie.org/695792
Best regards
-
I notice that Authlogic::ActsAsAuthentic::Login::Config 's login_field method accepts a symbol representing a single column.
I have a system which has 2 fields (agency & username) that uniquely identifies a user. Is there some way the existing authlogic can deal with a user table that has multiple columns that identify a user?
If not, would you be interested in a patch allowing login_field to also accept an array of symbols to handle such cases?
Comments
-
Hello,
I posted this message on authlogic_facebook_connect but Joakim told me I'd better ask Ben (ref: https://github.com/kalasjocke/authlogic_facebook_connect/issues/#issue/7).
So, here am I :)
I have a problem with facebook connect and the authlogic's persistence token. In my app right now I use 3 tokens : persistence, perishable and single_access. Following Authlogic example app (Ben's one), the three tokens should not be allowed NULL. I'd like to preserve that since I plan to have both facebook and non-facebook users.
perishable_token and single_access_token don't mess up facebook connect, and before_connect (a hook to grab facebook info and initialize your user model with it upon connection) seems a good place to set them in case you want to.
So my code looks like :
def before_connect(facebook_session)self.single_access_token = Authlogic::Random.friendly_token self.perishable_token = Authlogic::Random.friendly_token self.first_name = facebook_session.user.first_name self.last_name = facebook_session.user.last_name
end
Unfortunately, this doesn't work with the persistence_token.
It's really strange because if I add a persistence_token the same way I do for the two other tokens (friendly_token or hex_token), it gets impossible to login.
But, if I set the facebook_uid to an existing "non facebook" user (that has a persistence_token), he will be able to log in.
Also, if I manually edit the database entry and put whatever token, it will also work.So it looks like the random token generated during before_connect isn't acceptable, but I don't know why.
Do you have any clue regarding this behavior ?
Thanks a lot for your help.
Comments
-
I get this error with the following setup: uninitialized constant User::AuthLogic
config/environment.rb
= '2.3.4' unless defined? RAILS_GEM_VERSION require File.join(File.dirname(FILE), 'boot')
Rails::Initializer.run do |config|
config.gem 'authlogic'config.time_zone = 'UTC'
end
app/models/user.rb
class User < ActiveRecord::Base
acts_as_authentic do |c|c.crypto_provider = AuthLogic::CryptoProviders::MD5
end end
Any thoughts on what I am doing wrong?
Comments
mattberther Mon Nov 16 23:58:05 -0800 2009 | link
Please close this... i learned to spell Authlogic properly...
-
authlogic does not work with latest veersion 1.9.1 of roo
0 comments Created 14 days ago by boriscyI think the problem is with the roo gem, I just want to inform you about this problem, you can check the error messagge I have:
https://rubyforge.org/tracker/index.php?func=detail&aid=27445&group_id=3729&atid=14374Comments
-
I seem to have some sort of load issue kicking me into the test environment, and I've made a minimal app to replicate the issue. (https://www.ruby-forum.com/topic/199371#868558 has the app attached)
From what I can tell, the problem is due to three related items: 1) a user model with authlogic, 2) rspec-rails, and 3) a users observer. Removing any one of the three seems to "fix" the issue. I've noted the lines which you can comment out to see the problem resolve. (It should then load the development SQLite3 database with my test user). The visible symptom is:
SQLite3::SQLException: no such table: users: SELECT * FROM "users"
Apparently the conflict pushes the app into the test environment and therefore changes the database on me.
Gems:
- authlogic 2.1.3
- rspec and rspec-rails 1.2.9
- rails 2.3.4
I'm on passenger 2.2.5, and I hope that's not a factor. I currently run stock Snow Leopard ruby.
Any clue how I can further track this down? I don't see anything obvious with either rspec or authlogic fudging with the environment…
Regards,
David Nawara
Comments
-
Hi, I implemented the tutorial, with 'username' as the login field.
The column in the Users table is named 'username', and in user.rb I added:
acts_as_authentic do |c|
c.login_field = :username
end
and got this weird exception:
NoMethodError in User_sessions#new
Showing app/views/user_sessions/new.html.erb where line #33 raised:
undefined method `column_for_attribute' for #<UserSession: no credentials provided>
Extracted source (around line #33):
30: <%= f.label t('user.username') %> :
31:
32:
33: <%= f.text_field :username %>34:
35:
36:RAILS_ROOT: /disk1/home/slugs/34794_f1a214e_a88e/mnt
Application Trace | Framework Trace | Full Trace/disk1/home/slugs/34794_f1a214e_a88e/mnt/vendor/plugins/delocalize/lib/delocalize/rails_ext/action_view.rb:11:in
to_input_field_tag' /disk1/home/slugs/34794_f1a214e_a88e/mnt/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:531:in
text_field'/disk1/home/slugs/34794_f1a214e_a88e/mnt/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:930:in
send' /disk1/home/slugs/34794_f1a214e_a88e/mnt/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:930:in
text_field'/disk1/home/slugs/34794_f1a214e_a88e/mnt/app/views/user_sessions/new.html.erb:33:in
_run_erb_app47views47user_sessions47new46html46erb' /disk1/home/slugs/34794_f1a214e_a88e/mnt/app/views/user_sessions/new.html.erb:26:in
_run_erb_app47views47user_sessions47new46html46erb'This only appends in production, it works well in development.
Comments
Solved.
It was a plugin that was present in prod ('delocalize') and not in dev.
The app being deployed on Heroku, there is no visible file system.
To remove it fully, remove it from the local git:
git rm -r vendor/plugins/delocalize
Then redeploy on Heroku.There's a bug that causes AuthLogic to only maintain one session at a time. It is caused by BCrypt and the BCrypt.cost parameter. When one session starts, all the other sessions will be invalidated/logged out.
To reproduce, make the following changes in the AuthLogic Example, and register a new user after making those changes.
user.rb:
class User < ActiveRecord::Base acts_as_authentic do |c| c.crypto_provider = Authlogic::CryptoProviders::BCrypt end end
config/initializers/authlogic.rb
Authlogic::CryptoProviders::BCrypt.cost = 1
Removing the BCrypt.cost line seems to solve the issue.
Comments
Since recently updating to a newer version of both Formtastic and Authlogic I've noticed a NoMethodError for UserSession on method 'content_columns'
I've since made the following amendment to my UserSession model to get things humming again.
Comments
rspec + authlogic -> unable to ever log out during tests
0 comments Created about 2 hours ago by xxxThis is a bit of a strange one. I'm testing my logout action, simply testing to see if the user is logged-out after hitting the action.
It works fine in the browser, but never logs the user out in tests (at least user.reload.logged_in? is still true.) Logging in was fine once I discovered activate_authlogic, but logging out continues to elude me.
I understand that you don't use rspec, but I have no other recourse at this point. I've been trying for an hour to make a 5-line test I've written 20 times before to work and i'm about to slit my wrists here.
Comments
Labels- @Ben Johnson▾
- authlogic▾
- authlogici18n▾
- cookies▾
- documentation▾
- errors▾
- from-lighthouse▾
- http_basic_authentication▾
- i18n▾
- rdoc▾
- session▾
- sti▾
- validation▾
- |S| new▾
- |S| open▾
- Apply to Selection
-
Change Color…
Preview:preview
- Rename…
- Delete
This feature is coming soon. Sit tight!
most of these things are not really related to authlogic