LoginGenerator Problem

I am trying to make a barebones login system based on this example
(which in turn is just standard RoR login) but when I enter a user name
and password, it says the login is unsuccessful every time. I am not
sure where I am going wrong. Here is all relevent information

CREATE TABLE users (
id int(6) unsigned NOT NULL auto_increment,
login varchar(20) NOT NULL default ‘’,
password varchar(30) NOT NULL default ‘’,
name varchar(30) NOT NULL default ‘’,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CREATE TABLE ‘stuff’ (
‘id’ int(6) unsigned NOT NULL auto_increment,

‘user_id’ int(6) NOT NULL default ‘0’,

) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Stuff--------------------------
class StuffController < ApplicationController

scaffold :stuff
before_filter :login_required, :only => [:create, :edit, :new]

def create
@stuff= Stuff.new(params[:todo])
@stuff.user = @session[:user]
if @stuff.save
flash[:notice] = ‘Event was successfully created.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end

def edit
@stuff= Stuff.find(params[:id])
if @stuff.user != @session[:user]
flash[:notice] = ‘You cannot edit an article you didn’t upload.’
redirect_to :action => ‘show’, :id => @stuff
end


end
end

class Todo < ActiveRecord::Base
validates_presence_of :user
belongs_to :user
end

User------------------------------------
require ‘digest/sha1’

this model expects a certain database layout and its based on the

name/login pattern.
class User < ActiveRecord::Base

def self.authenticate(login, pass)
find_first([“login = ? AND password = ?”, login, sha1(pass)])
end

def change_password(pass)
update_attribute “password”, self.class.sha1(pass)
end

protected

def self.sha1(pass)
Digest::SHA1.hexdigest(pass)
end

before_create :crypt_password

def crypt_password
write_attribute(“password”, self.class.sha1(password))
end

validates_length_of :login, :within => 3…40
validates_length_of :password, :within => 5…40
validates_presence_of :login, :password, :password_confirmation
validates_uniqueness_of :login, :on => :create
validates_confirmation_of :password, :on => :create
end

class UserController < ApplicationController
model :user
layout ‘scaffold’

def login
case @request.method
when :post
if @session[‘user’] = User.authenticate(@params[‘user_login’],
@params[‘user_password’])

      flash['notice']  = "Login successful"
      redirect_back_or_default :action => "welcome"
    else
      @login    = @params['user_login']
      @message  = "Login unsuccessful"
  end
end

end

def signup
case @request.method
when :post
@user = User.new(@params[‘user’])

    if @user.save
      @session['user'] = User.authenticate(@user.login, 

@params[‘user’][‘password’])
flash[‘notice’] = “Signup successful”
redirect_back_or_default :action => “welcome”
end
when :get
@user = User.new
end
end

def delete
if @params[‘id’]
@user = User.find(@params[‘id’])
@user.destroy
end
redirect_back_or_default :action => “welcome”
end

def logout
@session[‘user’] = nil
end

def welcome
end

end

Use the LoginEngine available at http://rails-engines.org/login_engine.

— Neil [email protected] wrote:

name varchar(30) NOT NULL default ‘’,

  flash[:notice] = 'Event was successfully created.'

if @stuff.user != @session[:user]
belongs_to :user
find_first([“login = ? AND password = ?”, login, sha1(pass)])
end
validates_uniqueness_of :login, :on => :create
if @session[‘user’] = User.authenticate(@params[‘user_login’],

    end
redirect_back_or_default :action => "welcome"


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

http://www.ProblemSolvingSkill.net
Hone your problem-solving skills

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs