Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 13.21 KB | None | 0 0
  1. diff --git a/config/console.php b/config/console.php
  2. index 299656a..32b7f27 100644
  3. --- a/config/console.php
  4. +++ b/config/console.php
  5. @@ -8,6 +8,11 @@ $config = [
  6.      'basePath' => dirname(__DIR__),
  7.      'bootstrap' => ['log'],
  8.      'controllerNamespace' => 'app\commands',
  9. +    'enableCoreCommands' => false,
  10. +    'controllerMap' => [
  11. +        'help' => 'yii\console\controllers\HelpController',
  12. +        'migrate' => 'yii\console\controllers\MigrateController',
  13. +    ],
  14.      'aliases' => [
  15.          '@bower' => '@vendor/bower-asset',
  16.          '@npm'   => '@vendor/npm-asset',
  17. @@ -26,15 +31,13 @@ $config = [
  18.              ],
  19.          ],
  20.          'db' => $db,
  21. -    ],
  22. -    'params' => $params,
  23. -    /*
  24. -    'controllerMap' => [
  25. -        'fixture' => [ // Fixture generation command line.
  26. -            'class' => 'yii\faker\FixtureController',
  27. +        'forumdb' => [
  28. +            'class' => 'yii\db\Connection',
  29. +            'dsn' => 'sqlite:@app/forum/app.db',
  30. +            'tablePrefix' => 'mybb_',
  31.          ],
  32.      ],
  33. -    */
  34. +    'params' => $params,
  35.  ];
  36.  
  37.  if (YII_ENV_DEV) {
  38. diff --git a/config/web.php b/config/web.php
  39. index 4b27b03..32a7da8 100644
  40. --- a/config/web.php
  41. +++ b/config/web.php
  42. @@ -20,7 +20,7 @@ $config = [
  43.              'class' => 'yii\caching\FileCache',
  44.          ],
  45.          'user' => [
  46. -            'identityClass' => 'app\models\User',
  47. +            'identityClass' => 'app\models\MyBBUser',
  48.              'enableAutoLogin' => true,
  49.          ],
  50.          'errorHandler' => [
  51. @@ -43,6 +43,11 @@ $config = [
  52.              ],
  53.          ],
  54.          'db' => $db,
  55. +        'forumdb' => [
  56. +            'class' => 'yii\db\Connection',
  57. +            'dsn' => 'sqlite:@app/forum/app.db',
  58. +            'tablePrefix' => 'mybb_',
  59. +        ],
  60.          /*
  61.          'urlManager' => [
  62.              'enablePrettyUrl' => true,
  63. diff --git a/forum/app.db b/forum/app.db
  64. index 7bcab9d..6c01166 100644
  65. Binary files a/forum/app.db and b/forum/app.db differ
  66. diff --git a/forum/member.php b/forum/member.php
  67. index 9adb8c5..048b876 100644
  68. --- a/forum/member.php
  69. +++ b/forum/member.php
  70. @@ -8,6 +8,8 @@
  71.   *
  72.   */
  73.  
  74. +require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';
  75. +
  76.  define("IN_MYBB", 1);
  77.  define("IGNORE_CLEAN_VARS", "sid");
  78.  define('THIS_SCRIPT', 'member.php');
  79. @@ -689,6 +691,12 @@ if($mybb->input['action'] == "coppa_form")
  80.  
  81.  if($mybb->input['action'] == "register")
  82.  {
  83. +   // This is an action that i can call via GET
  84. +   $config = require __DIR__ . '/../config/web.php';
  85. +   $app = (new yii\web\Application($config));
  86. +   var_dump($app->user->getIsGuest()); // false when loggedin in Yii, true when logged out in Yii
  87. +   var_dump($app->user->getIdentity()->username); // prints my forum username when logged in
  88. +
  89.     $bdaysel = '';
  90.     if($mybb->settings['coppa'] == "disabled")
  91.     {
  92. @@ -1883,6 +1891,12 @@ if($mybb->input['action'] == "do_login" && $mybb->request_method == "post")
  93.  
  94.         $loginhandler->complete_login();
  95.  
  96. +       // This is the code that is called when forum login was successful
  97. +       $config = require __DIR__ . '/../config/web.php';
  98. +       $app = (new yii\web\Application($config));
  99. +       $user = app\models\MyBBUser::findByUsername($mybb->get_input('username'));
  100. +       $app->user->login($user);
  101. +
  102.         $plugins->run_hooks("member_do_login_end");
  103.  
  104.         $mybb->input['url'] = $mybb->get_input('url');
  105. diff --git a/models/MyBBUser.php b/models/MyBBUser.php
  106. new file mode 100644
  107. index 0000000..083e6df
  108. --- /dev/null
  109. +++ b/models/MyBBUser.php
  110. @@ -0,0 +1,276 @@
  111. +<?php
  112. +
  113. +namespace app\models;
  114. +
  115. +use Yii;
  116. +
  117. +/**
  118. + * This is the model class for table "mybb_users".
  119. + *
  120. + * @property int $uid
  121. + * @property string $username
  122. + * @property string $password
  123. + * @property string $salt
  124. + * @property string $loginkey
  125. + * @property string $email
  126. + * @property int $postnum
  127. + * @property int $threadnum
  128. + * @property string $avatar
  129. + * @property string $avatardimensions
  130. + * @property string $avatartype
  131. + * @property int $usergroup
  132. + * @property string $additionalgroups
  133. + * @property int $displaygroup
  134. + * @property string $usertitle
  135. + * @property int $regdate
  136. + * @property int $lastactive
  137. + * @property int $lastvisit
  138. + * @property int $lastpost
  139. + * @property string $website
  140. + * @property string $icq
  141. + * @property string $yahoo
  142. + * @property string $skype
  143. + * @property string $google
  144. + * @property string $birthday
  145. + * @property string $birthdayprivacy
  146. + * @property string $signature
  147. + * @property bool $allownotices
  148. + * @property bool $hideemail
  149. + * @property bool $subscriptionmethod
  150. + * @property bool $invisible
  151. + * @property bool $receivepms
  152. + * @property bool $receivefrombuddy
  153. + * @property bool $pmnotice
  154. + * @property bool $pmnotify
  155. + * @property bool $buddyrequestspm
  156. + * @property bool $buddyrequestsauto
  157. + * @property string $threadmode
  158. + * @property bool $showimages
  159. + * @property bool $showvideos
  160. + * @property bool $showsigs
  161. + * @property bool $showavatars
  162. + * @property bool $showquickreply
  163. + * @property bool $showredirect
  164. + * @property int $ppp
  165. + * @property int $tpp
  166. + * @property int $daysprune
  167. + * @property string $dateformat
  168. + * @property string $timeformat
  169. + * @property string $timezone
  170. + * @property bool $dst
  171. + * @property bool $dstcorrection
  172. + * @property string $buddylist
  173. + * @property string $ignorelist
  174. + * @property int $style
  175. + * @property bool $away
  176. + * @property int $awaydate
  177. + * @property string $returndate
  178. + * @property string $awayreason
  179. + * @property string $pmfolders
  180. + * @property string $notepad
  181. + * @property int $referrer
  182. + * @property int $referrals
  183. + * @property int $reputation
  184. + * @property resource $regip
  185. + * @property resource $lastip
  186. + * @property string $language
  187. + * @property int $timeonline
  188. + * @property bool $showcodebuttons
  189. + * @property int $totalpms
  190. + * @property int $unreadpms
  191. + * @property int $warningpoints
  192. + * @property bool $moderateposts
  193. + * @property int $moderationtime
  194. + * @property bool $suspendposting
  195. + * @property int $suspensiontime
  196. + * @property bool $suspendsignature
  197. + * @property int $suspendsigtime
  198. + * @property bool $coppauser
  199. + * @property bool $classicpostbit
  200. + * @property int $loginattempts
  201. + * @property int $loginlockoutexpiry
  202. + * @property string $usernotes
  203. + * @property bool $sourceeditor
  204. + */
  205. +class MyBBUser extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface
  206. +{
  207. +    /**
  208. +     * {@inheritdoc}
  209. +     */
  210. +    public static function tableName()
  211. +    {
  212. +        return 'mybb_users';
  213. +    }
  214. +
  215. +    /**
  216. +     * @return \yii\db\Connection the database connection used by this AR class.
  217. +     */
  218. +    public static function getDb()
  219. +    {
  220. +        return Yii::$app->get('forumdb');
  221. +    }
  222. +
  223. +    /**
  224. +     * {@inheritdoc}
  225. +     */
  226. +    public function rules()
  227. +    {
  228. +        return [
  229. +            [['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'],
  230. +            [['signature', 'buddylist', 'ignorelist', 'pmfolders', 'notepad', 'usernotes'], 'required'],
  231. +            [['signature', 'buddylist', 'ignorelist', 'pmfolders', 'notepad', 'usernotes'], 'string'],
  232. +            [['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'],
  233. +            [['username', 'password'], 'string', 'max' => 120],
  234. +            [['salt', 'avatardimensions', 'avatartype', 'icq'], 'string', 'max' => 10],
  235. +            [['loginkey', 'yahoo', 'language'], 'string', 'max' => 50],
  236. +            [['email'], 'string', 'max' => 220],
  237. +            [['avatar', 'additionalgroups', 'website', 'awayreason'], 'string', 'max' => 200],
  238. +            [['usertitle'], 'string', 'max' => 250],
  239. +            [['skype', 'google'], 'string', 'max' => 75],
  240. +            [['birthday', 'returndate'], 'string', 'max' => 15],
  241. +            [['birthdayprivacy', 'dateformat', 'timeformat'], 'string', 'max' => 4],
  242. +            [['threadmode'], 'string', 'max' => 8],
  243. +            [['timezone'], 'string', 'max' => 5],
  244. +            [['regip', 'lastip'], 'string', 'max' => 16],
  245. +        ];
  246. +    }
  247. +
  248. +    /**
  249. +     * {@inheritdoc}
  250. +     */
  251. +    public function attributeLabels()
  252. +    {
  253. +        return [
  254. +            'uid' => 'Uid',
  255. +            'username' => 'Username',
  256. +            'password' => 'Password',
  257. +            'salt' => 'Salt',
  258. +            'loginkey' => 'Loginkey',
  259. +            'email' => 'Email',
  260. +            'postnum' => 'Postnum',
  261. +            'threadnum' => 'Threadnum',
  262. +            'avatar' => 'Avatar',
  263. +            'avatardimensions' => 'Avatardimensions',
  264. +            'avatartype' => 'Avatartype',
  265. +            'usergroup' => 'Usergroup',
  266. +            'additionalgroups' => 'Additionalgroups',
  267. +            'displaygroup' => 'Displaygroup',
  268. +            'usertitle' => 'Usertitle',
  269. +            'regdate' => 'Regdate',
  270. +            'lastactive' => 'Lastactive',
  271. +            'lastvisit' => 'Lastvisit',
  272. +            'lastpost' => 'Lastpost',
  273. +            'website' => 'Website',
  274. +            'icq' => 'Icq',
  275. +            'yahoo' => 'Yahoo',
  276. +            'skype' => 'Skype',
  277. +            'google' => 'Google',
  278. +            'birthday' => 'Birthday',
  279. +            'birthdayprivacy' => 'Birthdayprivacy',
  280. +            'signature' => 'Signature',
  281. +            'allownotices' => 'Allownotices',
  282. +            'hideemail' => 'Hideemail',
  283. +            'subscriptionmethod' => 'Subscriptionmethod',
  284. +            'invisible' => 'Invisible',
  285. +            'receivepms' => 'Receivepms',
  286. +            'receivefrombuddy' => 'Receivefrombuddy',
  287. +            'pmnotice' => 'Pmnotice',
  288. +            'pmnotify' => 'Pmnotify',
  289. +            'buddyrequestspm' => 'Buddyrequestspm',
  290. +            'buddyrequestsauto' => 'Buddyrequestsauto',
  291. +            'threadmode' => 'Threadmode',
  292. +            'showimages' => 'Showimages',
  293. +            'showvideos' => 'Showvideos',
  294. +            'showsigs' => 'Showsigs',
  295. +            'showavatars' => 'Showavatars',
  296. +            'showquickreply' => 'Showquickreply',
  297. +            'showredirect' => 'Showredirect',
  298. +            'ppp' => 'Ppp',
  299. +            'tpp' => 'Tpp',
  300. +            'daysprune' => 'Daysprune',
  301. +            'dateformat' => 'Dateformat',
  302. +            'timeformat' => 'Timeformat',
  303. +            'timezone' => 'Timezone',
  304. +            'dst' => 'Dst',
  305. +            'dstcorrection' => 'Dstcorrection',
  306. +            'buddylist' => 'Buddylist',
  307. +            'ignorelist' => 'Ignorelist',
  308. +            'style' => 'Style',
  309. +            'away' => 'Away',
  310. +            'awaydate' => 'Awaydate',
  311. +            'returndate' => 'Returndate',
  312. +            'awayreason' => 'Awayreason',
  313. +            'pmfolders' => 'Pmfolders',
  314. +            'notepad' => 'Notepad',
  315. +            'referrer' => 'Referrer',
  316. +            'referrals' => 'Referrals',
  317. +            'reputation' => 'Reputation',
  318. +            'regip' => 'Regip',
  319. +            'lastip' => 'Lastip',
  320. +            'language' => 'Language',
  321. +            'timeonline' => 'Timeonline',
  322. +            'showcodebuttons' => 'Showcodebuttons',
  323. +            'totalpms' => 'Totalpms',
  324. +            'unreadpms' => 'Unreadpms',
  325. +            'warningpoints' => 'Warningpoints',
  326. +            'moderateposts' => 'Moderateposts',
  327. +            'moderationtime' => 'Moderationtime',
  328. +            'suspendposting' => 'Suspendposting',
  329. +            'suspensiontime' => 'Suspensiontime',
  330. +            'suspendsignature' => 'Suspendsignature',
  331. +            'suspendsigtime' => 'Suspendsigtime',
  332. +            'coppauser' => 'Coppauser',
  333. +            'classicpostbit' => 'Classicpostbit',
  334. +            'loginattempts' => 'Loginattempts',
  335. +            'loginlockoutexpiry' => 'Loginlockoutexpiry',
  336. +            'usernotes' => 'Usernotes',
  337. +            'sourceeditor' => 'Sourceeditor',
  338. +        ];
  339. +    }
  340. +
  341. +    /**
  342. +     * {@inheritdoc}
  343. +     */
  344. +    public static function findIdentity($id)
  345. +    {
  346. +        return static::findOne($id);
  347. +    }
  348. +
  349. +    /**
  350. +     * {@inheritdoc}
  351. +     */
  352. +    public static function findIdentityByAccessToken($token, $type = null)
  353. +    {
  354. +        return static::find()->where(['loginkey' => $token]);
  355. +    }
  356. +
  357. +    /**
  358. +     * {@inheritdoc}
  359. +     */
  360. +    public function getId()
  361. +    {
  362. +        return $this->getPrimaryKey();
  363. +    }
  364. +
  365. +    /**
  366. +     * {@inheritdoc}
  367. +     */
  368. +    public function getAuthKey()
  369. +    {
  370. +        $secret = Yii::$app->request->cookieValidationKey;
  371. +        return sha1($secret . $this->getId());
  372. +    }
  373. +
  374. +    /**
  375. +     * {@inheritdoc}
  376. +     */
  377. +    public function validateAuthKey($authKey)
  378. +    {
  379. +        return $this->getAuthKey() === $authKey;
  380. +    }
  381. +
  382. +    public static function findByUsername($username)
  383. +    {
  384. +        return static::find()->where(['username' => $username])->one();
  385. +    }
  386. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement