简体   繁体   English

Joomla Google身份验证插件保存新的用户记录

[英]Joomla google authentication plugin saves new user record

I've copied the Google authentication plugin for another API, but for some reason it's not saving records in Joomla. 我已经为另一个API复制了Google身份验证插件,但是由于某种原因,它没有将记录保存在Joomla中。 If I manually add the username and some random password, then my plugin does authenticate against the API correctly - but otherwise when trying to login I get the error message: "You cannot access the private section of this site." 如果我手动添加用户名和一些随机密码,那么我的插件会正确地针对API进行身份验证-否则,当尝试登录时,我会收到错误消息:“您无法访问此网站的私有部分。”

I'm not looking for coding help necessarily, I just want to know how the Google authentication plugin is saving the record. 我并不是在寻找编码帮助,我只是想知道Google身份验证插件如何保存记录。 I've got through the plugin several times looking for it, but I don't see it. 我已经多次通过插件寻找它,但我没有看到它。 I have to assume it has to do with the $response, but I'm setting each of the values that the google auth is. 我必须假定它与$ response有关,但是我正在设置google auth的每个值。 What's being called to save the record? 什么叫保存记录?

EDIT: 编辑:

Ok, clearly I have no idea how a user is logged on to Joomla. 好的,显然我不知道用户如何登录Joomla。 Why doesn't this work?? 为什么不起作用?

public function onUserAuthenticate($credentials, $options, &$response) {
    // Load plugin language
    $this->loadLanguage();

    if (empty($credentials['password'])) {
        $response->status = JAuthentication::STATUS_FAILURE;
        $response->error_message = JText::_('JGLOBAL_AUTH_EMPTY_PASS_NOT_ALLOWED');

        return false;
    } else {

        $response->status = JAuthentication::STATUS_SUCCESS;
        $response->error_message = '';
        $response->type = 'Mysite';
        $response->email = $credentials['username'];
        $response->username = $credentials['username'];
        $response->fullname = $credentials['username'];
    }
}

For people googling this and finding nothing, let me elaborate on what's happening. 对于谷歌搜索人员却一无所获的人,让我详细说明正在发生的事情。 If your non-stock Joomla authorization module ends up seeming to work, but no account is created on the back end and the user is immediately shown the message "You cannot access the private section of this site.", there are a couple of possible causes. 如果您的非库存Joomla授权模块似乎可以正常工作,但是在后端没有创建帐户,并且立即向用户显示消息“您无法访问此网站的私人部分”,则可能有两种情况原因。

First (and least likely, since you'd have to go out of your way to do this), there is an option in the stock "User - Joomla" plugin labeled "Auto-create users". 首先(也是最不可能的,因为您必须竭尽全力做到这一点),库存的“ User-Joomla”插件中有一个选项标记为“自动创建用户”。 It is enabled by default. 默认情况下启用。 If you disable it, then users who sign in via your custom authorization module will not get accounts made for them locally, and thus they will be Guests. 如果禁用它,则通过您的自定义授权模块登录的用户将不会在本地为其创建帐户,因此他们将成为来宾。 This is why the "you cannot access" message is being displayed -- by default, guests can't see stuff. 这就是为什么显示“您无法访问”消息的原因-默认情况下,访客看不到东西。 To fix this, you can either turn that autocreate option back on (but then, I presume you had a reason to turn it off?), or you can change the permissions site-wide to allow guests to access stuff like Registered users can. 要解决此问题,您可以重新打开该自动创建选项(但是我想您有理由将其关闭?),或者可以在整个站点范围内更改权限,以允许访客访问注册用户可以使用的权限。 Or your custom auth plugin can save the user manually itself. 或者您的自定义身份验证插件可以自己手动保存用户。

The more likely cause (in my experience) is that an exception is being thrown while trying to save the new user. 根据我的经验,更可能的原因是尝试保存新用户时引发了异常。 Unlike most places in Joomla!, any exception here is intercepted and hidden. 与Joomla!中的大多数地方不同,这里的任何异常都会被拦截和隐藏。 This is because the auth module succeeded, so the log in can proceed despite any exceptions that occur. 这是因为auth模块成功完成,因此尽管发生任何异常,登录仍可以继续进行。 However, since the account couldn't be saved, the user is logged in as a Guest account. 但是,由于无法保存该帐户,因此该用户以来宾帐户身份登录。 And since guest accounts can't access anything (by default), they're shown that message and then effectively logged out. 由于来宾帐户无法访问任何内容(默认情况下),因此会向他们显示该消息,然后有效注销。

To find more information about what exception is being thrown, I temporarily altered the Joomla core library's JUser class. 为了找到有关引发异常的更多信息,我临时更改了Joomla核心库的JUser类。 (In Joomla 3 this is in libraries/joomla/user/user.php.) Look for the save() function, and find where it is doing the try {} catch block, and in the catch, add something like (在Joomla 3中,这是在librarys / joomla / user / user.php中。)查找save()函数,并找到它在哪里进行try {} catch块,然后在catch中添加类似的内容

die($e->getMessage());

This will show any errors that occur during the saving process, rather than silently sweeping them under the rug. 这将显示在保存过程中发生的任何错误,而不是在地毯下悄悄地将它们清除。

If you need more info about where the exception is happening, you can get a stack trace by printing out the exception's getTraceAsString() method: 如果您需要有关异常发生位置的更多信息,则可以通过打印出异常的getTraceAsString()方法来获取堆栈跟踪:

die("<pre>".$e->getMessage()."\n\n".$e->getTraceAsString()."</pre>");

I had this problem before while trying to create an authenticate plugin for my website. 在尝试为我的网站创建身份验证插件时,我遇到了这个问题。 I trying very hard to find solutions for why my plugins didnt work ? 我非常努力地寻找为什么我的插件不起作用的解决方案? and why i keep getting: 以及为什么我不断得到:

You cannot access the private section of this site 您无法访问该网站的私人部分

Turn out the problem is not my plugins, it works perfectly. 原来问题不是我的插件,它可以完美运行。 But there already an account with the same username has been created in joomla which wasn't assigned to any user groups. 但是已经在joomla中创建了一个具有相同用户名的帐户,该帐户尚未分配给任何用户组。 That why after login, it automaticly logged out and give that error. 这就是为什么登录后会自动注销并给出该错误的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM