示例#1
0
 public function actionAdd($password, $discuz_uid, $type = 'User')
 {
     //TODO 这个之后一定要写进配置文件而非硬编码
     if ($password !== 'ngpt_2333') {
         Yii::warning("Wrong Password!!!!!!" . $password . "uid : {$discuz_uid}");
         return ['result' => 'failed', 'extra' => 'wrong password'];
     }
     if (is_numeric($discuz_uid) && intval($discuz_uid) <= 0) {
         Yii::warning("uid not a number : {$discuz_uid}");
         return ['result' => 'failed', 'extra' => 'discuz_uid should be numeric'];
     }
     $discuz_uid = intval($discuz_uid);
     /** @var User $user */
     $user = User::findOne(['discuz_user_id' => $discuz_uid]);
     if (!empty($user)) {
         return ['result' => 'succeed', 'extra' => $user->passkey];
     }
     $user = new User();
     $user->discuz_user_id = $discuz_uid;
     $user->passkey = User::genPasskey();
     Yii::info($user->attributes);
     if ($user->insert()) {
         return ['result' => 'succeed', 'extra' => $user->passkey];
     } else {
         Yii::warning("Insert to user table failed");
         return ['result' => 'failed', 'extra' => 'Database error'];
     }
 }