chengwl 5 gadi atpakaļ
vecāks
revīzija
ff2ce27b23
3 mainītis faili ar 47 papildinājumiem un 18 dzēšanām
  1. 39 1
      controllers/SiteController.php
  2. 7 13
      models/User.php
  3. 1 4
      views/site/login.php

+ 39 - 1
controllers/SiteController.php

@@ -12,7 +12,7 @@ use yii\web\Controller;
 use yii\web\NotFoundHttpException;
 use yii\filters\VerbFilter;
 use PhpOffice\PhpSpreadsheet\IOFactory;
-
+use app\models\LoginForm;
 /**
  * SiteController implements the CRUD actions for Orderreturn model.
  */
@@ -46,6 +46,9 @@ class SiteController extends Controller
      */
     public function actionIndex()
     {
+        if (Yii::$app->user->isGuest) {
+            return $this->redirect(['login']);
+        }
         $request = Yii::$app->request;
         $shop=$request->get('shop',1);
         $searchModel = new OrderreturnSearch();
@@ -205,6 +208,41 @@ class SiteController extends Controller
         return $this->render('upload', ['model' => $model]);
     }
 
+
+
+    /**
+     * Login action.
+     *
+     * @return Response|string
+     */
+    public function actionLogin()
+    {
+        if (!Yii::$app->user->isGuest) {
+            return $this->goHome();
+        }
+
+        $model = new LoginForm();
+        if ($model->load(Yii::$app->request->post()) && $model->login()) {
+            return $this->goBack();
+        }
+
+        $model->password = '';
+        return $this->render('login', [
+            'model' => $model,
+        ]);
+    }
+      /**
+     * Logout action.
+     *
+     * @return Response
+     */
+    public function actionLogout()
+    {
+        Yii::$app->user->logout();
+
+        return $this->goHome();
+    }
+
     /**
      * Finds the Orderreturn model based on its primary key value.
      * If the model is not found, a 404 HTTP exception will be thrown.

+ 7 - 13
models/User.php

@@ -11,20 +11,14 @@ class User extends \yii\base\BaseObject implements \yii\web\IdentityInterface
     public $accessToken;
 
     private static $users = [
-        '100' => [
-            'id' => '100',
-            'username' => 'admin',
-            'password' => 'admin',
-            'authKey' => 'test100key',
-            'accessToken' => '100-token',
-        ],
-        '101' => [
-            'id' => '101',
-            'username' => 'demo',
-            'password' => 'demo',
-            'authKey' => 'test101key',
-            'accessToken' => '101-token',
+        '102' => [
+            'id' => '102',
+            'username' => 'longyi',
+            'password' => 'longyi123',
+            'authKey' => 'test102key',
+            'accessToken' => '102-token',
         ],
+       
     ];
 
 

+ 1 - 4
views/site/login.php

@@ -40,8 +40,5 @@ $this->params['breadcrumbs'][] = $this->title;
 
     <?php ActiveForm::end(); ?>
 
-    <div class="col-lg-offset-1" style="color:#999;">
-        You may login with <strong>admin/admin</strong> or <strong>demo/demo</strong>.<br>
-        To modify the username/password, please check out the code <code>app\models\User::$users</code>.
-    </div>
+  
 </div>