Ejemplo n.º 1
0
 public function validatePassword($username, $password)
 {
     $model = Admin::findOne(['username' => $username]);
     if ($model == null) {
         $model = Admin::findOne(['email' => $username]);
     }
     if (md5($password) == $model->password) {
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
 public static function checkAdminLogedIn()
 {
     $ip = $_SERVER['REMOTE_ADDR'];
     $browser = $_SERVER['HTTP_USER_AGENT'];
     $sessionId = md5($ip . $browser);
     $model = Admin::findOne(['ssesid' => $sessionId]);
     if ($model === null) {
         return false;
     }
     if (strtotime($model->created_dt) < time() - 60 * 60 * 24 * 7) {
         return false;
     }
     return true;
 }
Ejemplo n.º 3
0
 public function actionLogin()
 {
     $this->layout = 'login';
     if (\Yii::$app->request->isPost) {
         $account = $_POST['admin_account'];
         $password = $_POST['password'];
         $admin = Admin::findOne(['admin_account' => $account]);
         if ($admin == null) {
             return $this->render('login', ['error' => '账户不存在']);
         }
         if ($admin->admin_password != md5($password)) {
             return $this->render('login', ['error' => '密码错误']);
         }
         $logService = new LogService();
         $msg = $logService->adminLogin($admin->admin_id);
         if ($msg == 'success') {
             $_SESSION['admin'] = $admin;
             return $this->redirect(Url::base() . '/index.php?r=admin/index');
         }
         return $this->render('login', ['error' => '登录失败']);
     }
     return $this->render('login');
 }
Ejemplo n.º 4
0
 /**
  * Finds the Admin model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Admin the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Admin::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 5
0
 /**
  * Finds the Admin model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Admin the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Admin::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException();
     }
 }
Ejemplo n.º 6
0
 public function disabledFiles($page)
 {
     $conn = Yii::$app->db;
     $sql = 'select count(*) as counts from file_manage_log';
     $command = $conn->createCommand($sql);
     $result = $command->queryOne();
     $pages = floor($result['counts'] / 20) + 1;
     $sql = 'select * from file_manage_log order by create_date desc limit ' . $page * (20 - 1) . ',20';
     $command = $conn->createCommand($sql);
     $files = $command->queryAll();
     for ($i = 0; $i < count($files); $i++) {
         $file = UserFile::findOne($files[$i]['file_id']);
         $files[$i]['file_type'] = $file->filetype;
         $files[$i]['file_size'] = round($file->filesize / (1024 * 1024), 2);
         $admin = Admin::findOne(['admin_id' => $files[$i]['admin_id']]);
         $files[$i]['admin'] = $admin->admin_account;
     }
     $conn->close();
     $data['pages'] = $pages;
     $data['page'] = $page;
     $data['files'] = $files;
     return $data;
 }