This page is intended to help you get the SaltedHashLoginGenerator up and running quickly and easily. JoeHosteny’s generator is cool, but getting it set up has caused a lot of headaches on the mailing list.
For easier installation, look at using the LoginEngine, which is a port to the Rails Engines system (an alternative to Generators that avoids copying source code into your application.)
In just a few steps, we’ll get the SaltedHashLoginGenerator up and running and get all the tests passing. I’m assuming that you have Ruby, Rails, and a database engine capable of transactions (MySQL 4.x with InnoDB, Postgres, etc)
Install the SaltedHashLoginGenerator and LocalizationGenerator gems:
gem install salted_login_generator
gem install localization_generator
Create your application and get into its directory:
rails yourapp
cd yourapp
Bring in the generator code:
ruby script/generate salted_login User Localization
Note: you can of course choose a different name for these, but that’s outside the scope of this guide
Edit your ApplicationController (yourapp/app/controllers/application.rb) to look like this
require 'localization'
require 'user_system'
# The filters added to this controller will be run for all controllers in the application.
# Likewise will all the methods added be available for all controllers.
class ApplicationController < ActionController::Base
include Localization
include UserSystem
helper :user
model :user
end
If you want to protect your entire application add the following line to ApplicationController:
before_filter :login_required
Add the following line to your ApplicationHelper (yourapp/app/helpers/application_helper.rb):
include Localization
Add the following lines to the bottom of yourapp/config/environment.rb:
require 'environments/localization_environment'
require 'localization'
Localization::load_localized_strings
require 'environments/user_environment'
[note, “localization” and “user” above assume those are the names you used in the generate command]
[note #2, above it says to put this in environment.rb. That didn’t work for me and I received the say error that everyone else sees, which is “NoMethodError in … for CONFIG:Module”. I solved that problem by adding require ‘environment.rb’ to the top of application.rb.]
Edit yourapp/config/environments/localization_environment.rb to taste. Refer to yourapp/README_LOCALIZATION for more details.
Edit yourapp/config/environments/user_environment.rb to taste. Specifically, make sure you set the email addresses and URL, or else your notifications won’t work/will be funky. If you leave the FROM field blank, some SMTP servers will refuse your email.
Add appropriate mail configuration to your Rails environments (yourapp/config/environments/development.rb, yourapp/config/environments/test.rb, yourapp/config/environments/production.rb)
Unix machines can often use Sendmail:
ActionMailer::Base.delivery_method=:sendmail
While other platforms may need to use SMTP:
ActionMailer::Base.server_settings = {
:address => "smtp.yourdomain.com",
:port => 25
}
Note: For many people, more settings will be required. In particular, you may need to set the :domain key. Refer to the ActionMailer docs for more information about the ActionMailer::Base.server_settings variable.
Thanks to DavidCorbin? for pointing this out.
Ensure that your database settings are properly configured in yourapp/config/database.yml, and import the appropriate schema in yourapp/README_USER_LOGIN. Note, however, that the schema in the README (as of 2005-06-03) is slightly different that the one offered in yourapp/db/user_model.erbsql. You\u’re only missing three fields, though—created_at, updated_at, logged_in_at which you can create by hand if you want.
If you have the db_structure gem installed, you can attempt to create the schema using it by running:
script/create_db
Note: db_structure v1.0.2 does not work with PostgreSQL. If you’re running Postgres, you’re going to have to create the database by hand.
Also note: If you run this command on an already existing application, it will destroy all tables in the databases referenced by your database.yml file.
First though, make sure your test/test_helper.rb has
self.use_instantiated_fixtures = true
Now, run the tests and watch in amazement as they pass with flying colors:
yourbox ~/yourapp $ rake test_units
(in /home/you/yourapp)
ruby -Ilib:test "/usr/local/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_loader.rb" \
"test/unit/localization_test.rb" "test/unit/user_test.rb"
Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_loader
Started
..............
Finished in 1.51912 seconds.
14 tests, 32 assertions, 0 failures, 0 errors
yourbox ~/yourapp $ rake test_functional
(in /home/you/yourapp)
ruby -Ilib:test "/usr/local/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_loader.rb" \
"test/functional/user_controller_test.rb"
Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_loader
Started
.........
Finished in 4.013108 seconds.
9 tests, 93 assertions, 0 failures, 0 errors
If the functional tests fail with a warning: already initialized constant DEFAULT_HEAD_OPTIONS, edit yourapp/app/helpers/user_helper.rb. At the top change
@
module UserHelper
DEFAULT_HEAD_OPTIONS = {
:notice => true,
:message => true,
:error => false
}.freeze
@
to
@
module UserHelper
DEFAULT_HEAD_OPTIONS = {
:notice => true,
:message => true,
:error => false
}.freeze unless const_defined? "DEFAULT_HEAD_OPTIONS"
@
(there are other bug fixes on the SaltedHashLoginGenerator page, but you can get by without most of them).
If you get messages like
2) Error:
test_passwordchange(UserTest):
NoMethodError: You have a nil object when you didn't expect it!
The error occured while evaluating nil.change_password
./test/unit/user_test.rb:17:in `test_passwordchange'
Then try editing test/test_helper.rb and set:
self.use_instantiated_fixtures = true
Seriously, though, read the README so you understand how to use your new system.
-Disha (disha_gupta@persistent.co.in)
hi disha,
i’ve encountered the same problem too. the culprit is localization. take away localization and it’ll work again.
-zan (liangzan at gmail.com)
def signup
if (User.count != 0)
redirect_to :action => 'login'
return
end
...standard code of signup...
ActionMailer::Base.server_settings = {
:address => "smtp.comcast.net",
:port => 25,
:user_name => "<a href="mailto:chillexistence@comcast.net">chillexistence@comcast.net</a>"
}
and when i run the following this is my response
ruby script/console
Loading development environment.
>> UserNotify.deliver_signup(User.new, ””,”“)
=> #
when in the same area for these settings i set
config.action_mailer.raise_delivery_errors = true
and now i get
C:\rails\saltlogin>ruby script/console
Loading development environment.
>> UserNotify.deliver_signup(User.new, "", "")
ArgumentError: both user and secret are required
from c:/ruby/lib/ruby/1.8/net/smtp.rb:563:in `check_auth_args'
from c:/ruby/lib/ruby/1.8/net/smtp.rb:391:in `do_start'
from c:/ruby/lib/ruby/1.8/net/smtp.rb:378:in `start'
from c:/ruby/lib/ruby/1.8/net/smtp.rb:316:in `start'
from c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer
/base.rb:436:in `perform_delivery_smtp'
from c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer
/base.rb:327:in `send'
from c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer
/base.rb:327:in `deliver!'
from c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer
/base.rb:223:in `method_missing'
from (irb):1
Either I don’t know what I’m doing (quite possible, being a Rails and Ruby newbie), or this thing is broken. I keep getting errors like
NoMethodError in User#login WARNING: You have a nil object when you probably didn't expect it! Odds are you want an instance of Array instead. Look in the callstack to see where you're working with an object that could be nil. Investigate your methods and make sure the object is what you expect! /app/controllers/user_controller.rb:9:in `login' script/server:49
I had some of the same problems. It turned out that the machine I was running an old version of rails. Double check yours?
gem install rails --remotejust to be sure. No change.
Even more puzzling, unit testing works fine:
C:>rake test_units ruby -Ilib;test "c:/ruby/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_lo ader.rb" "test/unit/localization_test.rb" "test/unit/user_test.rb" Loaded suite c:/ruby/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_loader Started .............. Finished in 1.072 seconds. 14 tests, 32 assertions, 0 failures, 0 errors
I’ve had no problems with the regular LoginGenerator, so I’m dropping back to that. sigh
I’m having the same problem, except strangely enough I don’t get it if I go directly to localhost:3000/user/login (or signup or anything), but I do get it when I try to use link_to_remote for the same controller and action.
Once I set the email field to be nullable the unit tests worked.
Perhaps it can but I have absolutely no idea how? :-)
It was my understand that date/time columns were supposed to be named as such.
If you changed :security_token_life_hours, the functional test might fail for your because of a hardcoded value in line 55. Be sure to modify this value to match your :security_token_life_hours setting in days.
One of the reasons that some people have more/less trouble with this generator than other people has to do with what they did before starting this quickstart. If you’ve already created most of your application, and you’re adding in this login system, you’ve got more of the ecostructure in place. If this login system is the first thing you’re creating for your app, you may find that some pieces are missing.
One item not generated in some cases is app/views/user/_form.rhtml. Here’s a stub _form.rhtml that will suffice:
<%= error_messages_for 'user' %> <!--[form:user]--> <p><label for="user_login">Login</label><br/> <%= text_field 'user', 'login' %></p> <p><label for="user_salted_password">Salted password</label><br/> <%= password_field 'user', 'salted_password' %></p> <p><label for="user_email">Email</label><br/> <%= text_field 'user', 'email' %></p> <p><label for="user_firstname">Firstname</label><br/> <%= text_field 'user', 'firstname' %></p> <p><label for="user_lastname">Lastname</label><br/> <%= text_field 'user', 'lastname' %></p> <p><label for="user_salt">Salt</label><br/> <%= text_field 'user', 'salt' %></p> <p><label for="user_verified">Verified</label><br/> <%= text_field 'user', 'verified' %></p> <p><label for="user_role">Role</label><br/> <%= text_field 'user', 'role' %></p> <p><label for="user_security_token">Security token</label><br/> <%= text_field 'user', 'security_token' %></p> <p><label for="user_token_expiry">Token expiry</label><br/> <%= datetime_select 'user', 'token_expiry' %></p> <p><label for="user_created_at">Created at</label><br/> <%= datetime_select 'user', 'created_at' %></p> <p><label for="user_updated_at">Updated at</label><br/> <%= datetime_select 'user', 'updated_at' %></p> <p><label for="user_logged_in_at">Logged in at</label><br/> <%= datetime_select 'user', 'logged_in_at' %></p> <p><label for="user_deleted">Deleted</label><br/> <%= text_field 'user', 'deleted' %></p> <p><label for="user_delete_after">Delete after</label><br/> <%= datetime_select 'user', 'delete_after' %></p> <!--[eoform:user]-->
users database keeps disappearing
If your user database keeps disappearing when you run your rake tests, maybe you tried to test out your changes on the test database before applying them to dev database. Make sure you apply the database changes to the dev database. The test database is re-created from the development database every time the tests are run.
How to see what your SMTP server is reporting
If you’ve identified that you have a problem sending your signup emails in UserNotify.deliver_signup (probably you’re seeing “Error creating account: confirmation email not sent”), one way to see what’s going on is to use the console.
ruby script/console >> UserNotify.deliver_signup(User.new, "", "") Net::SMTPSyntaxError: 500 5.5.1 Command unrecognized: "AUTH CRAM-MD5"
Some unit tests failing
The unit tests are written to expect instantiated fixtures, but they are turned off in the test_helper.rb file. Turn them back on with
self.use_instantiated_fixtures = true
NOTE for Windows Users
You need to have iconv support.
—
It’s quite a long procedure.. isn’t there a faster way?
C:\rails\clink>rake test_units
(in C:/rails/clink)
c:/ruby/bin/ruby -Ilib;test “c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/
rake_test_loader.rb” “test/unit/localization_test.rb” “test/unit/user_test.rb”
Loaded suite c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/rake_test_loader
Started
........F….E
Finished in 0.23 seconds.
1) Failure:
test_auth(UserTest) [./test/unit/user_test.rb:9]:
expected but was
<#<User:0x3773558
@attributes=
{"salt"=>"7f8b036f9b647d46d22abdbfc8113f44a88f9889",
"delete_after"=>nil,
"updated_at"=>nil,
"security_token"=>nil,
"role"=>nil,
"lastname"=>nil,
"firstname"=>nil,
"id"=>"1000001",
"deleted"=>"0",
"token_expiry"=>nil,
"verified"=>"1",
"logged_in_at"=>nil,
"salted_password"=>"ef94c16f6c124a4e84cc215c164767bfa25f6e92",
"login"=>"bob",
"created_at"=>nil,
"email"=>"bob@test.com"}>>.
2) Error:
test_passwordchange(UserTest):
NoMethodError: You have a nil object when you didn't expect it!
The error occured while evaluating nil.change_password
./test/unit/user_test.rb:17:in `test_passwordchange'
14 tests, 27 assertions, 1 failures, 1 errors
rake aborted!
Command failed with status (1): [c:/ruby/bin/ruby -Ilib;test “c:/ruby/lib/r…]
C:\rails\clink>rake test_functional
(in C:/rails/clink)
c:/ruby/bin/ruby -Ilib;test “c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/
rake_test_loader.rb” “test/functional/user_controller_test.rb”
Loaded suite c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/rake_test_loader
Started
F.FEF…F
Finished in 0.741 seconds.
1) Failure:
test_auth_bob(UserControllerTest) [./test/functional/user_controller_test.rb:23]
:
expected but was
<#<User:0x375da60
@attributes=
{"salt"=>"7f8b036f9b647d46d22abdbfc8113f44a88f9889",
"delete_after"=>nil,
"updated_at"=>nil,
"security_token"=>nil,
"role"=>nil,
"lastname"=>nil,
"firstname"=>nil,
"id"=>"1000001",
"deleted"=>"0",
"token_expiry"=>nil,
"verified"=>"1",
"logged_in_at"=>nil,
"salted_password"=>"ef94c16f6c124a4e84cc215c164767bfa25f6e92",
"login"=>"bob",
"created_at"=>nil,
"email"=>"bob@test.com"}>>.
@attributes={"user"=>nil, "flash"=>{}}>>
@attributes={"user"=>nil, "flash"=>{}}>>
5) Failure:
test_signup(UserControllerTest)
[c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/depr
ecated_assertions.rb:13:in `assert_redirect'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/depr
ecated_assertions.rb:98:in `assert_redirect_url'
./test/functional/user_controller_test.rb:37:in `do_test_signup'
./test/functional/user_controller_test.rb:145:in `test_signup']:
Expected response to be a <:redirect>, but was <200>
9 tests, 76 assertions, 4 failures, 1 errors
rake aborted!
Command failed with status (1): [c:/ruby/bin/ruby -Ilib;test “c:/ruby/lib/r…]
It looks like you aren’t using instantiated fixtures. Make sure the following is in test/test_helper.rb:
self.use_instantiated_fixtures = true
—ericdfoley at google’s mail service
Right. See Mike Clark’s explanation.
My rake tests are failing because of loads of inconsistencies in the spelling of localization/localisation
I upgraded to Ruby 1.8.4 using the one-click ruby installer at rubyforge
This resolved my installation problem.
—Nate
Many thanks for your help.
Having a nightmare setting this up. It really needs way more documentation and guidance.
ActionMailer::Base.server_settings = {
:address => "smtp.mac.com",
:port => 25,
:domain => "smtp.mac.com",
:user_name => "",
:password => "",
:authentication => :login
}
Also, for my question, I finished setting it up, but when I tried to start the server it said, ”=> Booting WEBrick…” then canceled and went back to the command prompt. What is wrong?
—> You need to install inconv support as or upgrade to ruby 1.8.4. Links for both of these have been mentioned earlier.
I’ve spent hours trying to ge this working. I’m still getting the following exception ‘undefined method `[]’ for CONFIG:Module’
I’m ready to leave ror and go back to what works. seriously.
Everything seems to be running smoothly up until the point I need to generate the login emails. While no errors are generated, I’m not sending out any emails.
I’m running off a development environment on my local machine (localhost), but my smtp server is from a hosted account elsewhere. Here’s how I’ve got it set up right now:
ActionMailer::Base.server_settings = {
:address => “mail.example.com”,
:port => 25,
:domain => “localhost”,
:user_name => “myusername”,
:password => “mypassword”
:authentication => :login
}
‘Error creating account: confirmation email not sent’
For me it was failing because I had mistyped my ActionMailer settings. I changed the rescue block in def signup to this:
rescue Exception => exc
flash.now['message'] = l(:user_confirmation_email_error)
logger.warn("User failed confirmation: " + exc.message)
end
Taking a quick look at your Actionmailer settings it looks like you are not init. it correctly. There is a correct example above in the wiki.
- Adam G.
undefined method `[]’ for CONFIG:Module
localization.rb:8:in `l’ #{RAILS_ROOT}/app/helpers/user_helper.rb:67:in `head_helper’ #{RAILS_ROOT}/app/views/user/login.rhtml:2:in `_run_rhtml_user_login’ #{RAILS_ROOT}/app/controllers/user_controller.rb:172:in `generate_blank’ #{RAILS_ROOT}/app/controllers/user_controller.rb:6:in `login’
help me what is the problem ?
-krull
You need to add this to the bottom of your config/environment.rb file:
require ‘environments/localization_environment’
require ‘localization’
Localization::load_localized_strings
require ‘environments/user_environment’
Hey there,
I’ve installed everything and ran the unit tests and functional test. The unit tests passed wonderfully, but the functional tests resulted in 3 failures and 1 error:
/usr/local/bin/ruby -Ilib:test ”/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb” “test/functional/user_controller_test.rb” “test/functional/view_controller_test.rb”
Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader
Started
..FE.F..F.
Finished in 0.87304 seconds.
1. Failure:
test_change_password(UserControllerTest)
[/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/deprecated_assertions.rb:23:in `assert_session_has'
./test/functional/user_controller_test.rb:190:in `do_change_password'
./test/functional/user_controller_test.rb:198:in `test_change_password']:
<"user"> is not in the session <#<ActionController::TestSession:0x247a894
@attributes={"user"=>nil, "flash"=>{}}>>
@attributes={"return-to"=>"/bogus/location", "flash"=>{}}>>
4. Failure:
test_signup(UserControllerTest)
[/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/deprecated_assertions.rb:13:in `assert_redirect'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/deprecated_assertions.rb:98:in `assert_redirect_url'
./test/functional/user_controller_test.rb:40:in `do_test_signup'
./test/functional/user_controller_test.rb:148:in `test_signup']:
Expected response to be a <:redirect>, but was <200>
10 tests, 68 assertions, 3 failures, 1 errors
rake aborted!
Command failed with status (1): [/usr/local/bin/ruby -Ilib:test ”/usr/local…]
I’ve started debugging it myself. It looks like when I request and email for a forgotten password, change_password does not do anything with the key, so you never have a user properly instantiated. Anyway, I figured I shouldn’t be debugging this myself. Am I missing something or is this flawed?
Thanks,
Ryan
For Ryan’s Failure#1: the test is wrong. When calling do_change_password with bad_email=true, the password actually did get changed, but we’re trying to login with the old password instead of the changed password. So assert_session_has “user” should actually fail… correct behavior, wrong assertion.
Great software. I followed the instructions and got it working on my Ubuntu in 30 minutes. I only had to change the sql query to create the database so I included the 3 missing fields and removed the DEFAULT CHARSET thing (not working on MySQL < 4.1) on README_USR_LOGIN:
CREATE TABLE users (
id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
login VARCHAR(80) NOT NULL,
salted_password VARCHAR(40) NOT NULL,
email VARCHAR(60) NOT NULL,
firstname VARCHAR(40),
lastname VARCHAR(40),
salt CHAR(40) NOT NULL,
verified INT default 0,
role VARCHAR(40) default NULL,
security_token CHAR(40) default NULL,
token_expiry DATETIME default NULL,
created_at DATETIME default NULL,
updated_at DATETIME default NULL,
logged_in_at DATETIME default NULL,
deleted INT default 0,
delete_after DATETIME default NULL
) TYPE=InnoDB;
Thanks!
Jaime Iniesta
[see my comments later…]
Maybe I’m missing somethng, but I find that the only way to “reload” the localization strings is by restarting my webserver. I’m using Lighttpd.. is there a better way to do this? How do you reload/rerun the environments.rb file without restarting the webserver. For now I’ve included “Localization::load_localized_strings” in my application.rb file and that seems to have done the trick, but I’d like to know how to do this properly. Thanks, Ryan
Not so happy now… this login generator fails sometimes… when I try to put authentication control on some of the controllers (not on the whole application), the verification link by email doesn’t work… I’ve been advised by many people to use the acts_as_authenticated plugin instead.
Jaime IniestaUserNotify.deliver_signup(User.new, ””, ””)
Errno::EBADF: Bad file descriptor – connect(2)
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/net/protocol.rb:206:in `initialize’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/net/protocol.rb:206:in `old_open’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/timeout.rb:56:in `timeout’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/net/protocol.rb:206:in `old_open’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/net/smtp.rb:393:in `do_start’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/net/smtp.rb:378:in `start’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/net/smtp.rb:316:in `start’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer/base.rb:447:in `perform_delivery_smtp’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer/base.rb:333:in `deliver!’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer/base.rb:227:in `method_missing’
and my development.rb looks like this (with real smtp adress instead of example):
ActionMailer::Base.server_settings = {For those trying to use Gmail as an smtp server, there is some additional setup that needs to take place. Here is a good explanation:
http://stephenchu.blogspot.com/2006/06/how-to-use-gmail-smtp-server-to-send.html
Does anyone know if it is possible to change your email address? I included “email” in the changeable_fields array of the edit action, but that didn’t work. It doesn’t look like it is set up to handle this. Are there any thoughts on how this could be done?
I’ve been working through the code to try and understand how it functions. Stuck on one bit though. I note that after signup the welcome action is called from the Click Me link in the email. I note also that the user table is read and updated before (I think) the empty welcome action is called. How is this database read/update triggered? I am fairly new to Rails so I may be overlooking something very obvious.
- LeeMatt
This is kind of silly and I’m new to RoR but where is the README for SaltedLoginGenator? I’ve been to the project site but I can’t find the README because there’s nothing listed under documentations. Can someone please point me to the README or some sort of documentation? I have no idea what table or columns to create.
Thanks.
-Hang Cheng
I have two different classes of users in my app. Any tips on how to create two different login systems for them using this? Thanks.
-George
Thu May 03 00:41:31 -0400 2007: Error calling Dispatcher.dispatch #
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:422:in `remove_const’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:422:in `send’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:422:in `remove_constant’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:273:in `remove_unloadable_constants!’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:273:in `each’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:273:in `remove_unloadable_constants!’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:72:in `clear’
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:60:in `reset_application!’
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:116:in `reset_after_dispatch’
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:51:in `dispatch’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:78:in `process’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `synchronize’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `process’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:618:in `process_client’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `each’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `process_client’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `initialize’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `new’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `initialize’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `new’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:271:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `each’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:127:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/command.rb:211:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:243
C:\ruby\bin\mongrel_rails:16:in `load’
C:\ruby\bin\mongrel_rails:16
-e:3:in `load’
-e:3
fixed the above witth this:
http://rc3.org/2007/02/resolving_the_n.php
I can’t get the change password to work how come? Am I supposed to add something to the source code from the basic when I first install it? Because it seems like the change_password function does nothing. It verifies the both passwords are identical and that’s it. What anyone help me out on that one?
Thanks,
Luc
When I try generate the code, I get the following error:
C:\ruby\app>ruby script/generate salted_login User Localization
DEPRECATION WARNING: server_settings has been renamed smtp_settings, this warning will be removed with rails 2.0 See http://www.rubyonrails.org/deprecation for details. (called from load_environment
at ./script/../config/../config/environments/development.rb:23)
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’: no such file to load—environments/localization_environment (MissingSourceFile)
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
from ./script/../config/../config/environment.rb:62
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/generate.rb:1
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `gem_original_require’
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `require’
from script/generate:3
I’m running rails 2.0.2 on Suse 10.1. The output of the functional tests look odd to me:
david@hathor:/Projects/folklist> rake\ test:functionals
(in /home/david/Projects/folklist)
/usr/bin/ruby -Ilib:test ”/usr/lib64/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb”
david@hathor:/Projects/folklist>
No results, no errors. Any idea what’s going on here?
ThanksI have a functional test failure that I don’t know how to fix:
david@hathor:~/Projects/folklist> rake test:functionals
(in /home/david/Projects/folklist)
/usr/bin/ruby -Ilib:test ”/usr/lib64/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb” “test/functional/user_controller_test.rb”
Loaded suite /usr/lib64/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader
/home/david/Projects/folklist/test/mocks/test/time.rb:10:in `now_old’: stack level too deep (SystemStackError)
from /home/david/Projects/folklist/test/mocks/test/time.rb:13:in `now_old’
from ./test/functional/../mocks/test/time.rb:13:in `now’
from /usr/lib64/ruby/1.8/test/unit/ui/testrunnermediator.rb:32:in `run_suite’
from /usr/lib64/ruby/1.8/test/unit/ui/console/testrunner.rb:65:in `start_mediator’
from /usr/lib64/ruby/1.8/test/unit/ui/console/testrunner.rb:39:in `start’
from /usr/lib64/ruby/1.8/test/unit/ui/testrunnerutilities.rb:27:in `run’ from /usr/lib64/ruby/1.8/test/unit/autorunner.rb:200:in `run’
from /usr/lib64/ruby/1.8/test/unit/autorunner.rb:13:in `run’
from /usr/lib64/ruby/1.8/test/unit.rb:285
from /usr/lib64/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb:5
How do I solve a “stack level too deep” error?
Thanks
Change test/mocks/test/time.rb to read:
require 'time'
Time.class_eval {
@@advance_by_days = 0
@@now_old = Time.now
cattr_accessor :advance_by_days
cattr_accessor :now_old
cattr_accessor :now_temp
class << Time
def now
if Time.advance_by_days != 0
Time.now_temp = Time.now_old
Time.now_old = Time.at(Time.now_old.to_i + Time.advance_by_days * 60 * 60 * 24 + 1)
Time.advance_by_days = 0
else
now_old
end
end
def reset
Time.now_old = Time.now_temp
end
end
}
Frankly, I don’t know how the old one ever worked. It was a recursive function that would loop forever if advance_by_days == 0. That is why you ran out of stack space.
Now this causes some other problems in the functional tests. If you read the above code you should be able to figure out what the issue is. To fix it just replace
Time.advance_by_days = 0
Time.reset
—actually thinking about it some more… this will not yield real values for “now” when called with advance_by_days ==0. But all these functional tests need is a starting point – the other calculations are just relative to the initial time so this will work fine for the given functional tests. Cheers.
Bath and Shower
Fragrance
Gift Sets
Hair Care
Makeup
Men’s Grooming
Shaving and Hair Removal
Skin Care
Tools and Accessories
Baby Apparel
Baby Bathing & Skin Care
Baby Bedding
Baby Car Seats
Baby Diapering
Baby Feeding
For Moms
Baby Furniture
Baby Gear
Baby Gifts
Baby Health & Baby Care
Nursery Décor
Potty Training
Baby Safety
Baby Strollers
This page is intended to help you get the SaltedHashLoginGenerator up and running quickly and easily. JoeHosteny’s generator is cool, but getting it set up has caused a lot of headaches on the mailing list.
For easier installation, look at using the LoginEngine, which is a port to the Rails Engines system (an alternative to Generators that avoids copying source code into your application.)
In just a few steps, we’ll get the SaltedHashLoginGenerator up and running and get all the tests passing. I’m assuming that you have Ruby, Rails, and a database engine capable of transactions (MySQL 4.x with InnoDB, Postgres, etc)
Install the SaltedHashLoginGenerator and LocalizationGenerator gems:
gem install salted_login_generator
gem install localization_generator
Create your application and get into its directory:
rails yourapp
cd yourapp
Bring in the generator code:
ruby script/generate salted_login User Localization
Note: you can of course choose a different name for these, but that’s outside the scope of this guide
Edit your ApplicationController (yourapp/app/controllers/application.rb) to look like this
require 'localization'
require 'user_system'
# The filters added to this controller will be run for all controllers in the application.
# Likewise will all the methods added be available for all controllers.
class ApplicationController < ActionController::Base
include Localization
include UserSystem
helper :user
model :user
end
If you want to protect your entire application add the following line to ApplicationController:
before_filter :login_required
Add the following line to your ApplicationHelper (yourapp/app/helpers/application_helper.rb):
include Localization
Add the following lines to the bottom of yourapp/config/environment.rb:
require 'environments/localization_environment'
require 'localization'
Localization::load_localized_strings
require 'environments/user_environment'
[note, “localization” and “user” above assume those are the names you used in the generate command]
[note #2, above it says to put this in environment.rb. That didn’t work for me and I received the say error that everyone else sees, which is “NoMethodError in … for CONFIG:Module”. I solved that problem by adding require ‘environment.rb’ to the top of application.rb.]
Edit yourapp/config/environments/localization_environment.rb to taste. Refer to yourapp/README_LOCALIZATION for more details.
Edit yourapp/config/environments/user_environment.rb to taste. Specifically, make sure you set the email addresses and URL, or else your notifications won’t work/will be funky. If you leave the FROM field blank, some SMTP servers will refuse your email.
Add appropriate mail configuration to your Rails environments (yourapp/config/environments/development.rb, yourapp/config/environments/test.rb, yourapp/config/environments/production.rb)
Unix machines can often use Sendmail:
ActionMailer::Base.delivery_method=:sendmail
While other platforms may need to use SMTP:
ActionMailer::Base.server_settings = {
:address => "smtp.yourdomain.com",
:port => 25
}
Note: For many people, more settings will be required. In particular, you may need to set the :domain key. Refer to the ActionMailer docs for more information about the ActionMailer::Base.server_settings variable.
Thanks to DavidCorbin? for pointing this out.
Ensure that your database settings are properly configured in yourapp/config/database.yml, and import the appropriate schema in yourapp/README_USER_LOGIN. Note, however, that the schema in the README (as of 2005-06-03) is slightly different that the one offered in yourapp/db/user_model.erbsql. You\u’re only missing three fields, though—created_at, updated_at, logged_in_at which you can create by hand if you want.
If you have the db_structure gem installed, you can attempt to create the schema using it by running:
script/create_db
Note: db_structure v1.0.2 does not work with PostgreSQL. If you’re running Postgres, you’re going to have to create the database by hand.
Also note: If you run this command on an already existing application, it will destroy all tables in the databases referenced by your database.yml file.
First though, make sure your test/test_helper.rb has
self.use_instantiated_fixtures = true
Now, run the tests and watch in amazement as they pass with flying colors:
yourbox ~/yourapp $ rake test_units
(in /home/you/yourapp)
ruby -Ilib:test "/usr/local/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_loader.rb" \
"test/unit/localization_test.rb" "test/unit/user_test.rb"
Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_loader
Started
..............
Finished in 1.51912 seconds.
14 tests, 32 assertions, 0 failures, 0 errors
yourbox ~/yourapp $ rake test_functional
(in /home/you/yourapp)
ruby -Ilib:test "/usr/local/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_loader.rb" \
"test/functional/user_controller_test.rb"
Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_loader
Started
.........
Finished in 4.013108 seconds.
9 tests, 93 assertions, 0 failures, 0 errors
If the functional tests fail with a warning: already initialized constant DEFAULT_HEAD_OPTIONS, edit yourapp/app/helpers/user_helper.rb. At the top change
@
module UserHelper
DEFAULT_HEAD_OPTIONS = {
:notice => true,
:message => true,
:error => false
}.freeze
@
to
@
module UserHelper
DEFAULT_HEAD_OPTIONS = {
:notice => true,
:message => true,
:error => false
}.freeze unless const_defined? "DEFAULT_HEAD_OPTIONS"
@
(there are other bug fixes on the SaltedHashLoginGenerator page, but you can get by without most of them).
If you get messages like
2) Error:
test_passwordchange(UserTest):
NoMethodError: You have a nil object when you didn't expect it!
The error occured while evaluating nil.change_password
./test/unit/user_test.rb:17:in `test_passwordchange'
Then try editing test/test_helper.rb and set:
self.use_instantiated_fixtures = true
Seriously, though, read the README so you understand how to use your new system.
-Disha (disha_gupta@persistent.co.in)
hi disha,
i’ve encountered the same problem too. the culprit is localization. take away localization and it’ll work again.
-zan (liangzan at gmail.com)
def signup
if (User.count != 0)
redirect_to :action => 'login'
return
end
...standard code of signup...
ActionMailer::Base.server_settings = {
:address => "smtp.comcast.net",
:port => 25,
:user_name => "<a href="mailto:chillexistence@comcast.net">chillexistence@comcast.net</a>"
}
and when i run the following this is my response
ruby script/console
Loading development environment.
>> UserNotify.deliver_signup(User.new, ””,”“)
=> #
when in the same area for these settings i set
config.action_mailer.raise_delivery_errors = true
and now i get
C:\rails\saltlogin>ruby script/console
Loading development environment.
>> UserNotify.deliver_signup(User.new, "", "")
ArgumentError: both user and secret are required
from c:/ruby/lib/ruby/1.8/net/smtp.rb:563:in `check_auth_args'
from c:/ruby/lib/ruby/1.8/net/smtp.rb:391:in `do_start'
from c:/ruby/lib/ruby/1.8/net/smtp.rb:378:in `start'
from c:/ruby/lib/ruby/1.8/net/smtp.rb:316:in `start'
from c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer
/base.rb:436:in `perform_delivery_smtp'
from c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer
/base.rb:327:in `send'
from c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer
/base.rb:327:in `deliver!'
from c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.1.5/lib/action_mailer
/base.rb:223:in `method_missing'
from (irb):1
Either I don’t know what I’m doing (quite possible, being a Rails and Ruby newbie), or this thing is broken. I keep getting errors like
NoMethodError in User#login WARNING: You have a nil object when you probably didn't expect it! Odds are you want an instance of Array instead. Look in the callstack to see where you're working with an object that could be nil. Investigate your methods and make sure the object is what you expect! /app/controllers/user_controller.rb:9:in `login' script/server:49
I had some of the same problems. It turned out that the machine I was running an old version of rails. Double check yours?
gem install rails --remotejust to be sure. No change.
Even more puzzling, unit testing works fine:
C:>rake test_units ruby -Ilib;test "c:/ruby/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_lo ader.rb" "test/unit/localization_test.rb" "test/unit/user_test.rb" Loaded suite c:/ruby/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_loader Started .............. Finished in 1.072 seconds. 14 tests, 32 assertions, 0 failures, 0 errors
I’ve had no problems with the regular LoginGenerator, so I’m dropping back to that. sigh
I’m having the same problem, except strangely enough I don’t get it if I go directly to localhost:3000/user/login (or signup or anything), but I do get it when I try to use link_to_remote for the same controller and action.
Once I set the email field to be nullable the unit tests worked.
Perhaps it can but I have absolutely no idea how? :-)
It was my understand that date/time columns were supposed to be named as such.
If you changed :security_token_life_hours, the functional test might fail for your because of a hardcoded value in line 55. Be sure to modify this value to match your :security_token_life_hours setting in days.
One of the reasons that some people have more/less trouble with this generator than other people has to do with what they did before starting this quickstart. If you’ve already created most of your application, and you’re adding in this login system, you’ve got more of the ecostructure in place. If this login system is the first thing you’re creating for your app, you may find that some pieces are missing.
One item not generated in some cases is app/views/user/_form.rhtml. Here’s a stub _form.rhtml that will suffice:
<%= error_messages_for 'user' %> <!--[form:user]--> <p><label for="user_login">Login</label><br/> <%= text_field 'user', 'login' %></p> <p><label for="user_salted_password">Salted password</label><br/> <%= password_field 'user', 'salted_password' %></p> <p><label for="user_email">Email</label><br/> <%= text_field 'user', 'email' %></p> <p><label for="user_firstname">Firstname</label><br/> <%= text_field 'user', 'firstname' %></p> <p><label for="user_lastname">Lastname</label><br/> <%= text_field 'user', 'lastname' %></p> <p><label for="user_salt">Salt</label><br/> <%= text_field 'user', 'salt' %></p> <p><label for="user_verified">Verified</label><br/> <%= text_field 'user', 'verified' %></p> <p><label for="user_role">Role</label><br/> <%= text_field 'user', 'role' %></p> <p><label for="user_security_token">Security token</label><br/> <%= text_field 'user', 'security_token' %></p> <p><label for="user_token_expiry">Token expiry</label><br/> <%= datetime_select 'user', 'token_expiry' %></p> <p><label for="user_created_at">Created at</label><br/> <%= datetime_select 'user', 'created_at' %></p> <p><label for="user_updated_at">Updated at</label><br/> <%= datetime_select 'user', 'updated_at' %></p> <p><label for="user_logged_in_at">Logged in at</label><br/> <%= datetime_select 'user', 'logged_in_at' %></p> <p><label for="user_deleted">Deleted</label><br/> <%= text_field 'user', 'deleted' %></p> <p><label for="user_delete_after">Delete after</label><br/> <%= datetime_select 'user', 'delete_after' %></p> <!--[eoform:user]-->
users database keeps disappearing
If your user database keeps disappearing when you run your rake tests, maybe you tried to test out your changes on the test database before applying them to dev database. Make sure you apply the database changes to the dev database. The test database is re-created from the development database every time the tests are run.
How to see what your SMTP server is reporting
If you’ve identified that you have a problem sending your signup emails in UserNotify.deliver_signup (probably you’re seeing “Error creating account: confirmation email not sent”), one way to see what’s going on is to use the console.
ruby script/console >> UserNotify.deliver_signup(User.new, "", "") Net::SMTPSyntaxError: 500 5.5.1 Command unrecognized: "AUTH CRAM-MD5"
Some unit tests failing
The unit tests are written to expect instantiated fixtures, but they are turned off in the test_helper.rb file. Turn them back on with
self.use_instantiated_fixtures = true
NOTE for Windows Users
You need to have iconv support.
—
It’s quite a long procedure.. isn’t there a faster way?
C:\rails\clink>rake test_units
(in C:/rails/clink)
c:/ruby/bin/ruby -Ilib;test “c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/
rake_test_loader.rb” “test/unit/localization_test.rb” “test/unit/user_test.rb”
Loaded suite c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/rake_test_loader
Started
........F….E
Finished in 0.23 seconds.
1) Failure:
test_auth(UserTest) [./test/unit/user_test.rb:9]:
expected but was
<#<User:0x3773558
@attributes=
{"salt"=>"7f8b036f9b647d46d22abdbfc8113f44a88f9889",
"delete_after"=>nil,
"updated_at"=>nil,
"security_token"=>nil,
"role"=>nil,
"lastname"=>nil,
"firstname"=>nil,
"id"=>"1000001",
"deleted"=>"0",
"token_expiry"=>nil,
"verified"=>"1",
"logged_in_at"=>nil,
"salted_password"=>"ef94c16f6c124a4e84cc215c164767bfa25f6e92",
"login"=>"bob",
"created_at"=>nil,
"email"=>"bob@test.com"}>>.
2) Error:
test_passwordchange(UserTest):
NoMethodError: You have a nil object when you didn't expect it!
The error occured while evaluating nil.change_password
./test/unit/user_test.rb:17:in `test_passwordchange'
14 tests, 27 assertions, 1 failures, 1 errors
rake aborted!
Command failed with status (1): [c:/ruby/bin/ruby -Ilib;test “c:/ruby/lib/r…]
C:\rails\clink>rake test_functional
(in C:/rails/clink)
c:/ruby/bin/ruby -Ilib;test “c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/
rake_test_loader.rb” “test/functional/user_controller_test.rb”
Loaded suite c:/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/rake_test_loader
Started
F.FEF…F
Finished in 0.741 seconds.
1) Failure:
test_auth_bob(UserControllerTest) [./test/functional/user_controller_test.rb:23]
:
expected but was
<#<User:0x375da60
@attributes=
{"salt"=>"7f8b036f9b647d46d22abdbfc8113f44a88f9889",
"delete_after"=>nil,
"updated_at"=>nil,
"security_token"=>nil,
"role"=>nil,
"lastname"=>nil,
"firstname"=>nil,
"id"=>"1000001",
"deleted"=>"0",
"token_expiry"=>nil,
"verified"=>"1",
"logged_in_at"=>nil,
"salted_password"=>"ef94c16f6c124a4e84cc215c164767bfa25f6e92",
"login"=>"bob",
"created_at"=>nil,
"email"=>"bob@test.com"}>>.
@attributes={"user"=>nil, "flash"=>{}}>>
@attributes={"user"=>nil, "flash"=>{}}>>
5) Failure:
test_signup(UserControllerTest)
[c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/depr
ecated_assertions.rb:13:in `assert_redirect'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/depr
ecated_assertions.rb:98:in `assert_redirect_url'
./test/functional/user_controller_test.rb:37:in `do_test_signup'
./test/functional/user_controller_test.rb:145:in `test_signup']:
Expected response to be a <:redirect>, but was <200>
9 tests, 76 assertions, 4 failures, 1 errors
rake aborted!
Command failed with status (1): [c:/ruby/bin/ruby -Ilib;test “c:/ruby/lib/r…]
It looks like you aren’t using instantiated fixtures. Make sure the following is in test/test_helper.rb:
self.use_instantiated_fixtures = true
—ericdfoley at google’s mail service
Right. See Mike Clark’s explanation.
My rake tests are failing because of loads of inconsistencies in the spelling of localization/localisation
I upgraded to Ruby 1.8.4 using the one-click ruby installer at rubyforge
This resolved my installation problem.
—Nate
Many thanks for your help.
Having a nightmare setting this up. It really needs way more documentation and guidance.
ActionMailer::Base.server_settings = {
:address => "smtp.mac.com",
:port => 25,
:domain => "smtp.mac.com",
:user_name => "",
:password => "",
:authentication => :login
}
Also, for my question, I finished setting it up, but when I tried to start the server it said, ”=> Booting WEBrick…” then canceled and went back to the command prompt. What is wrong?
—> You need to install inconv support as or upgrade to ruby 1.8.4. Links for both of these have been mentioned earlier.
I’ve spent hours trying to ge this working. I’m still getting the following exception ‘undefined method `[]’ for CONFIG:Module’
I’m ready to leave ror and go back to what works. seriously.
Everything seems to be running smoothly up until the point I need to generate the login emails. While no errors are generated, I’m not sending out any emails.
I’m running off a development environment on my local machine (localhost), but my smtp server is from a hosted account elsewhere. Here’s how I’ve got it set up right now:
ActionMailer::Base.server_settings = {
:address => “mail.example.com”,
:port => 25,
:domain => “localhost”,
:user_name => “myusername”,
:password => “mypassword”
:authentication => :login
}
‘Error creating account: confirmation email not sent’
For me it was failing because I had mistyped my ActionMailer settings. I changed the rescue block in def signup to this:
rescue Exception => exc
flash.now['message'] = l(:user_confirmation_email_error)
logger.warn("User failed confirmation: " + exc.message)
end
Taking a quick look at your Actionmailer settings it looks like you are not init. it correctly. There is a correct example above in the wiki.
- Adam G.
undefined method `[]’ for CONFIG:Module
localization.rb:8:in `l’ #{RAILS_ROOT}/app/helpers/user_helper.rb:67:in `head_helper’ #{RAILS_ROOT}/app/views/user/login.rhtml:2:in `_run_rhtml_user_login’ #{RAILS_ROOT}/app/controllers/user_controller.rb:172:in `generate_blank’ #{RAILS_ROOT}/app/controllers/user_controller.rb:6:in `login’
help me what is the problem ?
-krull
You need to add this to the bottom of your config/environment.rb file:
require ‘environments/localization_environment’
require ‘localization’
Localization::load_localized_strings
require ‘environments/user_environment’
Hey there,
I’ve installed everything and ran the unit tests and functional test. The unit tests passed wonderfully, but the functional tests resulted in 3 failures and 1 error:
/usr/local/bin/ruby -Ilib:test ”/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb” “test/functional/user_controller_test.rb” “test/functional/view_controller_test.rb”
Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader
Started
..FE.F..F.
Finished in 0.87304 seconds.
1. Failure:
test_change_password(UserControllerTest)
[/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/deprecated_assertions.rb:23:in `assert_session_has'
./test/functional/user_controller_test.rb:190:in `do_change_password'
./test/functional/user_controller_test.rb:198:in `test_change_password']:
<"user"> is not in the session <#<ActionController::TestSession:0x247a894
@attributes={"user"=>nil, "flash"=>{}}>>
@attributes={"return-to"=>"/bogus/location", "flash"=>{}}>>
4. Failure:
test_signup(UserControllerTest)
[/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/deprecated_assertions.rb:13:in `assert_redirect'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/deprecated_assertions.rb:98:in `assert_redirect_url'
./test/functional/user_controller_test.rb:40:in `do_test_signup'
./test/functional/user_controller_test.rb:148:in `test_signup']:
Expected response to be a <:redirect>, but was <200>
10 tests, 68 assertions, 3 failures, 1 errors
rake aborted!
Command failed with status (1): [/usr/local/bin/ruby -Ilib:test ”/usr/local…]
I’ve started debugging it myself. It looks like when I request and email for a forgotten password, change_password does not do anything with the key, so you never have a user properly instantiated. Anyway, I figured I shouldn’t be debugging this myself. Am I missing something or is this flawed?
Thanks,
Ryan
For Ryan’s Failure#1: the test is wrong. When calling do_change_password with bad_email=true, the password actually did get changed, but we’re trying to login with the old password instead of the changed password. So assert_session_has “user” should actually fail… correct behavior, wrong assertion.
Great software. I followed the instructions and got it working on my Ubuntu in 30 minutes. I only had to change the sql query to create the database so I included the 3 missing fields and removed the DEFAULT CHARSET thing (not working on MySQL < 4.1) on README_USR_LOGIN:
CREATE TABLE users (
id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
login VARCHAR(80) NOT NULL,
salted_password VARCHAR(40) NOT NULL,
email VARCHAR(60) NOT NULL,
firstname VARCHAR(40),
lastname VARCHAR(40),
salt CHAR(40) NOT NULL,
verified INT default 0,
role VARCHAR(40) default NULL,
security_token CHAR(40) default NULL,
token_expiry DATETIME default NULL,
created_at DATETIME default NULL,
updated_at DATETIME default NULL,
logged_in_at DATETIME default NULL,
deleted INT default 0,
delete_after DATETIME default NULL
) TYPE=InnoDB;
Thanks!
Jaime Iniesta
[see my comments later…]
Maybe I’m missing somethng, but I find that the only way to “reload” the localization strings is by restarting my webserver. I’m using Lighttpd.. is there a better way to do this? How do you reload/rerun the environments.rb file without restarting the webserver. For now I’ve included “Localization::load_localized_strings” in my application.rb file and that seems to have done the trick, but I’d like to know how to do this properly. Thanks, Ryan
Not so happy now… this login generator fails sometimes… when I try to put authentication control on some of the controllers (not on the whole application), the verification link by email doesn’t work… I’ve been advised by many people to use the acts_as_authenticated plugin instead.
Jaime IniestaUserNotify.deliver_signup(User.new, ””, ””)
Errno::EBADF: Bad file descriptor – connect(2)
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/net/protocol.rb:206:in `initialize’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/net/protocol.rb:206:in `old_open’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/timeout.rb:56:in `timeout’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/net/protocol.rb:206:in `old_open’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/net/smtp.rb:393:in `do_start’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/net/smtp.rb:378:in `start’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/1.8/net/smtp.rb:316:in `start’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer/base.rb:447:in `perform_delivery_smtp’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer/base.rb:333:in `deliver!’
from C:/Emil/Annat/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer/base.rb:227:in `method_missing’
and my development.rb looks like this (with real smtp adress instead of example):
ActionMailer::Base.server_settings = {For those trying to use Gmail as an smtp server, there is some additional setup that needs to take place. Here is a good explanation:
http://stephenchu.blogspot.com/2006/06/how-to-use-gmail-smtp-server-to-send.html
Does anyone know if it is possible to change your email address? I included “email” in the changeable_fields array of the edit action, but that didn’t work. It doesn’t look like it is set up to handle this. Are there any thoughts on how this could be done?
I’ve been working through the code to try and understand how it functions. Stuck on one bit though. I note that after signup the welcome action is called from the Click Me link in the email. I note also that the user table is read and updated before (I think) the empty welcome action is called. How is this database read/update triggered? I am fairly new to Rails so I may be overlooking something very obvious.
- LeeMatt
This is kind of silly and I’m new to RoR but where is the README for SaltedLoginGenator? I’ve been to the project site but I can’t find the README because there’s nothing listed under documentations. Can someone please point me to the README or some sort of documentation? I have no idea what table or columns to create.
Thanks.
-Hang Cheng
I have two different classes of users in my app. Any tips on how to create two different login systems for them using this? Thanks.
-George
Thu May 03 00:41:31 -0400 2007: Error calling Dispatcher.dispatch #
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:422:in `remove_const’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:422:in `send’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:422:in `remove_constant’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:273:in `remove_unloadable_constants!’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:273:in `each’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:273:in `remove_unloadable_constants!’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:72:in `clear’
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:60:in `reset_application!’
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:116:in `reset_after_dispatch’
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:51:in `dispatch’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:78:in `process’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `synchronize’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `process’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:618:in `process_client’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `each’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `process_client’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `initialize’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `new’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `initialize’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `new’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:271:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `each’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:127:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/command.rb:211:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:243
C:\ruby\bin\mongrel_rails:16:in `load’
C:\ruby\bin\mongrel_rails:16
-e:3:in `load’
-e:3
fixed the above witth this:
http://rc3.org/2007/02/resolving_the_n.php
I can’t get the change password to work how come? Am I supposed to add something to the source code from the basic when I first install it? Because it seems like the change_password function does nothing. It verifies the both passwords are identical and that’s it. What anyone help me out on that one?
Thanks,
Luc
When I try generate the code, I get the following error:
C:\ruby\app>ruby script/generate salted_login User Localization
DEPRECATION WARNING: server_settings has been renamed smtp_settings, this warning will be removed with rails 2.0 See http://www.rubyonrails.org/deprecation for details. (called from load_environment
at ./script/../config/../config/environments/development.rb:23)
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’: no such file to load—environments/localization_environment (MissingSourceFile)
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
from ./script/../config/../config/environment.rb:62
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in’
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’
from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/generate.rb:1
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `gem_original_require’
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `require’
from script/generate:3
I’m running rails 2.0.2 on Suse 10.1. The output of the functional tests look odd to me:
david@hathor:/Projects/folklist> rake\ test:functionals
(in /home/david/Projects/folklist)
/usr/bin/ruby -Ilib:test ”/usr/lib64/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb”
david@hathor:/Projects/folklist>
No results, no errors. Any idea what’s going on here?
ThanksI have a functional test failure that I don’t know how to fix:
david@hathor:~/Projects/folklist> rake test:functionals
(in /home/david/Projects/folklist)
/usr/bin/ruby -Ilib:test ”/usr/lib64/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb” “test/functional/user_controller_test.rb”
Loaded suite /usr/lib64/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader
/home/david/Projects/folklist/test/mocks/test/time.rb:10:in `now_old’: stack level too deep (SystemStackError)
from /home/david/Projects/folklist/test/mocks/test/time.rb:13:in `now_old’
from ./test/functional/../mocks/test/time.rb:13:in `now’
from /usr/lib64/ruby/1.8/test/unit/ui/testrunnermediator.rb:32:in `run_suite’
from /usr/lib64/ruby/1.8/test/unit/ui/console/testrunner.rb:65:in `start_mediator’
from /usr/lib64/ruby/1.8/test/unit/ui/console/testrunner.rb:39:in `start’
from /usr/lib64/ruby/1.8/test/unit/ui/testrunnerutilities.rb:27:in `run’ from /usr/lib64/ruby/1.8/test/unit/autorunner.rb:200:in `run’
from /usr/lib64/ruby/1.8/test/unit/autorunner.rb:13:in `run’
from /usr/lib64/ruby/1.8/test/unit.rb:285
from /usr/lib64/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb:5
How do I solve a “stack level too deep” error?
Thanks
Change test/mocks/test/time.rb to read:
require 'time'
Time.class_eval {
@@advance_by_days = 0
@@now_old = Time.now
cattr_accessor :advance_by_days
cattr_accessor :now_old
cattr_accessor :now_temp
class << Time
def now
if Time.advance_by_days != 0
Time.now_temp = Time.now_old
Time.now_old = Time.at(Time.now_old.to_i + Time.advance_by_days * 60 * 60 * 24 + 1)
Time.advance_by_days = 0
else
now_old
end
end
def reset
Time.now_old = Time.now_temp
end
end
}
Frankly, I don’t know how the old one ever worked. It was a recursive function that would loop forever if advance_by_days == 0. That is why you ran out of stack space.
Now this causes some other problems in the functional tests. If you read the above code you should be able to figure out what the issue is. To fix it just replace
Time.advance_by_days = 0
Time.reset
—actually thinking about it some more… this will not yield real values for “now” when called with advance_by_days ==0. But all these functional tests need is a starting point – the other calculations are just relative to the initial time so this will work fine for the given functional tests. Cheers.
Bath and Shower
Fragrance
Gift Sets
Hair Care
Makeup
Men’s Grooming
Shaving and Hair Removal
Skin Care
Tools and Accessories
Baby Apparel
Baby Bathing & Skin Care
Baby Bedding
Baby Car Seats
Baby Diapering
Baby Feeding
For Moms
Baby Furniture
Baby Gear
Baby Gifts
Baby Health & Baby Care
Nursery Décor
Potty Training
Baby Safety
Baby Strollers