Login does not work

S

Simon M.

Hi, could anybody help me try to get a login function working, I have
created a database for users called user1, I have the login screen set
up but when i hit login with a correct username and password, nothing
happens

I am expecting the lgin button to direct the user to the main page and
show the user as logged on, but nothing happens! Thanks!


Controller

class User1Controller < ApplicationController
def index
@title = "Temporary View"
@users = User1.find:)all)
end

def register
@title = "Register"

if request.post?
@user = User1.new(params[:user1])
if @user.save
session[:user_id] = @user.id
flash[:notice] = "User with login #{@user.screen_name} created!"
redirect_to :action => :index
end
end
end




end


def login
@title = "Title"

if request.post?
@user = User1.new(params[:user1])
user = User.find_by_screen_name_and_password(@user.screen_name,
@user.password)
if user
session[:user_id] = user.id
flash[:notice] = "User #{user.screen_name} logged in"
redirect_to :action => "index"
else
# Don't show the password in the view
@user.password = nil
flash[:notice] = "Invalid email/password combination"
end


end
end

def logout
session[:user_id] = nil
flash[:notice] = "Logged out"
redirect_to :controller => :site, :action => :index
end


end





Login View


<h1>Login</h1>
<%= error_messages_for :user %>
<% form_for :user do |f| %>
<p>
<%= f.label :screen_name %>:
<%= f.text_field :screen_name %>
</p>
<p>
<%= f.label :password %>:
<%= f.password_field :password %>
</p>
<p>
<%= f.submit "Login" %>
</p>
<p>
Not a member? <%= link_to "Register now!", :action => "register" %>
</p>

<% end %>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top