simple rails login system

Hey All,

    Just started to play around with rails a bit today by creating a login system, but I've run into a glitch.

###user_controller.rb###

class UserController < ApplicationController

def login         @title = "Log In"         if request.post? and params[:user]                 @user = User.new(params[:user])                 @userfind = User.find_by_username_and_password(@user.username,@user.password)

                if @userfind

                        redirect_to :action => "index"

                else                         render :text => "Login Failed"                 end         end end

  def index

          db = Mysql.connect('localhost','root','godsp33d','netv_dev')         feed_url = db.query("SELECT feeds FROM users WHERE username = '#{@user.username}' AND password = '#{@user.password}'")

        feed_url.each do |x|                 x.each do |b|                         @feeds = b.split(",")                 end         end @feeds.each do |links|         open(links) do |http|                 response = http.read                 result = RSS::Parser.parse(response, false)                 result.items.each_with_index do |item, i|                         output += "#{i + 1}. <a href=\"#{item.link}\">#{item.title}</a> <br />"                 end # output += "============================================"         end

end

end

  def register

          @title = "Register"           if request.post?                   @user = User.new(params[:user])                   if @user.save                           render :text => "Account Created."                   end           end    end end

user_model.rb

Hmm..not sure what the problem with the code is...if you're interested in a fast login system, you can try the acts_as_authenticated plugin.

Just type sudo ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/acts_as_authenticated/

Then in your application.rb file, you can just type: include AuthenticatedSystem and before_filter :login_from_cookie

With it installed, you get some scripts to generate things. So: ruby script/generate authenticated user account

gives you some migrations and some views to play around with.

On the other hand, if you want to build it homegrown, I totally understand.

Ron

You can then put before_filter :login_required before any controller you want password protected.

Ron wrote:

On the other hand, if you want to build it homegrown, I totally understand.

Yeah, I saw and checked out a few things revolving around those generators, but I'm more out for knowledge than a quick solution that I would have no general idea on how it works.

Thanks a lot for the info though!

- Mac