什么是devise authenticate_user的代码?生成后为:用户 [英] What is code for devise authenticate_user! after generated for :user

查看:350
本文介绍了什么是devise authenticate_user的代码?生成后为:用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到 authenticate_user!未明确定义,但是我想知道典型的应用程序(名为 User 的模型的身份验证),那么方法看起来像。我需要知道,所以我可以稍微修改一下。

I realize that authenticate_user! is not explicitly defined in the gem files, but I am wondering for the typical app (authentication on model named User), what would the method look like. I need to know so that I can modify it slightly.

推荐答案

我相信你链接到自己的答案,它定义的方法是

I believe you linked to your own answer, the method it defines is

def authenticate_#{mapping}!(opts={})
  opts[:scope] = :#{mapping}
  warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
end

如果我们替换真正的类,您的案例用户,它看起来像:

Which if we substituted the true class, in your case User, it would look like:

def authenticate_user!(opts={})
  opts[:scope] = :user
  warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
end

所以它真的要求监管者是认证逻辑的大部分位置。

So it really calls out to warden and that is where the bulk of the authentication logic lies.

对于典型的Rails应用程序, authenticate_user!方法将在 ApplicationController 中定义为 instance_method

For a typical Rails application, The authenticate_user! method will be defined as an instance_method on ApplicationController.

这篇关于什么是devise authenticate_user的代码?生成后为:用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆