在 HumHub 中使用第三方应用程序获取用户详细信息

编程入门 行业动态 更新时间:2024-10-23 20:31:40
本文介绍了在 HumHub 中使用第三方应用程序获取用户详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

I am building a custom webinar for humhub. I am using the Custom_pages modules (https://www.humhub/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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 18:35:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047582.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:详细信息   第三方   应用程序   用户   HumHub

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!