public function actionFollowing() { $query = Topic::find()->innerJoinWith('authorFollowedBy')->where([Favorite::tableName() . '.source_id' => Yii::$app->getUser()->id, Favorite::tableName() . '.type' => Favorite::TYPE_USER]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(1), 'pageSize' => $this->settings['list_pagesize'], 'pageParam' => 'p']); $topics = $query->select([Topic::tableName() . '.id'])->orderBy([Topic::tableName() . '.id' => SORT_DESC])->offset($pages->offset)->with(['topic.author', 'topic.node', 'topic.lastReply'])->limit($pages->limit)->all(); return $this->render('following', ['topics' => Util::convertModelToArray($topics), 'pages' => $pages]); }
private function createConfigFile($file, $settings) { $config = '<?php' . "\n"; $config = $config . 'return '; $config = $config . Util::convertArrayToString($settings, ''); $config = $config . ';' . "\n"; file_put_contents($file, $config); }
private function createConfigFile($file, $settings) { $config = '<?php' . "\n"; $config = $config . 'return '; $config = $config . \app\lib\Util::convertArrayToString($settings, ''); $config = $config . ';' . "\n"; $fp = fopen($file, "w"); fwrite($fp, $config); fclose($fp); }
private function createConfigFile($settings) { $settings = self::getCacheInfo($settings); $settings['footer_links'] = self::getFootLinks($settings['footer_links']); $config = '<?php' . "\n"; $config = $config . 'return [' . "\n"; $config = $config . ' \'settings\' => '; $config = $config . Util::convertArrayToString($settings, ' ') . "\n"; $config = $config . '];' . "\n"; file_put_contents(Yii::getAlias('@app/config/params.php'), $config); }
public function beforeAction($action) { $this->settings = Yii::$app->params['settings']; if ($this->isOffline($action)) { return Yii::$app->getResponse()->redirect(['site/offline']); } if ($this->needLogin($action)) { return Yii::$app->getResponse()->redirect(['site/login']); } Yii::$app->getUser()->setReturnUrl(Util::getReferrer()); return parent::beforeAction($action); }
public function actionReply($id) { $request = Yii::$app->getRequest(); $me = Yii::$app->getUser()->getIdentity(); $topic = $this->findTopicModel($id, ['node', 'author']); if (!$me->canReply($topic)) { throw new ForbiddenHttpException('您没有权限回复或此主题已关闭回复。'); } $model = new Comment(); if ($model->load($request->post()) && $model->validate()) { $model->user_id = $me->id; $cid = new \app\models\Commentid(['id' => null]); $cid->save(false); $model->id = $cid->id; $model->link('topic', $topic); $this->redirect(Topic::getRedirectUrl($id, $model->position)); } return $this->render('add', ['comment' => $model, 'topic' => Util::convertModelToArray($topic)]); }
// 'dbname' => 'adapi', // 'user' => 'root', // 'password' => '1qazXSW@', // 'host' => '192.168.99.100', // 'driver' => 'pdo_mysql', // 'charset' => 'utf8' // ); $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode); $em = EntityManager::create($connectionParams, $config); $app = new \Slim\Slim(array("debug" => true, "templates.path" => "./admin/templates")); $check_auth = function ($em) { return function () use($em) { $app = \Slim\Slim::getInstance(); $token = $app->request->headers("Auth-Token"); $user = $em->getRepository('App\\Model\\User')->findOneBy(array('token' => $token)); if (!$user) { $app->response->headers->set('Content-Type', 'application/json'); echo Util::resPonseJson($app, 4003, "Authenation denied", array()); exit; } $app->flashNow('user_id', $user->getId()); }; }; //require routes files require_once './routes/user.php'; require_once './routes/auth.php'; require_once './routes/account.php'; //require admin routes files require_once './admin/routes/index.php'; require_once './admin/routes/ad.php'; $app->run();
public function actionView($id) { $topic = Topic::getTopicFromView($id); $pages = new Pagination(['totalCount' => $topic->comment_count, 'pageSize' => intval($this->settings['comment_pagesize']), 'pageParam' => 'p']); return $this->render('view', ['topic' => Util::convertModelToArray($topic), 'comments' => Comment::getCommentsFromView($id, $pages), 'pages' => $pages]); }
/** * Generates "remember me" authentication key */ public function generateAuthKey() { $this->auth_key = Util::generateRandomString(); }
$user = $em->getRepository('App\\Model\\User')->findOneBy(array('phone' => $phone)); if (!$user) { $app->response->headers->set('Content-Type', 'application/json'); echo Util::resPonseJson($app, 4004, "User not found", array()); exit; } if (password_verify($password, $user->getPassword_hash())) { $token = password_hash(strval(time()), PASSWORD_BCRYPT); $user->setToken($token); $em->flush($user); $app->response->headers->set('Content-Type', 'application/json'); echo Util::resPonseJson($app, 200, "Login success.", array('token' => $token)); exit; } else { $app->response->headers->set('Content-Type', 'application/json'); echo Util::resPonseJson($app, 4001, "Authenation failed.", array()); exit; } }); $app->get('/auth/logout', $check_auth($em), function () use($app, $em) { $user = $em->getRepository('App\\Model\\User')->find($_SESSION['user_id']); $user->setToken(''); $em->persist($user); $em->flush(); $app->response->headers->set('Content-Type', 'application/json'); echo Util::resPonseJson($app, 200, "Login success.", array('token' => $token)); exit; }); $app->get('/phpinfo', function () use($app) { echo phpinfo(); });
public function actionAvatar() { $session = Yii::$app->getSession(); $model = new UploadForm(); $suffix = 'png'; $me = Yii::$app->getUser()->getIdentity(); $model->file = UploadedFile::getInstance($model, 'file'); if ($model->file && $model->validate()) { $name = $me->id; $myId = strtolower(Util::shorturl($me->id)); $savePath = 'avatar/' . substr($myId, 0, 1) . '/' . substr($myId, 1, 1); $avatar = $savePath . '/' . $name . '_{size}.' . $suffix . '?m=' . time(); $this->resizeAvator($this->resizes, $model->file->tempName, $savePath, $name, $suffix); $me->avatar = $avatar; $me->save(false); $session->setFlash('setAvatarOK', '头像设定成功,显示可能有延迟,请刷新。'); } else { $session->setFlash('setAvatarNG', '头像设定失败'); } return $this->redirect(['user/setting', '#' => 'avatar']); }
public static function generateToken($length = 32) { return Util::generateRandomString($length); }
$em->persist($user_info); $em->flush($user_info); $app->response->headers->set('Content-Type', 'application/json'); echo Util::resPonseJson($app, 200, "", array()); exit; } catch (Exception $e) { $app->response->headers->set('Content-Type', 'application/json'); echo Util::resPonseJson($app, 500, "System error.", array()); exit; } exit; }); $app->get('/userinfo/:user_id', $check_auth($em), function ($user_id) use($app, $em) { $user = $em->getRepository('App\\Model\\User')->find($user_id); if (!$user) { $app->response->headers->set('Content-Type', 'application/json'); echo Util::resPonseJson($app, 4004, "User not exists.", array()); exit; } $userInfo = $em->getRepository('App\\Model\\UserInfo')->find($user_id); if (!$userInfo) { $userInfo = new UserInfo(); } $allInfo = array_merge($user->toArray(), $userInfo->toArray()); unset($allInfo['password_hash']); unset($allInfo['payment_password']); unset($allInfo['user_id']); $app->response->headers->set('Content-Type', 'application/json'); echo Util::resPonseJson($app, 200, "", array("user" => $allInfo)); exit; });
public function uploadAvatar($uid) { $suffix = 'png'; if ($this->file && $this->validate()) { $name = $uid; $myId = strtolower(Util::shorturl($uid)); $savePath = 'avatar/' . substr($myId, 0, 1) . '/' . substr($myId, 1, 1); // $this->resizeAvator( $this->_avatarSizes, $this->file->tempName, $savePath, $name, $suffix); Upload::uploadAvatar($this->file->tempName, $savePath, $name, $suffix); return $savePath . '/' . $name . '_{size}.' . $suffix . '?m=' . time(); } return false; }
} catch (Exception $e) { $app->response->headers->set('Content-Type', 'application/json'); echo Util::resPonseJson($app, 500, "System Error", array()); exit; } }); $app->post('/account/payment_password/check', $check_auth($em), function () use($app, $em) { $payment_password = $app->request->params('payment_password'); if ($payment_password == '' || $payment_password == null) { $app->response->headers->set('Content-Type', 'application/json'); echo Util::resPonseJson($app, 40000, "Invalid Param", array()); exit; } $flash = $app->flashData(); $user_id = isset($flash['user_id']) ? $flash['user_id'] : ''; $user = $em->getRepository('App\\Model\\User')->find($user_id); if (!$user) { $app->response->headers->set('Content-Type', 'application/json'); echo Util::resPonseJson($app, 40004, "User not exists.", array()); exit; } if (password_verify($payment_password, $user->getPayment_password())) { $app->response->headers->set('Content-Type', 'application/json'); echo Util::resPonseJson($app, 200, "OK", array()); exit; } else { $app->response->headers->set('Content-Type', 'application/json'); echo Util::resPonseJson($app, 200, "Password Not Match", array()); exit; } });