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 7833759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:52:51+00:00 2026-06-02T12:52:51+00:00

I am working on a basic authentication system for a rails app. The authentication

  • 0

I am working on a basic authentication system for a rails app. The authentication is verifying account information from Active Directory using a net-ldap class (this part is working fine).

Something seems to be wrong with my session_helper however. Even though ActiveDirectoryUser.authenticate is successful, the signed_in helper always returns false. After signing in, the script redirects to root_path (default_controller’s home) and then immediately redirects back to signin_path again– as a result of the signed_in helper returning false.

See the code below. What am I missing?

Thanks

application_controller.rb

class ApplicationController < ActionController::Base
  protect_from_forgery
  include SessionsHelper
end

default_controller.rb

class DefaultController < ApplicationController
  before_filter :signed_in_user

  def home
  end

  private
    def signed_in_user
      redirect_to signin_path, notice: "Please sign in." unless signed_in?
    end
end

sessions_helper.rb

module SessionsHelper
  def sign_in(user)
    @current_user = user
  end

  def current_user
    @current_user ||= nil
  end

  def signed_in?
    !@current_user.nil?
  end

  def sign_out
    @current_user = nil
  end
end

sessions_controller.rb

class SessionsController < ApplicationController
  def new
  end

  def create    
    user = ActiveDirectoryUser.authenticate(params[:session][:username],params[:session][:password])

    if user.nil?
      # authentication failed
      flash.now[:error] = 'Invalid email/password combination'
      render 'new'
    else
      # authentication succeeded
      sign_in @user
      flash[:error] = 'Great success'
      redirect_to root_path
    end
  end

  def destroy
    sign_out
    redirect_to root_path
  end
end
  • 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-06-02T12:52:52+00:00Added an answer on June 2, 2026 at 12:52 pm

    You should use session for to persist that kind of data (will be assessable for every request), it’s user data. But I highly recommend you to use something like the devise gem that do all that authentication things and more for you. Why reinvent the weel right?

    I believe this would work for you.

    module SessionsHelper
      def sign_in(user)
        session[:user_id] = user.id
      end
    
      def current_user
        ActiveDirectoryUser.find(session[:user_id]) ||= nil
      end
    
      def signed_in?
        !session[:user_id].nil?
      end
    
      def sign_out
        session[:user_id] = nil
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get basic http authentication working on my Rails app. I'm offering
I'm trying to get some basic authentication/authorization with devise/cancan with Rails. Rather than using
I'm using Rails 3 and Devise for authentication. I have a proper working devise
I'm working on a site that uses basic authentication. Using Chrome I've logged in
I built an authentication system for my app following these Railscasts: http://railscasts.com/episodes/250-authentication-from-scratch and http://railscasts.com/episodes/274-remember-me-reset-password
I'm currently working on basic user authentication for an app I'm putting together, and
I'm working on a basic google applications based system. Like I earlier defined I'm
I'm working with a basic Java app on Heroku utilizing scribe for OAuth access
Working with a Visual Basic.NET console application that features a VERY BASIC natural language
I have basic authentatication working with REST API using curl: curl -X POST -H

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.