root/openid/files/lib/system/event/listener/UserLoginOpenIDListener.class.php @ 1382

Revision 1382, 2.8 kB (checked in by Torben Brodt, 2 years ago)

some openid fixes

Line 
1<?php
2require_once(WCF_DIR.'lib/system/event/EventListener.class.php');
3require_once(WCF_DIR.'lib/data/openid/OpenID.class.php');
4
5/**
6 * login will display openid login button and manage all the login stuff
7 *
8 * @author      Torben Brodt
9 * @license     GNU General Public License <http://opensource.org/licenses/gpl-3.0.html>
10 * @package     de.easy-coding.wcf.openid
11 */
12class UserLoginOpenIDListener implements EventListener {
13        protected static $ignoreForms = array(
14                'rulesagree',
15                'userprofileedit',
16                'accountmanagement',
17        );
18        protected static $ignorePages = array(
19                'legalnotice'
20        );
21
22        /**
23         * @see EventListener::execute()
24         */
25        public function execute($eventObj, $className, $eventName) {
26                if (!MODULE_OPENID) {
27                        return;
28                }
29
30                switch($className) {
31                       
32                        // did agree with rules?
33                        case 'SessionFactory':
34                                // didInit
35                                $this->validateRuleAgree($eventObj->session);
36                        break;
37                        case 'UserLoginForm':
38                        case 'OpenIDPage':
39                                // assignVariables
40                                WCF::getTPL()->assign(array(
41                                        'openid_url' => PAGE_URL.'/index.php?page=OpenID',
42                                ));
43
44                                WCF::getTPL()->append('additionalFields', WCF::getTPL()->fetch('openidLogin'));
45                        break;
46                }
47        }
48
49        /**
50         *
51         */
52        protected function validateRuleAgree($session) {
53               
54                // if the modul deactivated, or the user must no agree the rules, we can leave the event.
55                // if we log out or on the rulesagree page, we also leave the event.
56                if (MODULE_RULE == 0 || $session->getUser()->getPermission('admin.general.canIgnoreRules')) return;
57                if ((isset($_REQUEST['action']) && strtolower($_REQUEST['action']) == 'userlogout') || (isset($_REQUEST['form']) && in_array(strtolower($_REQUEST['form']), self::$ignoreForms)) || (isset($_REQUEST['page']) && in_array(strtolower($_REQUEST['page']), self::$ignorePages))) return;
58               
59                // if the modul activate and the user is openid user he must agree the rules after a change, and the user is not a guest.
60                if ($session->getUser()->userID && OpenID::hasOpenIDAccount($session->getUser()->userID)) {
61                        // select all packageids of the packages where the user is agree with the rules.
62                        $packageIDs = $session->getVar('package_agrees');
63                       
64                        // if the packageid array null or the current package is not in the id, must check the agreement.
65                        if (is_null($packageIDs) || !in_array(PACKAGE_ID, $packageIDs)) {
66                                // we check the agreement, is the user agree with the rules, we put the package id in to the array and leave the event.
67                                if (Ruleset::isUserAgree($session->getUser()->userID, PACKAGE_ID)) {
68                                        if (is_null($packageIDs) || !is_array($packageIDs)) 
69                                                $packageIDs = array(PACKAGE_ID);
70                                        else $packageIDs[] = PACKAGE_ID;
71                                                $session->register('package_agrees', $packageIDs);
72                                        return;
73                                }
74                                HeaderUtil::redirect('index.php?form=RulesAgree'.SID_ARG_2ND_NOT_ENCODED, false);
75                                exit;
76                        }
77                }
78        }
79}
80?>
Note: See TracBrowser for help on using the browser.