在 HumHub 中使用第三方应用程序获取用户详细信息 [英] Getting User details with third party app in HumHub

查看:13
本文介绍了在 HumHub 中使用第三方应用程序获取用户详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 humhub 构建一个自定义网络研讨会.我正在使用 Custom_pages 模块(https://www.humhub.org/marketplace/details?id=13)如何在我的应用中获取当前登录用户的用户详细信息?

I am building a custom webinar for humhub. I am using the Custom_pages modules (https://www.humhub.org/marketplace/details?id=13) How can i get the user details of the current logged in user inside my app?

有人给了我这个代码让我试试

Someone gave me this code to try

//plug in to Yii application
require_once('../protected/vendors/yii/yii.php');
Yii::createWebApplication('../protected/config/main.php');

//------------------

//print_r(Yii::app());

echo "<br />";

//check if user is logged in (not a guest)
if(!Yii::app()->user->isGuest)
{
    //if logged in, display the username and ID
    echo "<strong>Logged In.</strong>";
    echo "<br />";
    echo "Username: ".Yii::app()->user->name;
    echo "<br />";
    echo "User ID: ".Yii::app()->user->id;
}
else
{
    //if not logged in, display username (Guest)
    echo "<strong>Not Logged In.</strong>";
    echo "<br />";
    echo "Username: ".Yii::app()->user->name;
}

但由于某种原因line 3 使页面无法加载.如果我将其注释掉,页面会加载但 Yii 为空.

But for some reason line 3 makes the page not load. if i comment it out, the page loads but Yii is empty.

有什么办法可以在我的第三方应用中获取登录用户的用户详细信息?

Is there any way i can get the user details of the logged in user in this my third party app?

任何方法将不胜感激

推荐答案

更简单:

$userUsername = Yii::$app->user->identity->username;

其他有用的变量:

$userDisplayName = Yii::$app->user->identity->getDisplayName();
$userAttributesArray = Yii::$app->user->identity->getSearchAttributes(); // all profile fields and groups      
$userIsGuest = Yii::$app->user->isGuest; // true = loggedOut, false = loggedIn
$userIsAdmin = \humhub\modules\admin\widgets\AdminMenu::canAccess();

这篇关于在 HumHub 中使用第三方应用程序获取用户详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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