コード例 #1
0
 /**
  * Displays the login page
  * Handles processing of the login form and forgot password form
  */
 public function actionLogin()
 {
     $UserLogin = new UserLogin();
     $this->layout = false;
     // redirect if user already logged in
     //if (!Yii::app()->user->isGuest) {
     //    $this->redirect($this->createUrl('/site/dashboard'));
     //}
     // process login form submission
     if (isset($_POST['UserLogin'])) {
         if (isset($_POST['UserLogin']['LoginEmail'])) {
             // user login
             // set model scenario
             $UserLogin->scenario = 'formLogin';
             // collect user input data
             $UserLogin->attributes = $_POST['UserLogin'];
             // validate user input and redirect to the dashboard
             if ($UserLogin->validate() && $UserLogin->authenticate()) {
                 // redirect to relevant dashboard based on role
                 $authRoles = Yii::app()->authManager->getRoles(Yii::app()->user->id);
                 foreach (array_keys($authRoles) as $authRole) {
                     switch ($authRole) {
                         case 'superAdministrator':
                             $this->redirect($this->createUrl('admin/index'));
                             break;
                         case 'testimonialReviewer':
                         case 'testimonialApprover':
                             $this->redirect($this->createUrl('testimonial/dashboard'));
                             break;
                     }
                 }
                 // do redirect
                 if (UserLogin::model()->findByPk(Yii::app()->user->id)->IsPasswordReset) {
                     // change password form
                     $this->redirect($this->createUrl('user/profilepasswordupdate'));
                 } else {
                     // default dashboard
                     // echo ":TEST:";
                     // echo(UserLogin::model()->findByPk(Yii::app()->user->id)->AgreetoTerms);
                     //die(':TEST');
                     $this->redirect($this->createUrl('company/index'));
                 }
             }
         } elseif (isset($_POST['UserLogin']['ResetEmail'])) {
             // password reset
             // email of account for password reset
             $resetEmail = $_POST['UserLogin']['ResetEmail'];
             // check for record matching entered email
             if (!($UserLogin = UserLogin::model()->findByAttributes(array('LoginEmail' => $resetEmail)))) {
                 $UserLogin = new UserLogin();
             }
             // set model scenario
             $UserLogin->scenario = 'formReset';
             // generate a new password
             $newPassword = $UserLogin->generatePassword();
             // set reset attributes
             $UserLogin->UserPassword = md5($newPassword);
             $UserLogin->ResetEmail = $resetEmail;
             $UserLogin->IsPasswordReset = 1;
             // save password change
             if ($UserLogin->save()) {
                 // build message with temporary password
                 $mail = new YiiMailer();
                 $mail->clearLayout();
                 // no layout, plain text email
                 $mail->setFrom(Yii::app()->params['adminEmail'], Yii::app()->params['adminName']);
                 $mail->setTo($UserLogin->ResetEmail);
                 $mail->setSubject('ITR | Password Reset');
                 $mail->setBody('Your password has been reset, you may now log in with the following temporary password: '******'success', 'An email with a temporary password has been sent to your email address.');
                 } else {
                     // set failure message for user
                     Yii::app()->user->setFlash('failure', 'There was an error when trying to send your temporary password.  Please try again in a few minutes or contact web support.');
                 }
                 // reload view, clears post variables
                 $this->redirect($this->createUrl('user/login'));
             }
             // clear generated password so it doesn't display on the login form
             $UserLogin->UserPassword = '';
         }
     }
     // display the login form
     $this->render('login', array('UserLogin' => $UserLogin));
 }
コード例 #2
0
 public function actionSpam($order_id)
 {
     header('Content-type: application/json');
     $zakaz = Zakaz::model()->findByPk($order_id);
     if (!$zakaz) {
         throw new CHttpException(500);
     }
     $criteria = new CDbCriteria();
     if (Campaign::getId()) {
         $projectFields = $zakaz->getFields();
         if ($projectFields) {
             foreach ($projectFields as $field) {
                 if ($field->required == ProjectField::REQUIRED_YES_REG_SPAM) {
                     $varname = $field->varname;
                     $value = $zakaz->{$varname};
                     $criteria->addSearchCondition('profile.' . $varname, $value);
                     //$criteria->addCondition('profile.'.$varname.' REGEXP \'(^|[[:punct:]])'.$value.'($|[[:punct:]])\'');
                 }
             }
         }
         //echo json_encode(array('error'=>$tmp));
         //Yii::app()->end();
     }
     /* else {
     			$job = $zakaz->job_id;
     			$discipline = $zakaz->category_id;
     			
     			$criteria->addSearchCondition('profile.discipline',$discipline);
     			$criteria->addSearchCondition('profile.job_type',$job, true, 'OR');
             }*/
     $authors = User::model()->with('profile')->findAll($criteria);
     if (!empty($authors)) {
         $link = $this->createAbsoluteUrl('/project/chat/', ['orderId' => $order_id]);
         $mail = new YiiMailer();
         $mail->clearLayout();
         $mail->setFrom(Yii::app()->params['supportEmail'], Yii::app()->name);
         $mail->setSubject('Приглашение в проект');
         $link = 'http://' . $_SERVER['SERVER_NAME'] . '/project/chat?orderId=' . $order_id;
         $mail->setBody('<a href="' . $link . '">' . $link . '</a>');
         foreach ($authors as $author) {
             $mail->setTo($author->email);
             if ($author->getUserRole($author->id) == 'Author') {
                 $mail->send();
             }
         }
         echo 'ok =)';
         $email = new Emails();
         // новая рассылка
         $orderId = $order_id;
         $typeId = Emails::TYPE_14;
         $order = Zakaz::model()->findByPk($orderId);
         $user = User::model()->findByPk($order->user_id);
         $type_id = Emails::TYPE_18;
         $email->to_id = $user->id;
         $profile = Profile::model()->findAll("`user_id`='{$user->id}'");
         $rec = Templates::model()->findAll("`type_id`='{$typeId}'");
         $title = $rec[0]->title;
         $email->name = $profle->firstname;
         if (strlen($email->name) < 2) {
             $email->name = $user->username;
         }
         $email->login = $user->username;
         $email->num_order = $orderId;
         $email->page_order = 'http://' . $_SERVER['SERVER_NAME'] . '/project/chat?orderId=' . $orderId;
         $email->message = $rec[0]->text;
         $email->sendTo($user->email, $rec[0]->text, $typeId);
     } else {
         echo json_encode(array('error' => 'Нет авторов'));
     }
     Yii::app()->end();
 }