HI ,
i have some doubts on sign up feature in rails application (2.3.10)
in my views/users/new.html.erb
&l开发者_如何学JAVAt;div id="signup_form" style="display:none;" class="login-drpdwn ">
<% form_for :user, :url => users_path do |f| -%>
<%= error_messages_for 'user' %><br/>
<div>
<p> Enter your name </p>
<%= f.text_field :name, :class => "text_box" %>
<p> Enter your login name </p>
<%= f.text_field :login, :class => "text_box" %>
<p> Email ID</p>
<%= f.text_field :email, :class => "text_box" %>
<p> Password</p>
<%= f.password_field :password, :class => "text_box" %>
<p> Confirm your password</p>
<%= f.password_field :password_confirmation, :class => "text_box" %>
<div class="textalign_right">
<input type="submit" value="Submit" class="submit_button rounded_corner"/>
</div>
</div>
<% end %>
</div>
In my Users controller
before_filter :login_required, :except => [:new, :create, :forgot, :reset, :process_forgot_password, :activate]
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
redirect_to "/blogs/home",:notice => "signed up"
else
redirect_to "new"
end
end
In my User model
before_save :encrypt_password
attr_protected :id, :password_salt
attr_accessor :password, :password_confirmation
def self.authenticate(email, password)
user = find_by_email(email)
if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
user
else
nil
end
end
def encrypt_password
if password.present?
self.password_salt = BCrypt::Engine.generate_salt
self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
end
end
In my sessions controller - create method
def create
@current_user = User.find_by_login(params[:login].downcase)
if @current_user.blank? || params[:password] != @current_user.password_hash
@current_user = nil
render :action => "new"
else
session[:user_id] = @current_user.id
session[:close_time] = 1800.seconds.from_now
if @current_user.last_login.nil?
@login = LastLogin.new
@login.user_id = @current_user.id
@login.login_at = Time.now
@login.save
else
@login = @current_user.last_login
@login.last_at = @login.login_at
@login.login_at = Time.now
@login.login_count += 1
@login.save
end
if session[:return_to]
redirect_to session[:return_to], :protocol => USE_PROTOCOL
session[:return_to] = nil
else
end
end
end
when i submit the sign up page the user is getting created but not the session so its not directing to the blogs /home page as it has before_filter :login_required there in blogs controller..
how to resolve this My code is not having include Authenticated system line
session[:id] = @current_user.id
精彩评论