Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/config/console.php b/config/console.php
- index 299656a..32b7f27 100644
- --- a/config/console.php
- +++ b/config/console.php
- @@ -8,6 +8,11 @@ $config = [
- 'basePath' => dirname(__DIR__),
- 'bootstrap' => ['log'],
- 'controllerNamespace' => 'app\commands',
- + 'enableCoreCommands' => false,
- + 'controllerMap' => [
- + 'help' => 'yii\console\controllers\HelpController',
- + 'migrate' => 'yii\console\controllers\MigrateController',
- + ],
- 'aliases' => [
- '@bower' => '@vendor/bower-asset',
- '@npm' => '@vendor/npm-asset',
- @@ -26,15 +31,13 @@ $config = [
- ],
- ],
- 'db' => $db,
- - ],
- - 'params' => $params,
- - /*
- - 'controllerMap' => [
- - 'fixture' => [ // Fixture generation command line.
- - 'class' => 'yii\faker\FixtureController',
- + 'forumdb' => [
- + 'class' => 'yii\db\Connection',
- + 'dsn' => 'sqlite:@app/forum/app.db',
- + 'tablePrefix' => 'mybb_',
- ],
- ],
- - */
- + 'params' => $params,
- ];
- if (YII_ENV_DEV) {
- diff --git a/config/web.php b/config/web.php
- index 4b27b03..32a7da8 100644
- --- a/config/web.php
- +++ b/config/web.php
- @@ -20,7 +20,7 @@ $config = [
- 'class' => 'yii\caching\FileCache',
- ],
- 'user' => [
- - 'identityClass' => 'app\models\User',
- + 'identityClass' => 'app\models\MyBBUser',
- 'enableAutoLogin' => true,
- ],
- 'errorHandler' => [
- @@ -43,6 +43,11 @@ $config = [
- ],
- ],
- 'db' => $db,
- + 'forumdb' => [
- + 'class' => 'yii\db\Connection',
- + 'dsn' => 'sqlite:@app/forum/app.db',
- + 'tablePrefix' => 'mybb_',
- + ],
- /*
- 'urlManager' => [
- 'enablePrettyUrl' => true,
- diff --git a/forum/app.db b/forum/app.db
- index 7bcab9d..6c01166 100644
- Binary files a/forum/app.db and b/forum/app.db differ
- diff --git a/forum/member.php b/forum/member.php
- index 9adb8c5..048b876 100644
- --- a/forum/member.php
- +++ b/forum/member.php
- @@ -8,6 +8,8 @@
- *
- */
- +require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';
- +
- define("IN_MYBB", 1);
- define("IGNORE_CLEAN_VARS", "sid");
- define('THIS_SCRIPT', 'member.php');
- @@ -689,6 +691,12 @@ if($mybb->input['action'] == "coppa_form")
- if($mybb->input['action'] == "register")
- {
- + // This is an action that i can call via GET
- + $config = require __DIR__ . '/../config/web.php';
- + $app = (new yii\web\Application($config));
- + var_dump($app->user->getIsGuest()); // false when loggedin in Yii, true when logged out in Yii
- + var_dump($app->user->getIdentity()->username); // prints my forum username when logged in
- +
- $bdaysel = '';
- if($mybb->settings['coppa'] == "disabled")
- {
- @@ -1883,6 +1891,12 @@ if($mybb->input['action'] == "do_login" && $mybb->request_method == "post")
- $loginhandler->complete_login();
- + // This is the code that is called when forum login was successful
- + $config = require __DIR__ . '/../config/web.php';
- + $app = (new yii\web\Application($config));
- + $user = app\models\MyBBUser::findByUsername($mybb->get_input('username'));
- + $app->user->login($user);
- +
- $plugins->run_hooks("member_do_login_end");
- $mybb->input['url'] = $mybb->get_input('url');
- diff --git a/models/MyBBUser.php b/models/MyBBUser.php
- new file mode 100644
- index 0000000..083e6df
- --- /dev/null
- +++ b/models/MyBBUser.php
- @@ -0,0 +1,276 @@
- +<?php
- +
- +namespace app\models;
- +
- +use Yii;
- +
- +/**
- + * This is the model class for table "mybb_users".
- + *
- + * @property int $uid
- + * @property string $username
- + * @property string $password
- + * @property string $salt
- + * @property string $loginkey
- + * @property string $email
- + * @property int $postnum
- + * @property int $threadnum
- + * @property string $avatar
- + * @property string $avatardimensions
- + * @property string $avatartype
- + * @property int $usergroup
- + * @property string $additionalgroups
- + * @property int $displaygroup
- + * @property string $usertitle
- + * @property int $regdate
- + * @property int $lastactive
- + * @property int $lastvisit
- + * @property int $lastpost
- + * @property string $website
- + * @property string $icq
- + * @property string $yahoo
- + * @property string $skype
- + * @property string $google
- + * @property string $birthday
- + * @property string $birthdayprivacy
- + * @property string $signature
- + * @property bool $allownotices
- + * @property bool $hideemail
- + * @property bool $subscriptionmethod
- + * @property bool $invisible
- + * @property bool $receivepms
- + * @property bool $receivefrombuddy
- + * @property bool $pmnotice
- + * @property bool $pmnotify
- + * @property bool $buddyrequestspm
- + * @property bool $buddyrequestsauto
- + * @property string $threadmode
- + * @property bool $showimages
- + * @property bool $showvideos
- + * @property bool $showsigs
- + * @property bool $showavatars
- + * @property bool $showquickreply
- + * @property bool $showredirect
- + * @property int $ppp
- + * @property int $tpp
- + * @property int $daysprune
- + * @property string $dateformat
- + * @property string $timeformat
- + * @property string $timezone
- + * @property bool $dst
- + * @property bool $dstcorrection
- + * @property string $buddylist
- + * @property string $ignorelist
- + * @property int $style
- + * @property bool $away
- + * @property int $awaydate
- + * @property string $returndate
- + * @property string $awayreason
- + * @property string $pmfolders
- + * @property string $notepad
- + * @property int $referrer
- + * @property int $referrals
- + * @property int $reputation
- + * @property resource $regip
- + * @property resource $lastip
- + * @property string $language
- + * @property int $timeonline
- + * @property bool $showcodebuttons
- + * @property int $totalpms
- + * @property int $unreadpms
- + * @property int $warningpoints
- + * @property bool $moderateposts
- + * @property int $moderationtime
- + * @property bool $suspendposting
- + * @property int $suspensiontime
- + * @property bool $suspendsignature
- + * @property int $suspendsigtime
- + * @property bool $coppauser
- + * @property bool $classicpostbit
- + * @property int $loginattempts
- + * @property int $loginlockoutexpiry
- + * @property string $usernotes
- + * @property bool $sourceeditor
- + */
- +class MyBBUser extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface
- +{
- + /**
- + * {@inheritdoc}
- + */
- + public static function tableName()
- + {
- + return 'mybb_users';
- + }
- +
- + /**
- + * @return \yii\db\Connection the database connection used by this AR class.
- + */
- + public static function getDb()
- + {
- + return Yii::$app->get('forumdb');
- + }
- +
- + /**
- + * {@inheritdoc}
- + */
- + public function rules()
- + {
- + return [
- + [['postnum', 'threadnum', 'usergroup', 'displaygroup', 'regdate', 'lastactive', 'lastvisit', 'lastpost', 'ppp', 'tpp', 'daysprune', 'style', 'awaydate', 'referrer', 'referrals', 'reputation', 'timeonline', 'totalpms', 'unreadpms', 'warningpoints', 'moderationtime', 'suspensiontime', 'suspendsigtime', 'loginattempts', 'loginlockoutexpiry'], 'integer'],
- + [['signature', 'buddylist', 'ignorelist', 'pmfolders', 'notepad', 'usernotes'], 'required'],
- + [['signature', 'buddylist', 'ignorelist', 'pmfolders', 'notepad', 'usernotes'], 'string'],
- + [['allownotices', 'hideemail', 'subscriptionmethod', 'invisible', 'receivepms', 'receivefrombuddy', 'pmnotice', 'pmnotify', 'buddyrequestspm', 'buddyrequestsauto', 'showimages', 'showvideos', 'showsigs', 'showavatars', 'showquickreply', 'showredirect', 'dst', 'dstcorrection', 'away', 'showcodebuttons', 'moderateposts', 'suspendposting', 'suspendsignature', 'coppauser', 'classicpostbit', 'sourceeditor'], 'boolean'],
- + [['username', 'password'], 'string', 'max' => 120],
- + [['salt', 'avatardimensions', 'avatartype', 'icq'], 'string', 'max' => 10],
- + [['loginkey', 'yahoo', 'language'], 'string', 'max' => 50],
- + [['email'], 'string', 'max' => 220],
- + [['avatar', 'additionalgroups', 'website', 'awayreason'], 'string', 'max' => 200],
- + [['usertitle'], 'string', 'max' => 250],
- + [['skype', 'google'], 'string', 'max' => 75],
- + [['birthday', 'returndate'], 'string', 'max' => 15],
- + [['birthdayprivacy', 'dateformat', 'timeformat'], 'string', 'max' => 4],
- + [['threadmode'], 'string', 'max' => 8],
- + [['timezone'], 'string', 'max' => 5],
- + [['regip', 'lastip'], 'string', 'max' => 16],
- + ];
- + }
- +
- + /**
- + * {@inheritdoc}
- + */
- + public function attributeLabels()
- + {
- + return [
- + 'uid' => 'Uid',
- + 'username' => 'Username',
- + 'password' => 'Password',
- + 'salt' => 'Salt',
- + 'loginkey' => 'Loginkey',
- + 'email' => 'Email',
- + 'postnum' => 'Postnum',
- + 'threadnum' => 'Threadnum',
- + 'avatar' => 'Avatar',
- + 'avatardimensions' => 'Avatardimensions',
- + 'avatartype' => 'Avatartype',
- + 'usergroup' => 'Usergroup',
- + 'additionalgroups' => 'Additionalgroups',
- + 'displaygroup' => 'Displaygroup',
- + 'usertitle' => 'Usertitle',
- + 'regdate' => 'Regdate',
- + 'lastactive' => 'Lastactive',
- + 'lastvisit' => 'Lastvisit',
- + 'lastpost' => 'Lastpost',
- + 'website' => 'Website',
- + 'icq' => 'Icq',
- + 'yahoo' => 'Yahoo',
- + 'skype' => 'Skype',
- + 'google' => 'Google',
- + 'birthday' => 'Birthday',
- + 'birthdayprivacy' => 'Birthdayprivacy',
- + 'signature' => 'Signature',
- + 'allownotices' => 'Allownotices',
- + 'hideemail' => 'Hideemail',
- + 'subscriptionmethod' => 'Subscriptionmethod',
- + 'invisible' => 'Invisible',
- + 'receivepms' => 'Receivepms',
- + 'receivefrombuddy' => 'Receivefrombuddy',
- + 'pmnotice' => 'Pmnotice',
- + 'pmnotify' => 'Pmnotify',
- + 'buddyrequestspm' => 'Buddyrequestspm',
- + 'buddyrequestsauto' => 'Buddyrequestsauto',
- + 'threadmode' => 'Threadmode',
- + 'showimages' => 'Showimages',
- + 'showvideos' => 'Showvideos',
- + 'showsigs' => 'Showsigs',
- + 'showavatars' => 'Showavatars',
- + 'showquickreply' => 'Showquickreply',
- + 'showredirect' => 'Showredirect',
- + 'ppp' => 'Ppp',
- + 'tpp' => 'Tpp',
- + 'daysprune' => 'Daysprune',
- + 'dateformat' => 'Dateformat',
- + 'timeformat' => 'Timeformat',
- + 'timezone' => 'Timezone',
- + 'dst' => 'Dst',
- + 'dstcorrection' => 'Dstcorrection',
- + 'buddylist' => 'Buddylist',
- + 'ignorelist' => 'Ignorelist',
- + 'style' => 'Style',
- + 'away' => 'Away',
- + 'awaydate' => 'Awaydate',
- + 'returndate' => 'Returndate',
- + 'awayreason' => 'Awayreason',
- + 'pmfolders' => 'Pmfolders',
- + 'notepad' => 'Notepad',
- + 'referrer' => 'Referrer',
- + 'referrals' => 'Referrals',
- + 'reputation' => 'Reputation',
- + 'regip' => 'Regip',
- + 'lastip' => 'Lastip',
- + 'language' => 'Language',
- + 'timeonline' => 'Timeonline',
- + 'showcodebuttons' => 'Showcodebuttons',
- + 'totalpms' => 'Totalpms',
- + 'unreadpms' => 'Unreadpms',
- + 'warningpoints' => 'Warningpoints',
- + 'moderateposts' => 'Moderateposts',
- + 'moderationtime' => 'Moderationtime',
- + 'suspendposting' => 'Suspendposting',
- + 'suspensiontime' => 'Suspensiontime',
- + 'suspendsignature' => 'Suspendsignature',
- + 'suspendsigtime' => 'Suspendsigtime',
- + 'coppauser' => 'Coppauser',
- + 'classicpostbit' => 'Classicpostbit',
- + 'loginattempts' => 'Loginattempts',
- + 'loginlockoutexpiry' => 'Loginlockoutexpiry',
- + 'usernotes' => 'Usernotes',
- + 'sourceeditor' => 'Sourceeditor',
- + ];
- + }
- +
- + /**
- + * {@inheritdoc}
- + */
- + public static function findIdentity($id)
- + {
- + return static::findOne($id);
- + }
- +
- + /**
- + * {@inheritdoc}
- + */
- + public static function findIdentityByAccessToken($token, $type = null)
- + {
- + return static::find()->where(['loginkey' => $token]);
- + }
- +
- + /**
- + * {@inheritdoc}
- + */
- + public function getId()
- + {
- + return $this->getPrimaryKey();
- + }
- +
- + /**
- + * {@inheritdoc}
- + */
- + public function getAuthKey()
- + {
- + $secret = Yii::$app->request->cookieValidationKey;
- + return sha1($secret . $this->getId());
- + }
- +
- + /**
- + * {@inheritdoc}
- + */
- + public function validateAuthKey($authKey)
- + {
- + return $this->getAuthKey() === $authKey;
- + }
- +
- + public static function findByUsername($username)
- + {
- + return static::find()->where(['username' => $username])->one();
- + }
- +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement