質問

I'm brand new to rails (3.2) and I'm looking for a way to allow users to login using their Database ID and password. Reading the documentation, Authlogic seems to allow login using a login name or email. Is it possible to somehow extend the gem such to allow a user to authenticate by providing their database ID and password?

Here is my current user model

class User < ActiveRecord::Base
attr_accessible :password, :password_confirmation, :current_login_ip, :email, :failed_login_count, :first_name, :last_login_ip, :last_name, :last_request_at, :login_count, :password_salt,
              :perishable_token, :persistence_token, :single_access_token

acts_as_authentic
end

And my current User Session model

class UserSessionsController < ApplicationController

  def new
    @user_session = UserSession.new
  end

  def create
    @user_session = UserSession.new(params[:user_session])
    if @user_session.save
      flash[:notice] = "Successfully logged in."
      redirect_to root_url
    else
      render :action => 'new'
    end
  end

  def destroy
    if UserSession.find
      UserSession.find.destroy
      flash[:notice] = "Successfully logged out."
    end

    redirect_to root_url
  end
end

My current setup uses email address authentication.

Thanks in advance!

役に立ちましたか?

解決

Authlogic allows you to choose the column to use as the login field. See the Login::Config module (login_field option):

acts_as_authentic do |c|
  c.login_field = :database_id_or_whatever_fits_your_needs
end
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top