public function safeDown()
 {
     $controller = Yii::$app->controller;
     $model = \Yii::createObject(LoginForm::className());
     do {
         if ($model->hasErrors()) {
             $this->showErrors($model);
         }
         // get username
         $username = $controller->prompt($controller->ansiFormat("\tUsername: "******"\tPassword: "******"\n";
         $model->login = $username;
         $model->password = $password;
     } while (!$model->validate());
     $user = User::findOne(['username' => $username]);
     if (empty($user)) {
         throw new \yii\console\Exception("Unable to find user {$username}");
     }
     $this->delete('{{%auth_assignment}}', ['item_name' => 'admin', 'user_id' => $user->primaryKey]);
     $user->delete();
 }
 public function testLogin()
 {
     $this->form = \Yii::createObject(LoginForm::className());
     $this->specify('should not allow logging in blocked users', function () {
         $user = $this->getFixture('user')->getModel('blocked');
         $this->form->setAttributes(['login' => $user->email, 'password' => 'qwerty']);
         verify($this->form->validate())->false();
         verify($this->form->getErrors('login'))->contains('Your account has been blocked');
     });
     $this->specify('should not allow logging in unconfirmed users', function () {
         \Yii::$app->getModule('user')->enableConfirmation = true;
         \Yii::$app->getModule('user')->enableUnconfirmedLogin = false;
         $user = $this->getFixture('user')->getModel('user');
         $this->form->setAttributes(['login' => $user->email, 'password' => 'qwerty']);
         verify($this->form->validate())->true();
         $user = $this->getFixture('user')->getModel('unconfirmed');
         $this->form->setAttributes(['login' => $user->email, 'password' => 'unconfirmed']);
         verify($this->form->validate())->false();
     });
     $this->specify('should log the user in with correct credentials', function () {
         $user = $this->getFixture('user')->getModel('user');
         $this->form->setAttributes(['login' => $user->email, 'password' => 'wrong']);
         verify($this->form->validate())->false();
         $this->form->setAttributes(['login' => $user->email, 'password' => 'qwerty']);
         verify($this->form->validate())->true();
     });
 }
Beispiel #3
0
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         $this->goHome();
     }
     $model = \Yii::createObject(LoginForm::className());
     $this->performAjaxValidation($model);
     if ($model->load(Yii::$app->getRequest()->post()) && $model->login()) {
         $app = Yii::$app->id;
         //backend access only for users with some roles
         if ($app == 'backend') {
             if (!$this->hasBackendAccess($model->login)) {
                 $user = $this->getUser($model->login);
                 if (!empty($user)) {
                     $model->addError('app', 'This user is not authorized for administration');
                     $app = 'frontend';
                 } else {
                     Yii::$app->getUser()->logout();
                     return $this->goBack();
                 }
             }
         }
         $redirect = "@baseUrl" . ucfirst($app);
         return $this->redirect(Yii::getAlias($redirect));
     }
     return $this->render('login', ['model' => $model, 'module' => $this->module]);
 }
Beispiel #4
0
 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();
             } else {
                 return $this->render('login', [
                     'model' => $model,
                 ]);
             }*/
     if (!Yii::$app->user->isGuest) {
         $this->goHome();
     }
     /** @var LoginForm $model */
     $model = Yii::createObject(LoginForm::className());
     $this->performAjaxValidation($model);
     if ($model->load(Yii::$app->getRequest()->post()) && $model->login()) {
         return $this->goBack();
     }
     return $this->render('login', ['model' => $model, 'module' => $this->module]);
 }
 /**
  * Displays the login page.
  * @return string|\yii\web\Response
  */
 public function actionLogin()
 {
     $model = \Yii::createObject(LoginForm::className());
     $this->performAjaxValidation($model);
     if ($model->load(\Yii::$app->getRequest()->post()) && $model->login()) {
         return $this->goBack();
     }
     return $this->render('login', ['model' => $model, 'module' => $this->module]);
 }
Beispiel #6
0
 /** @inheritdoc */
 public function run()
 {
     $model = \Yii::createObject(LoginForm::className());
     $action = $this->validate ? null : ['/user/security/login'];
     if ($this->validate && $model->load(\Yii::$app->request->post()) && $model->login()) {
         return \Yii::$app->response->redirect(\Yii::$app->user->returnUrl);
     }
     return $this->render('login', ['model' => $model, 'action' => $action]);
 }
Beispiel #7
0
 /**
  * Tests login method.
  */
 public function testLogin()
 {
     $user = \Yii::createObject(User::className());
     test::double(Finder::className(), ['findUserByUsernameOrEmail' => $user]);
     $form = Yii::createObject(LoginForm::className());
     $form->beforeValidate();
     test::double($form, ['validate' => false]);
     verify($form->login())->false();
     test::double($form, ['validate' => true]);
     test::double(\yii\web\User::className(), ['login' => false]);
     verify($form->login())->false();
     test::double(\yii\web\User::className(), ['login' => true]);
     verify($form->login())->true();
 }
Beispiel #8
0
 public function actionLoginAjax()
 {
     if (!\Yii::$app->user->isGuest) {
         $this->goHome();
     }
     $model = \Yii::createObject(LoginForm::className());
     //$model = new LoginForm();
     //$this->performAjaxValidation($model);
     if ($model->load(Yii::$app->getRequest()->post()) && $model->login()) {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         return $this->redirect(Yii::$app->user->getReturnUrl());
     }
     return $this->renderAjax('login', ['model' => $model]);
 }
 /**
  * Displays the login page.
  *
  * @return string|Response
  */
 public function actionLogin()
 {
     if (!Yii::$app->user->isGuest) {
         $this->goHome();
     }
     /** @var LoginForm $model */
     $model = Yii::createObject(LoginForm::className());
     $this->performAjaxValidation($model);
     if ($model->load(Yii::$app->getRequest()->post()) && $model->login()) {
         return $this->goHome();
     }
     $this->layout = '@app/views/layouts/login';
     return $this->render('login', ['model' => $model, 'module' => $this->module]);
 }
Beispiel #10
0
 /**
  * Displays the login page.
  * @return string|Response
  */
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         $this->goHome();
     }
     $model = \Yii::createObject(LoginForm::className());
     $this->performAjaxValidation($model);
     if ($model->load(Yii::$app->getRequest()->post()) && $model->login() && (Yii::$app->user->identity->getId() == 1 || Yii::$app->user->identity->getId() == 4)) {
         return $this->redirect(\Yii::$app->urlManager->createUrl("admin/index"));
     } elseif ($model->load(Yii::$app->getRequest()->post()) && $model->login()) {
         return $this->redirect(\Yii::$app->urlManager->createUrl("admin/usermod"));
     }
     return 'l';
 }
Beispiel #11
0
 /**
  * Displays the login page.
  *
  * @return string|Response
  */
 public function actionLogin()
 {
     if (!Yii::$app->user->isGuest) {
         $this->goHome();
     }
     /** @var LoginForm $model */
     $model = Yii::createObject(LoginForm::className());
     $this->performAjaxValidation($model);
     if ($model->load(Yii::$app->getRequest()->post()) && $model->login()) {
         \someet\common\models\AdminLog::saveLog('登录成功', Yii::$app->user->id);
         return $this->goBack();
     }
     return $this->render('login', ['model' => $model, 'module' => $this->module]);
 }
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         $this->goHome();
     }
     $model = \Yii::createObject(LoginForm::className());
     $this->performAjaxValidation($model);
     if ($model->load(Yii::$app->getRequest()->post()) && $model->login()) {
         if (\Yii::$app->user->can('login_admin')) {
             echo Url::to(['/admin']);
         }
         return $this->goHome();
     }
     return $this->render('login', ['model' => $model]);
 }
 public function actionLogin()
 {
     \Yii::$app->response->format = Response::FORMAT_JSON;
     /** @var LoginForm $model */
     $model = Yii::createObject(LoginForm::className());
     $model->rememberMe = 0;
     //$this->performAjaxValidation($model);
     $model->login = Yii::$app->getRequest()->post()['login-form']['login'];
     $model->password = Yii::$app->getRequest()->post()['login-form']['password'];
     //$model->user = $this->finder->findUserByUsernameOrEmail($model->login);
     //$model->user = User::find()->where(['username'=>$model->login])->one();
     if ($model->login()) {
         //$user = $this->finder->findUserByUsernameOrEmail($model->login);
         //unset($user['password_hash']);
         //unset($user['auth_key']);
         //return $user;
         return !Yii::$app->user->isGuest;
     }
     return false;
 }
 /**
  * Creates a new Orders model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $industry = Yii::$app->request->get('industry');
     $process = Yii::$app->request->get('process');
     if (Yii::$app->session['cart'] != null && ($industry != null || $process != null)) {
         foreach (Yii::$app->session['cart']['industry'] as $key => $ind) {
             if ($key == $industry) {
                 $cart[$key] = $ind;
             }
         }
         $service = \common\models\CsServices::findOne($cart[$industry]['data'][1]['service']);
         $objects = $this->getObjectModels($cart[$industry]['data'][1]['object_models']);
         $user = !Yii::$app->user->isGuest ? \common\models\User::findOne(Yii::$app->user->id) : null;
         // orderer
         $model = new Orders();
         $model->service = $service;
         // skill model
         $model_skill = $this->loadServiceSkills($service);
         $location = new Locations();
         $location->control = $service->location;
         $location->userControl = Yii::$app->user->isGuest ? 0 : 1;
         $location_end = new Locations();
         $new_user = $user == null ? Yii::createObject(RegistrationProviderForm::className()) : null;
         // register provider
         $returning_user = $user == null ? Yii::createObject(LoginForm::className()) : null;
         // login existing user
         if ($model->load(Yii::$app->request->post())) {
             if (Yii::$app->user->isGuest) {
                 // register $ login user
                 if ($new_user->load(Yii::$app->request->post())) {
                     if ($user = $new_user->signup()) {
                         if (!Yii::$app->getUser()->login($user)) {
                             return $this->goBack();
                         }
                     }
                 }
                 // login user
                 if ($returning_user->load(Yii::$app->request->post())) {
                     if (!$returning_user->login()) {
                         return $this->goBack();
                     }
                 }
             }
             // continue
             $activity = Activities::loadActivity(Yii::$app->user->id);
             if ($activity->save()) {
                 // new activity saved
                 $model->activity_id = $activity->id;
                 $this->saveOrderLocation($model, $location, $service);
                 $this->saveOrderEndLocation($model, $location_end, $service);
                 if ($model->save()) {
                     $this->saveOrderSkills($model, $cart, $service);
                     $this->saveOrderServices($model, $activity, $cart, $service);
                     $this->eraseSessionData($industry);
                     // izbaci snimljene usluge iz korpe
                     return $this->redirect('/order/' . $model->id);
                 }
             } else {
                 return $this->redirect('/services');
             }
             return $this->redirect('/services');
         } else {
             return $this->render('create', ['service' => $service, 'model' => $model, 'model_skills' => $model_skill, 'location' => $location, 'location_end' => $location_end, 'objects' => $objects, 'new_user' => $new_user, 'returning_user' => $returning_user]);
         }
     } else {
         return $this->redirect('/services');
     }
 }
Beispiel #15
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     return $this->render('login', ['model' => \Yii::createObject(LoginForm::className())]);
 }
 /**
  * Creates a new Presentations model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $this->layout = '/user_presentation';
     if ($ps = Yii::$app->request->get('ProviderServices')) {
         if ($service = $this->findService($ps['service_id'])) {
             // service
             //print_r($service); die();
             $object_model = [];
             if (!empty($ps['object_model'])) {
                 foreach ($ps['object_model'] as $pso) {
                     $object_model[] = $this->findObjectModel($pso);
                 }
             }
             $user = !Yii::$app->user->isGuest ? \common\models\User::findOne(Yii::$app->user->id) : null;
             // presenter
             $model = new PresentationData();
             // new presentation
             $model->service = $service;
             $model->object_models = $object_model;
             $model->location_control = $service->location;
             $model->location_userControl = Yii::$app->user->isGuest ? 0 : 1;
             $model_action_properties = $model->loadPresentationActionProperties($service);
             // array of new presentationMethods
             $model_object_properties = $model->loadPresentationObjectProperties($service, $object_model);
             // array of new presentationSpecs
             $locationHQ = $model->hasProviderLocation() ? $model->hasProviderLocation() : new Locations();
             $locationPresentation = new LocationPresentation();
             $locationPresentationTo = new LocationPresentationTo();
             $model_timetable = new PresentationTimetables();
             $provider_openingHours = ($user and $provider = $user->provider and $provider->openingHours) ? $provider->openingHours : new ProviderOpeningHours();
             $model_notifications = new PresentationNotifications();
             $model_terms = new PresentationTerms();
             $model_termexpenses = new PresentationTermExpenses();
             $model_termmilestones = new PresentationTermMilestones();
             $model_termclauses = new PresentationTermClauses();
             $new_provider = $user == null ? Yii::createObject(RegistrationProviderForm::className()) : null;
             // register provider
             if ($new_provider) {
                 $new_provider->scenario = 'presentation';
             }
             $returning_user = $user == null ? Yii::createObject(LoginForm::className()) : null;
             // login existing user
             if ($returning_user) {
                 $returning_user->scenario = 'presentation';
             }
             if ($user == null) {
                 $this->performAjaxValidation($new_provider);
                 $this->performAjaxValidation($returning_user);
             }
             if ($model->load(Yii::$app->request->post())) {
                 $newUser = $user == null ? true : false;
                 // check if new user
                 if ($user = $user == null ? $this->saveUser($new_provider, $returning_user) : $user) {
                     // load user(presenter)
                     if ($newProvider = $user->is_provider == 0 ? true : false) {
                         if ($proserv = $this->saveProvider($user, $service)) {
                             if ($this->savePresentation($model, $user, $service, $object_model, $locationHQ, $locationPresentation, $locationPresentationTo, $proserv, $newUser, $newProvider, $model_object_properties, $model_action_properties, $model_terms, $model_timetable, $model_notifications, $provider_openingHours, $model_termexpenses, $model_termmilestones, $model_termclauses)) {
                                 return $this->redirect(['/presentation/' . $model->id]);
                             }
                         }
                     }
                     if ($proserv = $ps['id'] == null ? $this->saveProviderService($user, $service, $newProvider) : $this->findProviderService($ps['id'])) {
                         if ($this->savePresentation($model, $user, $service, $object_model, $locationHQ, $locationPresentation, $locationPresentationTo, $proserv, $newUser, $newProvider, $model_object_properties, $model_action_properties, $model_terms, $model_timetable, $model_notifications, $provider_openingHours, $model_termexpenses, $model_termmilestones, $model_termclauses)) {
                             return $newUser ? $this->redirect(['/blank']) : $this->redirect(['/presentation/' . $model->id]);
                         }
                     }
                 }
             } else {
                 return $this->render('create', ['service' => $service, 'model' => $model, 'model_action_properties' => $model_action_properties, 'model_object_properties' => $model_object_properties, 'object_model' => $object_model, 'new_provider' => $new_provider, 'returning_user' => $returning_user, 'locationHQ' => $locationHQ, 'locationPresentation' => $locationPresentation, 'locationPresentationTo' => $locationPresentationTo, 'user' => $user, 'model_timetable' => $model_timetable, 'provider_openingHours' => $provider_openingHours, 'model_notifications' => $model_notifications, 'model_terms' => $model_terms, 'model_termexpenses' => $model_termexpenses, 'model_termmilestones' => $model_termmilestones, 'model_termclauses' => $model_termclauses]);
             }
         } else {
             return $this->goBack();
         }
     } else {
         return $this->goBack();
     }
 }
 /**
  * Displays the login page.
  *
  * @return string|Response
  */
 public function actionLogin()
 {
     if (!Yii::$app->user->isGuest) {
         $this->goHome();
     }
     /** @var LoginForm $model */
     $model = Yii::createObject(LoginForm::className());
     $event = $this->getFormEvent($model);
     $this->performAjaxValidation($model);
     $this->trigger(self::EVENT_BEFORE_LOGIN, $event);
     if ($model->load(Yii::$app->getRequest()->post()) && $model->login()) {
         $this->trigger(self::EVENT_AFTER_LOGIN, $event);
         return $this->goBack();
     }
     return $this->render('login', ['model' => $model, 'module' => $this->module]);
 }
Beispiel #18
0
                    </div>
                </li>
            </ul>
        </div>
    </li>
</ul>
<!--login popup-->
<div class="popup_wrap d_none" id="login_popup">
    <section class="popup r_corners shadow">
        <button class="bg_tr color_dark tr_all_hover text_cs_hover close f_size_large"><i class="fa fa-times"></i>
        </button>
        <h3 class="m_bottom_20 color_dark">Log In</h3>
        <?php 
$form = ActiveForm::begin(['id' => 'login-form', 'enableAjaxValidation' => true, 'enableClientValidation' => false, 'validateOnBlur' => false, 'validateOnType' => false, 'validateOnChange' => false, 'action' => Url::to(['/user/security/login'])]);
/** @var dektrium\user\models\LoginForm $model */
$model = \Yii::createObject(LoginForm::className());
?>
        <ul>
            <li class="m_bottom_15">
                <?php 
echo $form->field($model, 'login', ['inputOptions' => ['autofocus' => 'autofocus', 'class' => 'r_corners full_width', 'tabindex' => '1']])->textInput()->label('Username', ['class' => 'm_bottom_5 d_inline_b']);
?>
            </li>
            <li class="m_bottom_25">
                <?php 
echo $form->field($model, 'password', ['inputOptions' => ['class' => 'r_corners full_width', 'tabindex' => '2']])->passwordInput()->label(Yii::t('user', 'Password'));
?>
            </li>
            <li class="m_bottom_15">
                <?php 
echo $form->field($model, 'rememberMe')->checkbox(['tabindex' => '4', 'class' => 'd_none']);