limesurvey 权限插件开发 - 接入第三方的用户系统

需求

  1. 管理员通过 oauth2 进行登录
  2. 填写问卷的用户使用已有的系统的权限认证
  3. 导出的问卷结果中需要有用户名

Limesurvey 版本

本文使用 Limesurvey 2.0.5 以上版本

解决方法

1. 管理员通过 oauth2 进行登录

可以通过编写插件来解决问题1和问题2。插件需要继承自AuthPluginBase。并在插件中订阅相关的Event:beforeLoginnewUserSessionbeforeLogout

其中,beforeLogin是在管理员登陆之前,可以在这里跳过 limesurvey 的登陆界面、进行自己的oauth2身份验证等。 newUserSession中进行真正的身份验证,将oauth2得到的用户信息与系统内的用户信息进行验证,并 setAuthSuccess。 beforeLogout则可以将相关的cookie、session等清理下。

2. 填写问卷的用户使用已有的系统的权限认证

同样是在插件中进行相关逻辑的编写。需要订阅的事件是beforeSurveyPage。也可以使用afterSurveyComplete来在用户填写完问卷后进行一些额外的操作。

插件的代码示例如下所示:

class AuthYours extends AuthPluginBase
{
    protected $storage = 'DbStorage';        
    static protected $description = 'Authentication For You';
    static protected $name = 'AuthYours';

    public function init()
    {
        $this->subscribe('beforeSurveyPage');
        $this->subscribe('afterSurveyComplete');
	$this->subscribe('beforeLogin');
        $this->subscribe('newUserSession');
        $this->subscribe('beforeLogout');
    }
    public function beforeSurveyPage(){……}
    public function afterSurveyComplete(){……}
    public function beforeLogin(){……}
    public function newUserSession(){
        …………
        $sUser = $this->getUsername(); //oauth得到的用户名信息
        $oUser = $this->api->getUserByName($sUser);
        …………
        $this->setAuthSuccess($oUser);
        …………
    }
    public function beforeLogout(){……}

3. 问卷导出的结果中添加用户名

直接hack了源代码,插件的方式也是可以的,但是工作量略有些大。

application/helpers/admin/export/writer.phpwrite方法中,对应的header数组和elementArray数组中添加需要的内容。

        // header中强行添加 用户id 字段
        array_unshift($headers, '用户ID');

        // If no empty survey, render/export responses array.
        foreach($oSurvey->responses as $response)
        {
            $elementArray = array();

            // 将对应的数据也从数据库取出,放入 elementArray 中
            $elementArray[] = $response['user_id'];

ps:
如果在你跟我类似,之前将用户ID存在了survey_{{surveyId}}这样的数据库中,其实会导致查看问卷结果的时候读不到结果。对应修改application/controller/admin/responses.php吧。 需要修改对应函数

    public function getResponses_json($iSurveyID)

转载于:https://my.oschina.net/gongshang/blog/491969

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值