Exemplo n.º 1
0
 /**
  * Verify if the user is sign-in or not
  * @return void
  */
 public function login_check()
 {
     $islogin = User::login();
     if ($islogin === true) {
         $this->redirectTo('posts/index');
     } else {
         return $this->redirectTo('users/login');
     }
 }
Exemplo n.º 2
0
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new User();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->goBack();
     }
     return $this->render('login', ['model' => $model]);
 }
Exemplo n.º 3
0
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new User();
     if ($model->login()) {
         return $this->goBack();
     } else {
         echo "strannaya oshibka";
     }
 }
Exemplo n.º 4
0
 /**
  *
  * Please careful if you want to delete or modify methods below.
  *
  */
 public function actionLogin()
 {
     $model = new User();
     $model->scenario('login');
     if (App::$app->request->post()) {
         if ($model->login(App::$app->request->post())) {
             return $this->redirect('admin');
         } else {
             $this->alert = ['danger' => 'Username/Email or Password wrong.'];
         }
     }
     return $this->render('login', ['model' => $model]);
 }
Exemplo n.º 5
0
 public function actionLogin($IVAOTOKEN = null)
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     if (!$IVAOTOKEN) {
         return $this->redirect(Yii::$app->params['api_url']);
     }
     //have the token
     $model = new User();
     $model->login($IVAOTOKEN);
     $this->redirect(Yii::$app->user->returnUrl);
 }
Exemplo n.º 6
0
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new User();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return 'aaaaa';
         return $this->redirect(Url::to(['posts/index']));
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
Exemplo n.º 7
0
 public function actionIndex()
 {
     Yii::$app->controller->layout = false;
     if (!\Yii::$app->user->isGuest) {
         $this->redirect(Url::toRoute('admin/index'));
         //已登录直接跳转
     }
     $model = new User(['scenario' => 'login']);
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->redirect(Url::toRoute('admin/index'));
     } else {
         return $this->render('index', ['model' => $model]);
     }
 }
Exemplo n.º 8
0
 public function login()
 {
     $data = Input::json()->all();
     $rules = ['username' => 'required|max:32|min:4|string', 'passwd' => 'required|max:32|min:4|string'];
     $validator = Validator::make($data, $rules);
     if ($validator->fails()) {
         return Response::json($validator->messages(), 422);
     }
     $user = User::login($data['username'], md5($data['passwd']));
     if (!empty($user)) {
         return $this->set_cookie_by_user($user);
     } else {
         return Response::json('', 403);
     }
 }
Exemplo n.º 9
0
 /**
  * log the user in B.O
  *
  * @return null|string|\yii\web\Response
  * @throws Exception
  * @throws \Exception
  */
 public function actionLogin()
 {
     try {
         Yii::trace('Trace : ' . __METHOD__, __METHOD__);
         $response = null;
         $model = new User(['scenario' => 'login']);
         if ($model->load(Yii::$app->request->post()) && $model->login()) {
             $response = $this->redirect(['/admin/index']);
         }
         if ($response === null) {
             $response = $this->render('login', ['model' => $model]);
         }
         return $response;
     } catch (Exception $e) {
         Yii::error($e->getMessage(), __METHOD__);
         throw $e;
     }
 }
Exemplo n.º 10
0
 public function loginAction()
 {
     $request = new LoginRequest(PostRequest::post(), true);
     return User::login($request);
 }
Exemplo n.º 11
0
<?php

//namespace app\core;
use app\models\Cookie;
use app\models\Config;
use app\models\Session;
use app\models\User;
use app\classes\DB;
session_start();
$GLOBALS['config'] = ['mysql' => ['host' => '127.0.0.1', 'username' => 'root', 'password' => 'root', 'db' => 'test'], 'remember' => ['cookie_name' => 'hash', 'cookie_expiry' => 604800], 'session' => ['session_name' => 'root', 'token_name' => 'token']];
spl_autoload_register(function ($class) {
    require_once 'classes/' . $class . '.php';
});
require_once "functions/sanitize.php";
if (Cookie::exists(Config::get('remember/cookie_name')) && !Session::exists(Config::get('session/session_name'))) {
    $hash = Cookie::get(Config::get('remember/cookie_name'));
    $hashCheck = DB::connect()->get('users_session', ['hash', '=', $hash]);
    if ($hashCheck->count()) {
        $user = new User($hashCheck->first()->user_id);
        $user->login();
    }
}