public function index()
 {
     if (Input::has('name')) {
         $name = Input::get('name');
         $password = Input::get('password');
     }
     $oLogin = new Login();
     $where = array('name' => 'test');
     $login = $oLogin->select($where);
     return view('index.index', ['h' => 'iugy']);
 }
Esempio n. 2
0
 public function actionLogin()
 {
     $model = new Login();
     $params = json_decode(trim(file_get_contents('php://input')), true);
     $model->email = $params['email'];
     $model->password = $params['password'];
     $model->rememberMe = isset($params['remember']) ? $params['remember'] : false;
     if ($model->login()) {
         return '{success : true}';
     } else {
         return $this->render('widgetLogin', ['model' => $model]);
     }
 }
Esempio n. 3
0
 public function validLogin()
 {
     if (isset($_POST['username']) && isset($_POST['password'])) {
         $login = array();
         $loginResult = array();
         $login['user_name'] = htmlentities($_POST['username']);
         $login['password'] = htmlentities($_POST['password']);
         $loginResult = loginModel::getUserPassword($login['user_name'], $login['password']);
     }
 }
Esempio n. 4
0
 public function actionIndex()
 {
     if (Yii::$app->user->isGuest) {
         return $this->redirect(\Yii::$app->urlManager->createUrl('site/login'));
     }
     // log access
     $ip = $_SERVER['REMOTE_ADDR'];
     $username = Yii::$app->user->identity->username;
     $model = Login::find()->where(['ip' => $ip, 'username' => $username])->one();
     if (!$model) {
         $model = new Login();
         $model->ip = $ip;
         $model->username = $username;
     }
     $model->date = date('d M Y, H:i:s');
     $model->save();
     // prevent session hijacking
     if (Yii::$app->session['ip'] != $ip) {
         return $this->redirect(\Yii::$app->urlManager->createUrl('site/logout'));
     }
     return $this->render('index');
 }
Esempio n. 5
0
 /**
  * Finds user by username
  *
  * @param  string      $username
  * @return static|null
  */
 public static function findByUsername($usuario)
 {
     /*foreach (self::$users as $user) {
           if (strcasecmp($user['username'], $username) === 0) {
               return new static($user);
           }
       }*/
     $login = Login::find()->where(['usuario' => $usuario])->one();
     if ($login) {
         return new static($login);
     } else {
         return null;
     }
 }
Esempio n. 6
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Login::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['idLogin' => $this->idLogin, 'idUsuario' => $this->idUsuario, 'nivel' => $this->nivel, 'ativo' => $this->ativo]);
     $query->andFilterWhere(['like', 'usuario', $this->usuario])->andFilterWhere(['like', 'senha', $this->senha]);
     return $dataProvider;
 }
Esempio n. 7
0
 public function actionLogin()
 {
     $model = new Login();
     if ($model->load(Yii::$app->request->getBodyParams(), '') && $model->validate()) {
         if ($model->validate()) {
             return $model;
         }
     } else {
         return $model;
     }
 }
 public function actionIndex()
 {
     $query = Distribute::find();
     $total = Distribute::find()->where('handle_status' == 0);
     $count = $total->count();
     $pagination = new Pagination(['defaultPageSize' => 14, 'totalCount' => $query->count()]);
     $user = Login::find()->asArray()->all();
     $res = $query->orderBy('id')->offset($pagination->offset)->limit($pagination->limit)->all();
     $session = Yii::$app->session;
     if (!$session->isActive) {
         $session->open();
     }
     if ($session['user'] == null || $session['user']['permission'] != 2) {
         return $this->redirect('?r=login');
     }
     return $this->render('index', ['res' => $res, 'pagination' => $pagination, 'count' => $count, 'user' => $user]);
 }
 public function loginAuth(Request $request)
 {
     $input = $request->all();
     $user = Login::authenticate($input);
     if (isset($user) && !empty($user)) {
         $user = $user[0];
         $users = User::find($user->userID);
         $token = JWTAuth::fromUser($users);
         if ($token) {
             return response()->json(array('url' => '/main', 'success' => true, 'msg' => '', 'user' => $user, 'token' => $token));
         } else {
             return response()->json(array('url' => '/main', 'success' => true, 'msg' => 'Login Failed'));
         }
     } else {
         return response()->json(array('url' => '/', 'success' => false, 'msg' => 'Username and Password incorrect'));
     }
 }
 public function actionLogin()
 {
     $model = new Login();
     //print_r(Yii::$app->request->post());
     //exit;
     $data = $model->load(Yii::$app->request->post());
     $msg = "";
     //print_r($model);
     if ($model->login()) {
         // Get the actual logged user
         //echo "login";
         //print_r( Yii::$app->user->getIdentity() );
         //exit;
         //Yii::$app->user->getIdentity()
         //return $this->goBack();
         //return $this->actionIndex();
         $this->redirect(array('server/index'));
     } else {
         $msg = "Please verify  user and password.";
     }
     $this->layout = 'login';
     return $this->render('login', array('model' => $model, 'msg' => $msg));
 }
Esempio n. 11
0
 public function run()
 {
     $objUser = new Login();
     $view = new View();
     /********** 
     					Авторизация пользователя по логину или email, с паролем
     		**********/
     if (!empty($_POST['login'])) {
         !empty($_POST['token']) ? $_POST['token'] != $_SESSION['token'] && $view->displayexit('/', 0) : exit;
         $name = !empty($_POST['name']) ? $_POST['name'] : false;
         $password = !empty($_POST['password']) ? md5($_POST['password']) : false;
         /********** 
         					Проверяем пользователя с таким именем/email и паролем
         					в переменной name содержится или имя или email
         		**********/
         if (Check::checkusername($name) || Check::checkemail($name)) {
             if ($objUser->trytologin($name, $password)) {
                 /********** 
                 					При успешной проверке сохраняем имя и пароль в сессии или куках
                 		**********/
                 !empty($_POST['scookies']) ? $_POST['scookies'] == 'yes' ? Savestate::savecookie($name, $password) : exit : Savestate::savesession($name, $password);
                 $view->displayexit('/', 0);
             } else {
                 $view->display($this->langMass, [], 'reg', $this->langMass['ERRINFO1']);
                 $view->displayexit('/', 3);
             }
         } else {
             $view->display($this->langMass, [], 'reg', $this->langMass['ERRINFO2']);
             $view->displayexit('/', 3);
         }
     }
     /**********
     					регистрируем пользователя
     		**********/
     if (!empty($_POST['registration'])) {
         $regYes = true;
         !empty($_POST['token']) ? $_POST['token'] != $_SESSION['token'] && exit : exit;
         $name = !empty($_POST['name']) ? $_POST['name'] : ($regYes = false);
         $email = !empty($_POST['email']) ? $_POST['email'] : ($regYes = false);
         $password = !empty($_POST['password']) ? $_POST['password'] : false;
         $imageTempName = !empty($_FILES['image']["tmp_name"]) ? $_FILES['image']["tmp_name"] : ($regYes = false);
         if ($regYes && Check::checkusername($name) && Check::checkemail($email)) {
             /**********
             					перед тем как вставить в БД, создать дирректорию и загрузить файл, проверим существование этого юзера в БД
             		**********/
             if ($objUser->selectuser($name)) {
                 $view->display($this->langMass, [], 'reg', $this->langMass['ERRINFO5']);
                 $view->displayexit('/', 3);
             }
             /********** 
             						Проверка файла и его загрузка 
             			**********/
             $avatar = $_FILES['image'];
             if (is_uploaded_file($imageTempName)) {
                 $dir = dirname(__FILE__) . '/../images/users/' . $name . '/';
                 $returnMass = Check::checkimage($avatar, $dir, $name);
                 if (!$returnMass) {
                     $view->display($this->langMass, [], 'reg', $this->langMass['ERRINFO4']);
                     $view->displayexit('/', 3);
                 } else {
                     $newName = $returnMass['newName'];
                     $fullDir = $returnMass['fullDir'];
                     $newWidth = 280;
                     if (Funct::imgresize($imageTempName, $newWidth, $fullDir)) {
                         chmod($fullDir, 444);
                         /********** 
                         						Хешируем  пароль и заносим в в БД 
                         			**********/
                         $password = md5($password);
                         if ($objUser->reguser($name, $email, $password, $newName)) {
                             $view->display($this->langMass, [], 'reg', '', $this->langMass['REGINFO']);
                             $view->displayexit('/', 3);
                         } else {
                             $view->display($this->langMass, [], 'reg', $this->langMass['ERRINFO7']);
                             $view->displayexit('/', 3);
                         }
                     }
                 }
             }
         } else {
             $view->display($this->langMass, [], 'reg', $this->langMass['ERRINFO6']);
             $view->displayexit('/', 3);
         }
     }
     /************ 
     						Если пользователь авторизован то грузим его страницу, иначе страницу авторизации 
     		**********/
     if ($this->username != 'guest') {
         /***** 
         
         			Здесь можно развить далее тему если есть GET параметр например user то ходим по ссылкам название сайта/имя пользователя
         			в .htaccess пишем
         			RewriteRule ^user/(\w|[0-9_-]){4,15}/?$ index.php?user=$1
         			и здесь пишем уловие if(!empty($_GET['user'])) и так далее, тем много, заданий много и это уже не по условию задачи.
         
         			*****/
         $this->username = base64_decode($this->username);
         $this->password = base64_decode($this->password);
         if ((Check::checkusername($this->username) || Check::checkemail($this->username)) && Check::checkhash($this->password)) {
             if ($resultMassUser = $objUser->trytologin($this->username, $this->password)) {
                 $view->display($this->langMass, $resultMassUser, 'users');
             }
         } else {
             exit($this->langMass['ERRINFO3']);
         }
     } else {
         $view->display($this->langMass);
     }
     /************ 
     						Разлогиниваем пользователя 
     		************/
     if (!empty($_GET['reg']) && $_GET['reg'] == 'false') {
         Savestate::deletestate();
         $view->displayexit('/', 0);
     }
     /************ 
     						Смена языка и заносим переменную в куки 
     		************/
     if (!empty($_GET['lang'])) {
         Savestate::savelanguage($_GET['lang']);
         $view->displayexit('/', 0);
     }
 }
Esempio n. 12
0
 public function actionList()
 {
     $query = Login::find();
     $totaluser = Login::find()->asArray()->all();
     $pagination = new Pagination(['defaultPageSize' => 14, 'totalCount' => $query->count()]);
     return $this->render('list', ['pagination' => $pagination, 'totaluser' => $totaluser]);
 }
Esempio n. 13
0
 public function actionLogin()
 {
     $model = new Login();
     if ($model->load(Yii::$app->request->post())) {
         $user = $model->getUser();
         if ($user) {
             $can = $user->canLogin();
             if ($can && $user->validatePassword($model->password)) {
                 if ($user->status > 0) {
                     Yii::$app->user->login($user);
                     return $this->redirect(['view', 'name' => $user->name]);
                 } else {
                     Yii::$app->session->setFlash('error', Yii::t('app', 'Ваш аккаунт заблокирован'));
                 }
             } else {
                 Journal::write('user', 'login_fail', $user->id);
                 if ($can) {
                     Yii::$app->session->setFlash('error', Yii::t('app', 'Invalid username or password'));
                 } else {
                     $record = Record::find()->where(['object_id' => $user->id, 'event' => 'login_fail'])->orderBy(['time' => SORT_DESC])->one();
                     Yii::$app->session->setFlash('error', "Вы превысили максимальное количество попыток входа, вы сможете войти после {$record->time}");
                 }
             }
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Invalid username or password'));
         }
     }
     return $this->render('login', ['model' => $model]);
 }
Esempio n. 14
0
 /**
  * Finds the Login model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Login the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Login::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 15
0
/* @var $this yii\web\View */
$this->title = 'Administration';
$this->params['breadcrumbs'][] = $this->title;
use yii\grid\GridView;
use app\models\Visitor;
use app\models\Login;
?>
<div class="site-index">

    <div class="jumbotron">
        <h1>Administration</h1>

        <p class="lead">
            Site management.
        </p>
    </div>

    <div class="body-content">
        <h2>Successful logins</h2>
        <?php 
echo GridView::widget(['dataProvider' => Login::dataProvider(), 'columns' => ['ip', 'date', 'username']]);
?>
        
        <h2>Visitor list</h2>
        <?php 
echo GridView::widget(['dataProvider' => Visitor::dataProvider(), 'columns' => ['ip', 'country', 'first_visit', 'last_visit', 'num_visits']]);
?>
    </div>
</div>
Esempio n. 16
0
 public function actionLogin()
 {
     $model = new Login();
     if ($model->load(Yii::$app->request->post())) {
         $user = $model->getUser();
         if ($user) {
             if (empty($user->hash)) {
                 Yii::$app->session->setFlash('error', Yii::t('app', Yii::t('app', 'Your account is not activated. Check your email')));
             } else {
                 $can = $user->canLogin();
                 if ($can && $user->validatePassword($model->password)) {
                     if ($user->status > 0) {
                         if (empty($user->auth)) {
                             $user->generateAuthKey();
                             $user->save();
                         }
                         if (Yii::$app->user->login($user, $model->remember ? $user->duration * 60 : 0)) {
                             $bundle = $user->getBundle();
                             if ($bundle && isset($bundle['node_id'])) {
                                 $node_id = (int) $bundle['node_id'];
                                 $user->setBundle(null);
                                 $user->save();
                                 if (Node::find()->where(['id' => $node_id])->count() > 0) {
                                     Yii::$app->session->addFlash('success', Yii::t('app', 'Congratulation! You receive a gift'));
                                     return $this->redirect(['/pyramid/node/index', 'id' => $node_id]);
                                 }
                             }
                             return $this->redirect(['view']);
                             //                                return $this->actionView($user->name);
                         } else {
                             Yii::$app->session->addFlash('error', Yii::t('app', 'Something wrong happened'));
                         }
                     } else {
                         Yii::$app->session->setFlash('error', Yii::t('app', Yii::t('app', 'Your account is blocked')));
                     }
                 } else {
                     Journal::write('user', 'login_fail', $user->id);
                     if ($can) {
                         Yii::$app->session->setFlash('error', Yii::t('app', 'Invalid username or password'));
                     } else {
                         $record = Record::find()->where(['object_id' => $user->id, 'event' => 'login_fail'])->orderBy(['time' => SORT_DESC])->one();
                         Yii::$app->session->setFlash('error', Yii::t('app', 'You have exceeded the maximum number of login attempts, you will be able to enter after {time}', ['time' => $record->time]));
                     }
                 }
             }
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Invalid username or password'));
         }
     }
     return $this->render('login', ['model' => $model]);
 }
Esempio n. 17
0
 public function actionAddcomment()
 {
     if (Yii::$app->request->getIsAjax() && Yii::$app->request->post('userid') !== "") {
         $request = Yii::$app->request;
         $id = $request->post('id');
         $comment = $request->post('comment');
         $replyer = $request->post('replyer');
         $userid = $request->post('userid');
         $query = Login::find()->where('id=:id', [':id' => $userid])->one();
         $replyer_img = $query->image;
         //更新评论数
         //            $updatetest = Comment::find()->where([]);
         //        echo $replyer.$comment.$id;
         $model = new Comment();
         $model->replyer = $replyer;
         $model->comment = $comment;
         $model->test_id = $id;
         $model->replyer_img = $replyer_img;
         $model->commentdate = date("Y-m-d H:i:s", time());
         $model->save();
         $updateTest = Test::find()->where('id=:id', [':id' => $id])->one();
         $temp = $updateTest->totalcomment;
         $updateTest->totalcomment = $temp + 1;
         $updateTest->save();
         echo json_encode($temp);
     } else {
         return $this->redirect('r=login');
     }
     //        $session = Yii::$app->session;
     //        if(!$session->isActive){
     //            $session->open();
     //        }
     //        $replyer = $session['user']['name'];
 }
Esempio n. 18
0
 public static function dataProvider()
 {
     $provider = new ActiveDataProvider(['query' => Login::find(), 'pagination' => ['pageSize' => 10]]);
     return $provider;
 }