public function actionLogin()
 {
     $app = Mindy::app();
     if (!$app->user->getIsGuest()) {
         $model = $app->getUser();
         $key = Key::objects()->get(['user' => $model]);
         echo $this->json(['status' => true, 'errors' => [], 'user' => UserHelper::userToJson($model, $key ? $key->key : null), 'message' => UserModule::t('You have successfully logged in to the site')]);
         $this->end();
     }
     $form = new LoginForm();
     $r = $this->getRequest();
     if ($r->getIsPost() && $form->setAttributes($_POST)->isValid() && $form->login()) {
         $model = $form->getUser();
         $this->clearKeys($model);
         $authKey = md5(Password::generateSalt());
         $key = new Key(['user' => $model, 'key' => $authKey]);
         if ($key->save() === false) {
             echo $this->json(['status' => false, 'error' => 'Failed to save token']);
             $this->end();
         }
         $data = ['errors' => [], 'status' => true, 'user' => UserHelper::userToJson($model, $authKey), 'message' => UserModule::t('You have successfully logged in to the site')];
     } else {
         $data = ['errors' => $form->getErrors()];
     }
     echo $this->json($data);
     $this->end();
 }
Example #2
0
 public function actionLogin()
 {
     $form = new LoginForm();
     if ($this->r->isPost && $form->populate($_POST)->isValid() && $form->login()) {
         if ($this->r->isAjax) {
             echo $this->json(array('status' => 'success', 'title' => UserModule::t('You have successfully logged in to the site')));
         } else {
             $this->r->redirect('admin:index');
         }
     }
     $data = ['form' => $form];
     if ($this->r->isAjax) {
         echo $this->json(['content' => $this->render('admin/_login.html', $data)]);
     } else {
         echo $this->render('admin/login.html', $data);
     }
 }
Example #3
0
 public function actionLogin()
 {
     $request = $this->getRequest();
     $app = Mindy::app();
     if ($app->getUser()->getIsGuest() === false) {
         $request->redirect('user:profile');
     }
     $this->addBreadcrumb(UserModule::t("Login"));
     $form = new LoginForm();
     if ($request->getIsPost() && $form->populate($_POST)->isValid() && $form->login()) {
         $this->redirectNext();
         if ($request->getIsAjax()) {
             echo $this->json(['status' => 'success', 'title' => UserModule::t('You have successfully logged in to the site')]);
             Mindy::app()->end();
         } else {
             $request->redirect('user:profile');
         }
     }
     echo $this->render('user/login.html', ['form' => $form]);
 }