开发者

How to authenticate the primary key?

i can't authenticate the Transaction_Id where this is the primary key of my transaction table, while i can do it with the email. what would seem to be the problem? help. thanks.

here's my model/transaction:

def self.authenticate(email, transaction_id)
    user = Transaction.find_by_email(email)
    if user && user.Transaction_Id
      return user
    else
      return false
    end
end

here's my controller/modifications:

  def attempt_login
    user = Transaction.authenticate(params[:email], params[:Transaction_Id])
    if user
        session[:user_id] = user.id
        se开发者_开发技巧ssion[:email] = user.email
        flash[:notice] = "You are now logged in!"
        redirect_to :action => "modify"
    else
        flash[:notice] = "Invalid username/password  combination."
        redirect_to :action => "login"
    end
  end

and here's my view/login:

<div class="login">
    <%= form_tag :action => "attempt_login" do %>

        <%= label_tag :email, "Email Address:" %>
        <%= text_field_tag :email %>
        <%= label_tag :Transaction_Id, "Transaction Id:" %>
        <%= text_field_tag :Transaction_Id %>

        <%= submit_tag "Log In"%>   
    <% end %>
</div>


You check only if there is a transaction_id present in your found user object, but you do not compare this id to the given id, so try:

def self.authenticate(email, transaction_id)
    user = Transaction.find_by_email(email)
    if user && user.Transaction_Id == transaction_id
      return user
    else
      return false
    end
end

or (don't know if it works)

def self.authenticate(email, transaction_id)
    user = Transaction.find_by_email_and_transaction_id(email, transaction_id)
    if user
      return user
    else
      return false
    end
end

in short:

# will return user if found; else nil
def self.authenticate(email, transaction_id)
    Transaction.find_by_email_and_transaction_id(email, transaction_id)
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜