Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 877963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:41:42+00:00 2026-05-15T11:41:42+00:00

I store all session information in database. The user can login the system for

  • 0

I store all session information in database. The user can login the system for do something. There are some restricted area required user login. If the user try to reach those area before login, the system will redirect them to login page.

Sometimes user may close the browser without logout. If this happen, next time when he try to login, the system cannot recognized the newly generate session, even the user typed in the correct username and password. The system will then force the user login again.

Would anyone know how to fix this? I tried to reset the session using reset_session before loading the login page. The problem cannot be fixed.

Session Controller

  def new
  end

  def create
    session[:current_account] = Account.authenticate(params[:email], params[:password])
    if session[:current_account]
      redirect_to :controller => "xxxxx", :action => "index"
    else
      flash[:notice] = "Please try again."
      render :action => 'new'
    end
  end

Account Model

  def self.authenticate(email, pass)
    account = find_by_email(email)
    account && account.authenticated?(pass) ? account : nil
  end

  def authenticated?(pass)
    encrypted_password == Account.encrypt(pass,salt)
  end

Xxxxx Controller

  before_filter :permission_handling

  def index
  end

Application Controller

  def permission_handling
    unless logged_in?
      forced_login
    end
  end

  def logged_in?
    session[:current_account].is_a?(Account)
  end

  def forced_login
    flash[:notice] = "You haven't login yet!"
    redirect_to ( :controller => "sessions", :action => "new" )
  end

Thanks all. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:41:43+00:00Added an answer on May 15, 2026 at 11:41 am

    It looks like you’re storing an Account object in the session. This is not recommended: you should store just simple values, like the account id in session.

    Change Model.authenticate to return account.id, and check logged_in by loading the account from the database instead of keeping it in the session.

    I’m not sure if this fully addresses the problem though, but it might be significant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi all i want to know that we can store information and session information
Is it best to store all the users information in session cookies like this
In my app I use a static database to store all counties and census
i have some timedate information of my users in my database. Also i have
Long introduction: Normally all data necessary for my web application are stored in session
I would like to store all paths to headers in separate file. I'm going
Not able to store all binary data values into sqlite3 table using QT. For
I was attempting to store all the JMS object of the class Message recieved
I want to store all of the data that is kept in encoding_symbols_tab [0]
I don't want to store all my NuGet packages in my source code repository.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.