Forum: Ruby on Rails Create a logging system

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sylvain P. (Guest)
on 2009-01-04 12:27
(Received via mailing list)
Hello.

I would like to create a loggin system. I have a players model with
name and passwd. Then, I would like to put the player item in the
session.

When I try to loggin, it create a player, so, I'm kind of lost here :

login_controller.rb :

class LoginController < ApplicationController
  def index
    if request.get?
      session[:current_user]=nil
      @Player = Player.new
    else
      @Player = Player.new(params[:player])
      logged_in_user = @Player.try_to_login
      if logged_in_user
        session[:current_user]=logged_in_user
      else
        flash[:notice] = "Utilisateur invalide"
    end
  end
  end
end




player.rb

class Player < ActiveRecord::Base
  has_one :accessory
  has_many :possessions
  has_many :games, :through =>:possessions, :select =>
"possessions.user_notation, possessions.user_comment, games.*"

  def self.login (name, password)
    find(:first, :conditions => ["name = ? and password = ?", name,
password])
  end

  def try_to_loggin
    Player.login(self.name, self.password)
  end

end


index.html.erb in login

<% form_for(@Player) do |f| %>
 <%= f.error_messages %>
  <p>
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.text_field :password %>
  </p>
  <p>
  <%= f.submit "Login" %>
    </p>
  <% end %>

Any ideas ? Link that can help ? Thanks !
Ryan B. (Guest)
on 2009-01-04 13:34
(Received via mailing list)
Use something like restful_authentication
http://github.com/technoweenie/restful_authentication
-----
Ryan B.
Freelancer
http://frozenplague.net
Sylvain P. (Guest)
on 2009-01-04 13:43
(Received via mailing list)
There's no way of doing it simply ? Because I'm kind of new in Ror,
and I'd like to work this out with only the basics.
Sylvain P. (Guest)
on 2009-01-04 14:32
(Received via mailing list)
Ok, I've finally found this
http://codingbitch.com/p/comboy/User+authenticatio...
Adapting this is fine.
This topic is locked and can not be replied to.