Exemple #1
0
 public function sendMailToAuthor($news, $subject)
 {
     $user = \app\models\Users::findOne($news->user_id);
     $body = sprintf('%s <br />
         Ссылка на новость - %s', $subject['author'], $this->urlToNews($news->id));
     $this->sendMail($user->email, $subject['author'], $body);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param null $user_id
  * @param null $group_id
  * @throws \yii\web\NotFoundHttpException
  * @return ActiveDataProvider
  */
 public function search($user_id = null, $group_id = null)
 {
     $query = Beacons::find();
     if (!Yii::$app->user->can(RbacController::admin)) {
         $user = Users::getLogged(true);
         $user->getBeaconsQuery($query);
     }
     if ($user_id !== null) {
         $user = Users::findOne(['id' => $user_id]);
         $user->getBeaconsQuery($query);
     }
     if ($group_id !== null) {
         $group = Groups::findOne(['id' => $group_id]);
         $query = $group->getBeacons();
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'minor' => $this->minor, 'major' => $this->major]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'uuid', $this->uuid]);
     return $dataProvider;
 }
 public function actionAjax()
 {
     $resultArray = array(2 => 0, 131 => 0, 25 => 0);
     $words = (new \yii\db\Query())->select(['translateWord', 'wordTranslate', 'typeWord', 'flashCards'])->from('users')->where(['userId' => $this->userId])->one();
     foreach ($resultArray as $key => $value) {
         if (strpos($words['flashCards'], "|{$key}|")) {
             $words['flashCards'] = str_replace("|{$key}|", "|", $words['flashCards']);
         }
     }
     $wordsModel = Users::findOne($this->userId);
     $wordsModel->flashCards = $words['flashCards'];
     if ($wordsModel->update()) {
         echo 'ok';
     } else {
         echo 'no';
     }
     //        if (Yii::$app->request->isAjax) {
     //            $success = true;
     //            foreach ($_POST['ajaxData'] as $key => $value) {
     //                $words = Vocabulary::findOne($key);
     //                if (!$words->updateCounters(['Learned' => $value])){
     //                    $success = false;
     //                }
     //            }
     //            if (!$success){
     //                echo  'Your session progress has successfully been saved';
     //            }else echo 'Your session progress has not been saved! An error has occured during proccessing';
     //        }
 }
Exemple #4
0
 /**
  * Creates a new Exchange model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Exchange();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->beforeValidate()) {
             if ($model->selectorIncomeExpenses == 'income') {
                 $model->expenses = 0;
                 $model->income = $model->inputIncomeExpenses;
             } else {
                 $model->income = 0;
                 $model->expenses = $model->inputIncomeExpenses;
             }
             if ($model->create_time) {
                 false;
             } else {
                 $model->create_time = date('Y-m-d');
             }
         }
         $users = Users::findOne(Yii::$app->user->id);
         $location = $users->location_id;
         $model_report = $model->updateReport($location, $model->create_time, $model->currency, $model->income, $model->expenses, $model->transaction, $model->bo);
         $model->location_id = $location;
         $model->save();
         $model_report->save();
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function execute($user, $item, $params)
 {
     $user_role = Users::findOne($user)->authAssignments->item_name;
     if (isset($params['news'])) {
         $news_status = $params['news']->status;
         $news_category = $params['news']->category_id;
         $relCat = !is_null(RelationCategories::findOne(['user_id' => $user, 'category_id' => $news_category]));
         if ($user_role == 'moderator' && $relCat && isset($params['action']) && $params['action'] == 'view') {
             return true;
         }
         if ($news_status == News::MODER_NEWS) {
             if ($user_role == 'moderator') {
                 return $relCat;
             }
         }
         if ($news_status == News::SMODER_NEWS) {
             if ($user_role == 'super_moderator') {
                 return true;
             }
         }
     } elseif (isset($params['question'])) {
         if ($user_role == 'moderator') {
             $news = News::findOne($params['question']->news_id);
             if (!is_null($news)) {
                 if ($news->status == News::MODER_NEWS && !is_null(RelationCategories::findOne(['user_id' => $user, 'category_id' => $news->category_id]))) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Exemple #6
0
 public function actionConfirm()
 {
     $table = new Users();
     if (Yii::$app->request->get()) {
         //Obtenemos el valor de los parámetros get
         $id = Html::encode($_GET["id"]);
         $authKey = $_GET["authKey"];
         if ((int) $id) {
             //Realizamos la consulta para obtener el registro
             $model = $table->find()->where("id=:id", [":id" => $id])->andWhere("authKey=:authKey", [":authKey" => $authKey]);
             //Si el registro existe
             if ($model->count() == 1) {
                 $activar = Users::findOne($id);
                 $activar->activate = 1;
                 if ($activar->update()) {
                     echo "Enhorabuena registro llevado a cabo correctamente, redireccionando ...";
                     echo "<meta http-equiv='refresh' content='8; " . Url::toRoute("site/login") . "'>";
                 } else {
                     echo "Ha ocurrido un error al realizar el registro, redireccionando ...";
                     echo "<meta http-equiv='refresh' content='8; " . Url::toRoute("site/login") . "'>";
                 }
             } else {
                 //Si no existe redireccionamos a login
                 return $this->redirect(["site/login"]);
             }
         } else {
             //Si id no es un número entero redireccionamos a login
             return $this->redirect(["site/login"]);
         }
     }
 }
Exemple #7
0
 /**
  * Finds the Users model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Users the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Users::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #8
0
 static function findByUsername($username)
 {
     $user = Users::findOne(['username' => $username]);
     if ($user) {
         return new static($user);
     }
     return null;
 }
 public function findModel($id)
 {
     if (($model = Users::findOne($id)) != null) {
         return $model;
     } else {
         throw new NotFoundHttpException('gak iso bos, ojo dipekso');
     }
 }
Exemple #10
0
 public static function findIdentity($id)
 {
     try {
         $user = Users::findOne($id);
         return $user ? new static($user) : false;
     } catch (Exception $e) {
         return false;
     }
 }
 /**
  * Finds the User model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * 
  * @param integer $id
  * @return User the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Users::findOne($id)) !== null) {
         return $model;
     } else {
         $this->getHeader(400);
         echo json_encode(['status' => 0, 'error_code' => 400, 'message' => 'Bad request'], JSON_PRETTY_PRINT);
         exit;
         // throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #12
0
 /**
  * Logs in a user using the provided username and password.
  * @return boolean whether the user is logged in successfully
  */
 public function login()
 {
     if ($this->validate()) {
         $model = Users::findOne(['mail' => $this->username]);
         $model->ip = \Yii::$app->getRequest()->getUserIP();
         $model->agent = \Yii::$app->getRequest()->getUserAgent();
         $model->last_login = new yii\db\Expression("NOW()");
         $model->save();
         return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
     }
     return false;
 }
 public function actionView($link)
 {
     /** @var Users $user */
     $user = Users::findOne(['link' => $link]);
     if (!$user) {
         throw new NotFoundHttpException('Неверная ссылка или проект удален');
     }
     Yii::$app->session->set('user', $user);
     $project = $user->project;
     $photos = $user->photos;
     return $this->render('view', ['user' => $user, 'project' => $project, 'photos' => $photos]);
 }
Exemple #14
0
 public function createClassInfo($model)
 {
     // 获取专业的中文名
     $majorid = substr($model->st_class, 0, 4);
     $major = Major::findOne($majorid);
     $model->class_major = $major->mj_name_zh;
     // 获取专业级数
     $model->class_year = '20' . substr($model->st_class, 4, 2) . '级';
     // 获取辅导员姓名
     $user = Users::findOne($model->teID);
     $model->te_name = $user->te_name;
     return $model;
 }
Exemple #15
0
 public function actionMyWishlist()
 {
     try {
         $id = Yii::$app->session['user_id'];
         if (empty($id)) {
             $this->redirect('http://bluebee-uet.com');
         }
         $data = Documents::getDocumentsByWishlist($id);
         $user = Users::findOne(['id' => $id]);
         Yii::$app->view->title = $user->name . ', đây là tài liệu bạn đã đánh dấu';
         return $this->render('//document/documents', $data);
     } catch (Exception $ex) {
     }
 }
 /**
  * Sends an email with a link, for resetting the password.
  *
  * @return boolean whether the email was send
  */
 public function sendEmail()
 {
     /* @var $user Users */
     $user = Users::findOne(['status' => Users::STATUS_ACTIVE, 'email' => $this->email]);
     if ($user) {
         if (!Users::isPasswordResetTokenValid($user->password_reset_token)) {
             $user->generatePasswordResetToken();
         }
         if ($user->save()) {
             return \Yii::$app->mailer->compose('password-token', ['user_name' => $user->email, 'password_reset_link' => Yii::$app->urlManager->createAbsoluteUrl(['site/password-change', 'token' => $user->password_reset_token])])->setTo($this->email)->send();
         }
     }
     return false;
 }
Exemple #17
0
 /**
  * @inheritdoc
  */
 public static function findOneCustom($condition, $checkRole = null)
 {
     // FIND ROLE
     $rolePrevious = 0;
     $roleSession = $rolePrevious;
     $roleCookie = $rolePrevious;
     $model = null;
     // SET Role: by MANUALLY. Default: at user requested time
     if (!is_null($checkRole)) {
         $rolePrevious = $checkRole;
         Yii::$app->session->set('user.role', $rolePrevious);
     }
     // Check Role: by PHP session. Default: at every loading page
     if (Yii::$app->session->has('user.role')) {
         $rolePrevious = intval(Yii::$app->session->get('user.role'));
         $roleSession = $rolePrevious;
     } elseif (Yii::$app->getRequest()->getCookies()->has('user_role')) {
         $rolePrevious = intval(Yii::$app->getRequest()->getCookies()->getValue('user_role'));
         $roleCookie = $rolePrevious;
         Yii::$app->session->set('user.role', $rolePrevious);
     }
     // FIND USER BY SELECTED ROLE
     if ($rolePrevious) {
         $user = null;
         if ($rolePrevious >= static::ROLE_ADMIN) {
             $user = Users::findOne($condition);
         } elseif ($rolePrevious >= static::ROLE_CLIENTES) {
             $user = Clientes::findOne($condition);
         }
         if ($user) {
             $model = new Identity();
             $model->data = $user->attributes;
             $model->data['id'] = $user->getPrimaryKey();
             // IF ALREADY LOGGED - RESTORE current user logged in ROLE
             if ($rolePrevious != $model->role) {
                 // UPDATE: Role: PHP Session: at runtime
                 if ($roleSession) {
                     Yii::$app->session->set('user.role', $model->role);
                 }
                 // UPDATE: Role: COOKIE: at runtime
                 if ($roleCookie) {
                     Yii::$app->getResponse()->getCookies()->add(new \yii\web\Cookie(['name' => 'user_role', 'value' => (string) $model->role, 'expire' => time() + 3600 * 24 * 30]));
                 }
             }
         }
     }
     // RETURN a searched user found or null if not
     return $model;
 }
 public function search($params)
 {
     // $query = Record::find();
     $b = Yii::$app->user->getId();
     // var_dump(Yii::$app->user);
     // die;
     $admin = Users::findOne($b);
     $academy = $admin->te_aca;
     $id = $admin->id;
     $te_id = self::searchte_id();
     $teClass = array();
     $te = teClass::find()->where(['teID' => $id])->asArray()->all();
     // var_dump($te);die;
     for ($i = 0; $i < sizeof($te); $i++) {
         $teClass[] = $te[$i]['st_class'];
     }
     // var_dump($teClass);die;
     if ($academy == "学生处") {
         $query = Record::find()->where(['status' => ['审核不通过', '审核通过']]);
     } else {
         if ($te_id == "辅导员") {
             $query = Record::find()->where(["academy" => $academy])->andwhere(['st_class' => $teClass])->andwhere(['status' => ['待审核', '审核通过', '审核不通过']]);
         } else {
             if ($te_id == "副书记") {
                 $query = Record::find()->where(["academy" => $academy])->andwhere(['status' => ['等待副书记审核']]);
             } else {
                 if ($te_id == "书记") {
                     $query = Record::find()->where(["academy" => $academy])->andwhere(['status' => ['等待书记审核']]);
                 }
             }
         }
     }
     // // $sql = 'SELECT * FROM record where academy=".$aa"';
     // $sql = "SELECT * FROM record where academy=(select te_aca from admin where id='".$b."' )";
     // $query = Record::findBySql($sql);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['today' => SORT_DESC]]]);
     $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(['totalday' => $this->totalday]);
     $query->andFilterWhere(['like', 'todaydetail', $this->todaydetail])->andFilterWhere(['like', 'st_classmark', $this->st_classmark])->andFilterWhere(['like', 'startday', $this->startday])->andFilterWhere(['like', 'endday', $this->endday])->andFilterWhere(['like', 'country', $this->country])->andFilterWhere(['like', 'countryEN', $this->countryEN])->andFilterWhere(['like', 'st_name', $this->st_name])->andFilterWhere(['like', 'st_nameEN', $this->st_nameEN])->andFilterWhere(['like', 'gaokaohao', $this->gaokaohao])->andFilterWhere(['like', 'idcard', $this->idcard])->andFilterWhere(['like', 'sex', $this->sex])->andFilterWhere(['like', 'st_year', $this->st_year])->andFilterWhere(['like', 'st_class', $this->st_class])->andFilterWhere(['like', 'academy', $this->academy])->andFilterWhere(['like', 'major', $this->major])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'model', $this->model])->andFilterWhere(['like', 'today', $this->today]);
     return $dataProvider;
 }
 public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     $model = Users::findOne(\Yii::$app->user->id);
     /* @var Users $model */
     $model->login = $this->login;
     $model->first_name = $this->first_name;
     $model->last_name = $this->last_name;
     if ($this->date_of_birth) {
         $model->date_of_birth = DateTime::createFromFormat('d/m/Y', $this->date_of_birth)->format('Y-m-d');
     } else {
         $model->date_of_birth = null;
     }
     $model->save();
     return true;
 }
Exemple #20
0
 /**
  * ќтправка денег между пользовател¤ми
  * @param $uTo
  * @param $uFrom
  * @param $money
  * @return int - чтобы посчитать сколько создано операций
  * @throws \yii\db\Exception
  */
 public static function sendMoneyFill($uTo, $uFrom, $money)
 {
     $userTo = Users::findOne($uTo);
     $userFrom = Users::findOne($uFrom);
     $money = (int) ($money * 100) / 100;
     $transaction = \Yii::$app->db->beginTransaction();
     try {
         if ($money <= 0) {
             throw new Exception(" Money < 0");
         }
         if (isset($userTo) && isset($userTo->user_id) && isset($userFrom->user_id) && $userTo->user_id != $userFrom->user_id) {
             $userMoney = \Yii::$app->db->createCommand("SELECT user_id, user_money FROM public.user WHERE user_id IN (:idFrom, :idTo) FOR UPDATE", array(':idTo' => $userTo->user_id, ':idFrom' => $userFrom->user_id))->queryAll();
             if ($userMoney[0]['user_id'] == $userTo->user_id) {
                 $userMoneyTo = $userMoney[0]['user_money'];
                 $userMoneyFrom = $userMoney[1]['user_money'];
             } else {
                 $userMoneyTo = $userMoney[1]['user_money'];
                 $userMoneyFrom = $userMoney[0]['user_money'];
             }
             if ($userMoneyFrom - $money < 0) {
                 throw new Exception(" User (id: " . $userFrom->user_id . ") not enough money");
             }
             $to_balance = $userMoneyTo + $money;
             $userTo->user_money = $to_balance;
             $from_balance = $userMoneyFrom - $money;
             $userFrom->user_money = $from_balance;
             if ($userTo->save() && $userFrom->save()) {
                 self::setOperation($userFrom->user_id, $userTo->user_id, $money, $to_balance, $from_balance);
                 $transaction->commit();
                 echo '|';
                 return 1;
             } else {
                 throw new Exception(" User (id:" . $uFrom . ") failed to add money to user (id: " . $uTo . ")");
             }
         } else {
             throw new Exception(" user (id: " . $uFrom . ") not exist or user (id: " . $uTo . ") wanted to transfer the money at yourself");
         }
     } catch (Exception $e) {
         $text = date('Y-m-d H:i') . $e->getMessage() . PHP_EOL;
         file_put_contents("demoLog.txt", $text, FILE_APPEND);
         $transaction->rollBack();
     }
 }
Exemple #21
0
 public static function getDocumentById($id)
 {
     $document = Documents::findOne(['id' => $id]);
     $retVal = array();
     $retVal['id'] = $document->id;
     $retVal['name'] = $document->name;
     $retVal['description'] = $document->description;
     $retVal['created_at'] = Date('d/m/Y', $document->created_at);
     $retVal['updated_at'] = Date('d/m/Y', $document->updated_at);
     $retVal['preview'] = $document->preview;
     $retVal['original_url'] = $document->original_url;
     $retVal['money_url'] = $document->money_url;
     $retVal['subject'] = Subjects::findOne(['id' => $document->subject])->name;
     $retVal['user'] = Users::findOne(['id' => $document->user]);
     $retVal['number_download'] = $document->number_download;
     $retVal['pdf'] = $document->pdf;
     $retVal['scribd_id'] = $document->scribd_id;
     return $retVal;
 }
Exemple #22
0
 public static function getUserById($id)
 {
     $retVal = array();
     $user = Users::findOne(['id' => $id]);
     $retVal['id'] = $user->id;
     $retVal['name'] = $user->name;
     $retVal['avatar'] = $user->avatar;
     $retVal['fb_id'] = $user->fb_id;
     $retVal['description'] = $user->description;
     $retVal['created_at'] = Date('d/m/Y', $user->created_at);
     $retVal['updated_at'] = Date('d/m/Y', $user->updated_at);
     $retVal['number_upload'] = $user->number_upload;
     $retVal['points'] = $user->points;
     $retVal['role'] = $user->role;
     $retVal['status'] = $user->status;
     $retVal['gender'] = \app\components\Util::getGender($user->gender);
     $retVal['dob'] = $user->dob;
     $retVal['email'] = $user->email;
     return $retVal;
 }
 public function actionForm($id = NULL)
 {
     if (Yii::$app->user->can('createProject')) {
         $model = $id ? Projects::findOne($id) : new Projects();
         $model->counters = $model->projectCounters ? array_keys(ArrayHelper::map($model->projectCounters, 'id', 'username')) : [Yii::$app->user->getId()];
         if (!($model->load(Yii::$app->request->post()) && $model->validate())) {
             return $this->render('form', ['model' => $model, 'users' => Users::find()->select(['id', 'username', 'fullname'])->all()]);
         }
         $model->save(false);
         /* Project counters */
         $model->unlinkAll('projectCounters', true);
         foreach (Yii::$app->request->post('Projects')['counters'] as $countUser) {
             if (!($countUser = Users::findOne($countUser)) == false) {
                 $countUser->link('counterProjects', $model);
             }
         }
         return $this->redirect(Url::toRoute('projects/detail/' . $model->id));
     }
     return $this->redirect(Url::toRoute('projects/index'));
 }
Exemple #24
0
 public function registerDrupalUser($user_id)
 {
     /* User data */
     $drupalData = user_load($user_id);
     $userModel = Users::findOne($user_id) ? Users::findOne($user_id) : new Users();
     $userModel->id = $drupalData->uid;
     $userModel->username = $drupalData->name;
     $userModel->fullname = field_get_items('user', user_load($user_id), 'field_fullname')[0]['value'];
     $userModel->save();
     $this->yiiUser = $userModel;
     /* Revoke all roles */
     $this->authManager->revokeAll($this->yiiUser->id);
     /* User roles */
     foreach ($this->drupalUser->roles as $role) {
         $role = $this->authManager->getRole($role);
         $userRoles = array_keys($this->authManager->getRolesByUser($this->yiiUser->id));
         if ($role && !in_array($role->name, $userRoles)) {
             $this->authManager->assign($role, $this->yiiUser->id);
         }
     }
 }
 public function actionPersonalDetails()
 {
     if (Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new PersonalDetailsForm();
     if ($user = Users::findOne(Yii::$app->user->id)) {
         $model->initForm($user);
     }
     $interests_model = new UsersInterestsForm();
     $interests = UsersInterests::find()->where([UsersInterests::FIELD_USER_ID => Yii::$app->user->id])->all();
     if ($model->load(Yii::$app->request->post(), 'PersonalDetailsForm') && $model->save()) {
         Yii::$app->session->setFlash('success', 'Personal details update successfully');
         return $this->redirect('personal-details');
     }
     if ($interests_model->load(Yii::$app->request->post(), 'UsersInterestsForm') && $interests_model->save()) {
         Yii::$app->session->setFlash('success', 'Interest added successfully');
         return $this->redirect('personal-details');
     }
     return $this->render('personal_details', ['model' => $model, 'interests_model' => $interests_model, 'interests' => $interests]);
 }
 public function actionUpload()
 {
     $file = UploadedFile::getInstanceByName('file');
     if ($file->hasError) {
         throw new ServerErrorHttpException('Ошибка при загрузке');
     }
     /** @var Users $user */
     $user = Users::findOne(Yii::$app->request->post('user_id'));
     if (!$user) {
         throw new NotFoundHttpException('Не наден пользователь');
     }
     $fileName = $file->name;
     $uploadDir = Yii::getAlias('@webroot/images/' . $user->id . '/');
     FileHelper::createDirectory($uploadDir);
     // Thumbnail
     $img = Image::getImagine()->open($file->tempName);
     $size = $img->getSize();
     $ratio = $size->getWidth() / $size->getHeight();
     $width = Yii::$app->params['thumbnailWidth'];
     $height = round($width / $ratio);
     // Save thumbnail
     Image::thumbnail($file->tempName, $width, $height)->save($uploadDir . 'thumbnail_' . $fileName, ['quality' => 70]);
     // Save image
     if (file_exists($uploadDir . $fileName)) {
         $fileName = $file->baseName . '-' . uniqid() . '.' . $file->extension;
     }
     if (!$file->saveAs($uploadDir . $fileName)) {
         throw new ServerErrorHttpException('Ошибка при сохранении файла');
     }
     // Save model
     $model = new Photo();
     $model->user_id = $user->id;
     $model->project_id = $user->project_id;
     $model->filename = $fileName;
     $model->save();
     $response = ['filename' => $fileName];
     return Json::encode($response);
 }
 public function actionUpdateStatus()
 {
     $status = Yii::$app->request->post('status');
     $idList = Yii::$app->request->post('selection');
     if (!empty($status) && !empty($idList)) {
         foreach ($idList as $key => $val) {
             TrainUsers::updateAll(['status' => $status], ['id' => $val]);
             if ($status == TrainUsers::ENROLL) {
                 $trainUsersInfo = TrainUsers::findOne($val);
                 //录取发送系统通知
                 $content = "您好,很高兴的通知您,您报名的培训班已通过审核,请按指定日期前往培训地点缴费上课。【教练系统】";
                 $userInfo = Users::findOne(['id' => $trainUsersInfo['user_id']]);
                 $result = $this->sendMessage($content, Messages::TRAIN_SIGN_SUCCESS, $trainUsersInfo['user_id'], $userInfo['mobile_phone'], '1');
                 if ($result != '0') {
                     throw new ServerErrorHttpException('' . $result . '!');
                 }
             }
             if ($status == TrainUsers::END) {
                 $trainUsersInfo = TrainUsers::findOne($val);
                 //结束发送系统通知
                 $content = "尊敬的学员,您参与的培训课程已经结束,请等待评分,谢谢!【教练系统】";
                 $userInfo = Users::findOne(['id' => $trainUsersInfo['user_id']]);
                 $result = $this->sendMessage($content, Messages::TRAIN_END, $trainUsersInfo['user_id'], $userInfo['mobile_phone'], '1');
                 if ($result != '0') {
                     throw new ServerErrorHttpException('' . $result . '!');
                 }
             }
         }
         return $this->redirect(Yii::$app->request->referrer);
     } else {
         throw new ServerErrorHttpException('请选择评分信息!');
     }
 }
Exemple #28
0
 public function actionResetpass()
 {
     //Instancia para validar el formulario
     $model = new FormResetPass();
     //Mensaje que será mostrado al usuario
     $msg = null;
     //Abrimos la sesión
     $session = new Session();
     $session->open();
     //Si no existen las variables de sesión requeridas lo expulsamos a la página de inicio
     if (empty($session["recover"]) || empty($session["id_recover"])) {
         return $this->redirect(["site/index"]);
     } else {
         $recover = $session["recover"];
         //El valor de esta variable de sesión la cargamos en el campo recover del formulario
         $model->recover = $recover;
         //Esta variable contiene el id del usuario que solicitó restablecer el password
         //La utilizaremos para realizar la consulta a la tabla users
         $id_recover = $session["id_recover"];
     }
     //Si el formulario es enviado para resetear el password
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             //Si el valor de la variable de sesión recover es correcta
             if ($recover == $model->recover) {
                 //Preparamos la consulta para resetear el password, requerimos el email, el id
                 //del usuario que fue guardado en una variable de session y el código de verificación
                 //que fue enviado en el correo al usuario y que fue guardado en el registro
                 $table = Users::findOne(["email" => $model->email, "id" => $id_recover, "verification_code" => $model->verification_code]);
                 //Encriptar el password
                 $table->password = crypt($model->password, Yii::$app->params["salt"]);
                 //Si la actualización se lleva a cabo correctamente
                 if ($table->save()) {
                     //Destruir las variables de sesión
                     $session->destroy();
                     //Vaciar los campos del formulario
                     $model->email = null;
                     $model->password = null;
                     $model->password_repeat = null;
                     $model->recover = null;
                     $model->verification_code = null;
                     $msg = "Enhorabuena, password reseteado correctamente, redireccionando a la página de login ...";
                     $msg .= "<meta http-equiv='refresh' content='5; " . Url::toRoute("site/login") . "'>";
                 } else {
                     $msg = "Ha ocurrido un error";
                 }
             } else {
                 $model->getErrors();
             }
         }
     }
     return $this->render("resetpass", ["model" => $model, "msg" => $msg]);
 }
Exemple #29
0
 public function actionNews()
 {
     $news = Users::findOne(Yii::$app->user->id)->news;
     return $this->render('news', ['dataProvider' => $news]);
 }
Exemple #30
0
 public function findByName($username)
 {
     return Users::findOne(['name' => $username]);
 }