/** * 登录控制 * @return type */ public function actionLogin() { if (!\Yii::$app->user->isGuest) { $this->redirect('/member/index.html'); } $time = time(); $time = $time - 10; if (!empty(\Yii::$app->request->get('id')) && !empty(\Yii::$app->request->get('stoken'))) { $user_id = \Yii::$app->request->get('id'); $stoken = \Yii::$app->request->get('stoken'); //$user = Users::model()->find(" user_id=:id AND repstaken=:repstaken AND repsativetime>=:time", array(":id"=>$user_id,":repstaken" => $stoken, ":time" => $time)); //echo $user_id;exit; $user = User::find()->where(" user_id=:id", [":id" => $user_id])->one(); //$user = User::model()->find(" user_id=:id", array(":id" => $user_id)); if ($user) { $loginform = new LoginForm(); $loginform->setAttributes(['username' => $user->username, 'password' => $user->password, 'rememberMe' => true]); if ($loginform->login(2)) { $this->redirect('/member/index.html'); \Yii::$app->end(); } } } $this->redirect('/public/nologin.html'); }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->user === false) { $this->user = User::find()->andWhere(['or', ['username' => $this->username], ['email' => $this->username]])->one(); } return $this->user; }
public function actionIndexadd() { if (Yii::$app->user->isGuest) { $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } else { return $this->render('/site/login', ['model' => $model]); } } else { $Order = new Order(); $Order->user_id = Yii::$app->user->identity->id; $Order->date_time = date('Y-m-d H:i:s'); $Order->status_id = '1'; $Order->save(); $Card = new CardList(); $Products = $Card->getCardAndCardList(Yii::$app->user->identity->id); $Ord = new Order(); $order_id = $Ord->GetOrderId(Yii::$app->user->identity->id); for ($i = 0; $i < sizeof($Products); $i++) { $Orderlist = new Orderlist(); $Orderlist->order_id = $order_id[0]['MAX(`order_id`)']; $Orderlist->product_id = $Products[$i]['product_id']; $Orderlist->quantity = $Products[$i]['quantity']; $Orderlist->save(); } $card = new Card(); $card->DeleteCardId(Yii::$app->user->identity->id); $order = $Ord->GetOrdersFromID(Yii::$app->user->identity->id); $user = User::find()->where(['id' => Yii::$app->user->identity->id])->one(); return $this->render('index', ['user' => $user, 'order' => $order]); } }
public function actionGetUserInfo() { $user = wanhunet::$app->user; $userArray = User::find()->where(['id' => $user->id])->select(['username', 'id'])->asArray()->one(); $userArray['role'] = current(wanhunet::$app->authManager->getRolesByUser($user->id)); return $userArray; }
public function actionCreate2() { $username = Yii::$app->user->identity->username; $users = User::find()->all(); $scholars = Scholar::find()->all(); $model2 = new Email(); foreach ($users as $user) { foreach ($scholars as $scholar) { if ($user->username == $username && $user->id == $scholar->scholar_user_id) { $model2->email_scholar_id = $scholar->scholar_id; $model2->subject = "Low/Fail Grade"; if ($model2->load(Yii::$app->request->post())) { if ($model->load(Yii::$app->request->post())) { $to = "*****@*****.**"; $subject = "Low/Fail Grade"; $body = $model2->content . "\nfrom:" . $scholar->scholar_contact_email . PHP_EOL; $headers = "from: root@localhost"; if (mail($to, $subject, $body, $headers)) { \Yii::$app->getSession()->setFlash('error', 'The message is delivered'); } else { \Yii::$app->getSession()->setFlash('error', 'Message failed'); } return $this->redirect(['subject/index', 'id' => $model2->email_id]); return $this->redirect(['create2', 'id' => $model2->email_id]); } else { return $this->render('create2', ['model2' => $model2]); } } } } } }
/** * Уведомления при подписке на человека */ public function actionSubscriptionUserNotifications() { $date_minus_six_hours = new \DateTime(); $date_minus_six_hours = $date_minus_six_hours->modify('-2 hours'); $email_queue = []; $wall_events = Wall::find()->where('created >= ' . $date_minus_six_hours->getTimestamp() . ' AND created <= ' . time())->all(); foreach ($wall_events as $event) { if ($event->type == 2) { $event_data = json_decode($event->mem); $User = User::findOne(['id' => $event_data->to]); $Subscriber = User::find()->where(['id' => $event_data->from])->asArray()->one(); if ($Subscriber) { $email_queue[$User->email][$event_data->from] = ['subscriber' => User::find()->where(['id' => $event_data->from])->asArray()->one(), 'data' => $event->created, 'status' => $event_data->status]; } } } foreach ($email_queue as $email => $recipient) { $subscribed = []; $unsubscribed = []; foreach ($recipient as $person) { if ($person['status']) { $subscribed[] = $person; } else { $unsubscribed[] = $person; } } $messages[] = \Yii::$app->mailer->compose('user-subscribe', ['subscribed' => $subscribed, 'unsubscribed' => $unsubscribed])->setFrom('*****@*****.**')->setTo($email)->setSubject('Для Вас есть новые уведомления на сайте http://findspree.ru'); } if (isset($messages) && !empty($messages)) { \Yii::$app->mailer->sendMultiple($messages); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::find()->joinWith('authAssignment.authItem'); $pageSize = isset($_GET['per-page']) ? $_GET['per-page'] : \Yii::$app->params['user.defaultPageSize']; // Aca se cocina lo que deberia ver el usuario segun su rol $rol = User::getRol(Yii::$app->user->getId()); // el administrador no puede ver al usuario consejo, el consejo puede ver a todos, // el intendente no puede ver al consejo ni administrador switch ($rol->name) { case (string) "administrador": $query->andFilterWhere(['not in', 'item_name', ['consejo']]); break; case (string) "consejo": break; case (string) "intendente": $query->andFilterWhere(['not in', 'item_name', ['administrador', 'consejo']]); break; default: $query->andFilterWhere(['not in', 'item_name', ['intendente', 'administrador', 'consejo']]); } $query->andFilterWhere(['status' => User::STATUS_ACTIVE]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $pageSize], 'sort' => ['defaultOrder' => ['id' => SORT_DESC], 'enableMultiSort' => true]]); // Agregado a mano, para que incluya el ordenamiento por descCliente $dataProvider->sort->attributes['descRolUsuario'] = ['asc' => ['auth_item.description' => SORT_ASC], 'desc' => ['auth_item.description' => 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(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'acceso_externo' => $this->acceso_externo]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'auth_item.description', $this->descRolUsuario]); return $dataProvider; }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->user === false) { $this->user = User::find()->activated()->notDeleted()->andWhere(['or', ['username' => $this->identity], ['email' => $this->identity]])->one(); } return $this->user; }
/** * Список пользователей в компании. * * @return string */ public function actionList() { /** @var \common\models\User $user */ $user = Yii::$app->getUser()->getIdentity(); $users = User::find()->where('user_id!=:user_id and company_id=:company_id and is_deleted=0', ['user_id' => $user->getId(), 'company_id' => $user->getCompanyId()])->all(); return $this->render('list', ['users' => $users]); }
/** * Finds user by [[username]] or [[id]]. * * @return User|null */ protected function getUser() { if ($this->user === null) { $this->user = User::find()->andWhere(['and', ['or', ['username' => $this->identity], ['email' => $this->identity]]])->active()->one(); } return $this->user; }
/** * Creates data provider instance with search query applied * @return ActiveDataProvider */ public function search($params) { $query = User::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); // Important: here is how we set up the sorting // The key is the attribute name on our "TourSearch" instance $dataProvider->sort->attributes['search_date_created'] = ['asc' => ['created_at' => SORT_ASC], 'desc' => ['created_at' => SORT_DESC]]; // Important: here is how we set up the sorting // The key is the attribute name on our "TourSearch" instance $dataProvider->sort->attributes['search_date_logged'] = ['asc' => ['logged_at' => SORT_ASC], 'desc' => ['logged_at' => SORT_DESC]]; if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'domain_id' => $this->domain_id]); if ($this->search_date_created != '') { $this->data_begin_created = strtotime($this->search_date_created); $this->data_end_created = strtotime($this->search_date_created) + 24 * 60 * 60; } if ($this->search_date_logged != '') { $this->data_begin_logged = strtotime($this->search_date_logged); $this->data_end_logged = strtotime($this->search_date_logged) + 24 * 60 * 60; } $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['between', 'created_at', $this->data_begin_created, $this->data_end_created])->andFilterWhere(['between', 'logged_at', $this->data_begin_logged, $this->data_end_logged])->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup1() { if ($this->validate()) { $user = new user(); $user->username = $this->email; $user->email = $this->email; $user->firstname = $this->fname; $user->lastname = $this->lname; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { \Yii::$app->mailer->compose(['html' => 'auth-html'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Authenticate your account ' . \Yii::$app->name)->send(); $date = Yii::$app->formatter->asDatetime(date('Y-d-m h:i:s')); $car = new Car(); //$model_name=$this->$model_name; $row = Car::find()->where('model=:model AND model_name=:model_name AND fuel=:fuel AND variant=:variant', array(':model' => $this->brand, ':model_name' => $this->model_name, 'fuel' => $this->fuel, 'variant' => $this->variant))->one(); $user = User::find()->where('email=:email', array(':email' => $this->email))->one(); $urequest = new Userrequest(); $urequest->car_id = $row->id; $urequest->user_id = $user->id; $urequest->color = $this->color; $urequest->city = $this->city; $urequest->other = $this->other; $urequest->delivery = $this->delivery; $urequest->status = 0; $urequest->time = $date; if ($urequest->save()) { return $user; } } else { return null; } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => array('pageSize' => 2)]); $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->joinWith('usertype'); if (isset($params['UserSearch']['search']) && $params['UserSearch']['search'] != '') { if ($params['UserSearch']['field'] == '') { $query->orFilterWhere(['=', 'user.id', $params['UserSearch']['search']])->orFilterWhere(['=', 'user.status', $params['UserSearch']['search']])->orFilterWhere(['like', 'user.first_name', $params['UserSearch']['search']])->orFilterWhere(['like', 'user.last_name', $params['UserSearch']['search']])->orFilterWhere(['like', 'user.email', $params['UserSearch']['search']])->orFilterWhere(['like', 'user.created_at', $params['UserSearch']['search']])->orFilterWhere(['like', 'user_type.title', $params['UserSearch']['search']])->orFilterWhere(['like', 'user.username', $params['UserSearch']['search']]); } else { if ($params['UserSearch']['field'] == 'id' || $params['UserSearch']['field'] == 'status') { $query->andFilterWhere(['=', 'user.' . $params['UserSearch']['field'], $params['UserSearch']['search']]); } elseif ($params['UserSearch']['field'] == 'user_type_id') { $query->andFilterWhere(['like', 'user_type.title', $params['UserSearch']['search']]); } else { $query->andFilterWhere(['like', 'user.' . $params['UserSearch']['field'], $params['UserSearch']['search']]); } } } else { $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'first_name', $this->first_name])->andFilterWhere(['like', 'last_name', $this->last_name])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'user_type.title', $this->user_type_id]); } return $dataProvider; }
public function actionIndex() { if (Yii::$app->user->isGuest) { $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } else { return $this->render('/site/login', ['model' => $model]); } } else { if (!empty($_POST)) { $model = new User(); $model = User::find()->where(['id' => Yii::$app->user->identity->id])->one(); //$model->username = '******'username']'; //$model->email = '$_POST['email']'; $model->country = $_POST['country']; $model->city = $_POST['city']; $model->street = $_POST['street']; $model->zip_code = $_POST['zip_code']; $model->save(); } $user = User::find()->where(['id' => Yii::$app->user->identity->id])->one(); return $this->render('index', ['user' => $user]); } }
public function notification($event) { $model = User::find()->where(['roles' => 'admin'])->all(); foreach ($model as $r) { Common::sendMail(); } }
/** * 验证用户是否合法 */ public function UseridRight() { $friendUser = User::find()->where("user_id=:user_id", [':user_id' => $this->to_user_id])->one(); if (!$friendUser->province || !$friendUser->city || !$friendUser->address) { $this->addError('logis_name', '请先通知好友完善个人地址信息。'); return false; } $this->logis_country = '中国'; $this->logis_provice = CacheService::getProvinceNameById($friendUser->province); $this->logis_city = CacheService::getCityNameById($friendUser->city); if ($friendUser->area) { $this->logis_area = CacheService::getAreaNameById($friendUser->area); } else { $this->logis_area = '无'; } $this->logis_detailaddress = $friendUser->address; //配置发布用户的地址信息 $publishUser = User::find()->where("user_id=:user_id", [':user_id' => $this->publis_user_id])->one(); if (!$publishUser->province || !$publishUser->city || !$publishUser->address) { $this->addError('logis_name', '您的个人地址信息不完整。'); return false; } $this->user_country = '中国'; $this->user_province = CacheService::getProvinceNameById($publishUser->province); $this->user_city = CacheService::getCityNameById($publishUser->city); if ($publishUser->area) { $this->user_area = CacheService::getAreaNameById($publishUser->area); } else { $this->user_area = '无'; } $this->user_address = $publishUser->address; }
public function up() { $data = (include Yii::getAlias('@common') . '/data/test-adverts.php'); $i = 0; while ($i++ !== 3) { foreach ($data as $one) { $advert = new Advert(); $advert->detachBehavior('timestamp'); $advert->setAttributes($one); $advert->user_id = rand(1, 50); $advert->created_at = time() - 3600 * 24 * rand(1, 31) - 3600 * rand(1, 24) + rand(1, 3600); $advert->updated_at = $advert->created_at; $advert->term_at = $advert->created_at + 3600 * 24 * rand(1, 31); if ($advert->save()) { echo "Advert for user №{$advert->user_id} created\n"; } else { print_r($advert->getErrors()); } } } foreach (User::find()->all() as $user) { $profile = new Profile(); $profile->user_id = $user->id; $profile->name = $user->username; if ($profile->save()) { echo "Profile of \"{$user->username}\" created\n"; } else { print_r($profile->getErrors()); } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::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; } if ($this->created_at_from_date != '') { $this->created_at_from = DDateTimeHelper::DateToUnix($this->created_at_from_date, '00:00:00'); } if ($this->created_at_to_date != '') { $this->created_at_to = DDateTimeHelper::DateToUnix($this->created_at_to_date, '23:59:59'); } //var_dump($this->created_at_to);die; $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'birthday' => $this->birthday, 'deposit' => $this->deposit, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'nickname', $this->nickname])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'first_name', $this->first_name])->andFilterWhere(['like', 'last_name', $this->last_name]); if ($this->created_at_from < $this->created_at_to && $this->created_at_to != 0) { $query->andFilterWhere(['between', 'created_at', $this->created_at_from, $this->created_at_to]); } elseif ($this->created_at_from != 0 && $this->created_at_to == 0) { $query->andFilterWhere(['>=', 'created_at', $this->created_at_from]); } elseif ($this->created_at_from == 0 && $this->created_at_to != 0) { $query->andFilterWhere(['<=', 'created_at', $this->created_at_to]); } return $dataProvider; }
/** * 用户基本信息 * @return type */ public function actionUserinfo() { $model = new UserBaseInfoForm(); $user_id = Yii::$app->user->getId(); $thisUser = User::find()->where("user_id=" . $user_id)->one(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($thisUser->real_status != 1) { $thisUser->setAttribute('realname', $model->realname); $thisUser->setAttribute('card_id', $model->card_id); $thisUser->setAttribute('real_status', 1); } if ($thisUser->phone != $model->phone) { $thisUser->setAttribute('phone', $model->phone); $thisUser->setAttribute('phone_status', 0); } if ($thisUser->email != $model->email) { $thisUser->setAttribute('email', $model->email); $thisUser->setAttribute('email_status', 0); } if ($thisUser->update()) { $this->refresh(); Yii::$app->session->setFlash('success', '更新成功'); $this->redirect('/public/notices.html'); Yii::$app->end(); } return $this->refresh(); } else { $model->setAttributes($thisUser->attributes); return $this->render('userinfo', ['model' => $model]); } }
public function search($params) { $query = User::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['id', 'userIdLink' => ['asc' => ['user.id' => SORT_ASC], 'desc' => ['user.id' => SORT_DESC], 'label' => 'User'], 'userLink' => ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC], 'label' => 'User'], 'profileLink' => ['asc' => ['profile.id' => SORT_ASC], 'desc' => ['profile.id' => SORT_DESC], 'label' => 'Profile'], 'roleName' => ['asc' => ['role.role_name' => SORT_ASC], 'desc' => ['role.role_name' => SORT_DESC], 'label' => 'Role'], 'statusName' => ['asc' => ['status.status_name' => SORT_ASC], 'desc' => ['status.status_name' => SORT_DESC], 'label' => 'Status'], 'userTypeName' => ['asc' => ['user_type.user_type_name' => SORT_ASC], 'desc' => ['user_type.user_type_name' => SORT_DESC], 'label' => 'User Type'], 'created_at' => ['asc' => ['created_at' => SORT_ASC], 'desc' => ['created_at' => SORT_DESC], 'label' => 'Created At'], 'email' => ['asc' => ['email' => SORT_ASC], 'desc' => ['email' => SORT_DESC], 'label' => 'Email']]]); if (!($this->load($params) && $this->validate())) { $query->joinWith(['role'])->joinWith(['status'])->joinWith(['profile'])->joinWith(['userType']); return $dataProvider; } $this->addSearchParameter($query, 'user.id'); $this->addSearchParameter($query, 'username', true); $this->addSearchParameter($query, 'email', true); $this->addSearchParameter($query, 'role_id'); $this->addSearchParameter($query, 'status_id'); $this->addSearchParameter($query, 'user_type_id'); $this->addSearchParameter($query, 'created_at'); $this->addSearchParameter($query, 'updated_at'); $query->joinWith(['role' => function ($q) { $q->where('role.role_name LIKE "%' . $this->roleName . '%"'); }])->joinWith(['status' => function ($q) { $q->where('status.status_name LIKE "%' . $this->statusName . '%"'); }])->joinWith(['userType' => function ($q) { $q->where('user_type.user_type_name LIKE "%' . $this->userTypeName . '%"'); }]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); /** * Setup your sorting attributes * Note: This is setup before the $this->load($params) * statement below */ $dataProvider->setSort(['attributes' => ['id', 'userIdLink' => ['asc' => ['user.id' => SORT_ASC], 'desc' => ['user.id' => SORT_DESC], 'label' => 'User'], 'userLink' => ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC], 'label' => 'User'], 'profileLink' => ['asc' => ['profile.id' => SORT_ASC], 'desc' => ['profile.id' => SORT_DESC], 'label' => 'Profile'], 'roleName' => ['asc' => ['role.role_name' => SORT_ASC], 'desc' => ['role.role_name' => SORT_DESC], 'label' => 'Role'], 'statusName' => ['asc' => ['status.status_name' => SORT_ASC], 'desc' => ['status.status_name' => SORT_DESC], 'label' => 'Status'], 'userTypeName' => ['asc' => ['user_type.user_type_name' => SORT_ASC], 'desc' => ['user_type.user_type_name' => SORT_DESC], 'label' => 'User Type'], 'created_at' => ['asc' => ['created_at' => SORT_ASC], 'desc' => ['created_at' => SORT_DESC], 'label' => 'Created At'], 'email' => ['asc' => ['email' => SORT_ASC], 'desc' => ['email' => SORT_DESC], 'label' => 'Email']]]); if (!($this->load($params) && $this->validate())) { $query->joinWith(['role'])->joinWith(['status'])->joinWith(['profile'])->joinWith(['userType']); return $dataProvider; } $this->addSearchParameter($query, 'id'); $this->addSearchParameter($query, 'username', true); $this->addSearchParameter($query, 'email', true); $this->addSearchParameter($query, 'role_id'); $this->addSearchParameter($query, 'status_id'); $this->addSearchParameter($query, 'user_type_id'); $this->addSearchParameter($query, 'created_at'); $this->addSearchParameter($query, 'updated_at'); // filter by role $query->joinWith(['role' => function ($q) { $q->andFilterWhere(['=', 'role.role_name', $this->roleName]); }])->joinWith(['status' => function ($q) { $q->andFilterWhere(['=', 'status.status_name', $this->statusName]); }])->joinWith(['userType' => function ($q) { $q->andFilterWhere(['=', 'user_type.user_type_name', $this->userTypeName]); }])->joinWith(['profile' => function ($q) { $q->andFilterWhere(['=', 'profile.id', $this->profileId]); }]); return $dataProvider; }
/** * Finds user by id. * * @return User|null User instance */ protected function getUser() { if ($this->_user === null) { $this->_user = User::find()->where(['id' => Yii::$app->user->identity->id])->one(); } return $this->_user; }
/** * Creates a new Uploadedforms model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $username=Yii::$app->user->identity->username; $users = User::find()->all(); $scholars = Scholars::find()->all(); $model = new Uploadedforms(); foreach($users as $user){ foreach($scholars as $scholar){ if($user->username==$username&&$user->id==$scholar->scholar_id){ $model->uploaded_scholar_id=$scholar->scholar_id; if ($model->load(Yii::$app->request->post())) { $fileName = $model->fileName.$model->uploaded_scholar_id; $model->file = UploadedFile::getInstance($model,'file'); if($model->file != null) { $model->file->saveAs('uploads/'.$fileName.'.'.$model->file->extension); $model->uploadedForm = 'uploads/'.$fileName.'.'.$model->file->extension; } $model->save(); return $this->redirect(['index', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, ]); } } } } }
function getTopUsersForInterval($startMonth, $startYear, $endMonth, $endYear, $numUsers = 5) { $topUsers = array(); $allUsers = User::find()->all(); foreach ($allUsers as $user) { $numTweets = getNumTweetsForIntervalByUsername($user->username, $startMonth, $startYear, $endMonth, $endYear); if (count($topUsers) < $numUsers) { $topUsers[] = array('label' => $user->username, 'value' => $numTweets); } else { //Check if we are higher than the lowest user. if ($topUsers[0]['value'] < $numTweets) { //If so, replace this user. $topUsers[0] = array('label' => $user->username, 'value' => $numTweets); } } //Sort our top users array so lower $numTweets come first. $needSort = true; while ($needSort) { $needSort = false; $i = 0; while ($i < count($topUsers) - 1) { if ($topUsers[$i]['value'] > $topUsers[$i + 1]['value']) { $temp = $topUsers[$i]; $topUsers[$i] = $topUsers[$i + 1]; $topUsers[$i + 1] = $temp; $needSort = true; } $i++; } } } return $topUsers; }
public function successCallback($client) { $session = Yii::$app->session; $attributes = $client->getUserAttributes(); $email = User::find()->where(['email' => $attributes['email']])->one(); if ($email) { // email, fbid existed, login success $fbid = User::find()->where(['fbid' => $attributes['id'], 'email' => $attributes['email']])->one(); if ($fbid) { $active = User::find()->where(['fbid' => $attributes['id'], 'email' => $attributes['email'], 'status' => 1])->one(); if ($active) { Yii::$app->user->login($active); } else { // email existed, redirect to login $session->set('active', 'true'); $session->set('email', $attributes['email']); $session->set('fbid', $attributes['id']); $this->successUrl = Yii::$app->urlManager->createAbsoluteUrl(['site/login']); } } else { // email existed, redirect to login $session->set('login', ''); $session->set('email', $attributes['email']); $session->set('fbid', $attributes['id']); $this->successUrl = Yii::$app->urlManager->createAbsoluteUrl(['site/login']); } } else { // email not exist, redirect to register $session->set('login', 'false'); $session->set('email', $attributes['email']); $session->set('fbid', $attributes['id']); $session->set('name', $attributes['name']); $this->successUrl = Yii::$app->urlManager->createAbsoluteUrl(['site/login']); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); /** * Setup your sorting attributes * Note: This is setup before the $this->load($params) * statement below */ $dataProvider->setSort(['attributes' => ['id', 'userIdLink' => ['asc' => ['user.id' => SORT_ASC], 'desc' => ['user.id' => SORT_DESC], 'label' => 'ID'], 'userLink' => ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC], 'label' => 'User'], 'perfilLink' => ['asc' => ['perfil.id' => SORT_ASC], 'desc' => ['perfil.id' => SORT_DESC], 'label' => 'Perfil'], 'rolNombre' => ['asc' => ['rol.rol_name' => SORT_ASC], 'desc' => ['rol.rol_name' => SORT_DESC], 'label' => 'Rol'], 'estadoNombre' => ['asc' => ['estado.estado_nombre' => SORT_ASC], 'desc' => ['estado.estado_nombre' => SORT_DESC], 'label' => 'Estado'], 'created_at' => ['asc' => ['created_at' => SORT_ASC], 'desc' => ['created_at' => SORT_DESC], 'label' => 'Created At'], 'email' => ['asc' => ['email' => SORT_ASC], 'desc' => ['email' => SORT_DESC], 'label' => 'Email']]]); if (!($this->load($params) && $this->validate())) { $query->joinWith(['rol'])->joinWith(['estado'])->joinWith(['perfil']); return $dataProvider; } $this->addSearchParameter($query, 'id'); $this->addSearchParameter($query, 'username', true); $this->addSearchParameter($query, 'email', true); $this->addSearchParameter($query, 'rol_id'); $this->addSearchParameter($query, 'estado_id'); $this->addSearchParameter($query, 'created_at'); $this->addSearchParameter($query, 'updated_at'); // filter by role $query->joinWith(['rol' => function ($q) { $q->andFilterWhere(['=', 'rol.rol_nombre', $this->rolNombre]); }])->joinWith(['estado' => function ($q) { $q->andFilterWhere(['=', 'estado.estado_nombre', $this->estadoNombre]); }])->joinWith(['perfil' => function ($q) { $q->andFilterWhere(['=', 'perfil.id', $this->perfilId]); }]); return $dataProvider; }
/** * Creates a new Participant model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($meeting_id) { $mtg = new Meeting(); $title = $mtg->getMeetingTitle($meeting_id); $model = new Participant(); $model->meeting_id = $meeting_id; $model->invited_by = Yii::$app->user->getId(); // load friends for auto complete field $friends = Friend::getFriendList(Yii::$app->user->getId()); if ($model->load(Yii::$app->request->post())) { if (!User::find()->where(['email' => $model->email])->exists()) { // if email not already registered // create new user with temporary username & password $temp_email_arr[] = $model->email; $model->username = Inflector::slug(implode('-', $temp_email_arr)); $model->password = Yii::$app->security->generateRandomString(12); $model->participant_id = $model->addUser(); } else { // add participant from user record $usr = User::find()->where(['email' => $model->email])->one(); $model->participant_id = $usr->id; } // validate the form against model rules if ($model->validate()) { // all inputs are valid $model->save(); return $this->redirect(['/meeting/view', 'id' => $meeting_id]); } else { // validation failed return $this->render('create', ['model' => $model, 'title' => $title, 'friends' => $friends]); } } else { return $this->render('create', ['model' => $model, 'title' => $title, 'friends' => $friends]); } }
public function notification($event) { $model = User::find()->where(['roles' => 'admin'])->all(); foreach ($model as $r) { Common::sendMail('Notification', 'New subscribe', $r['email']); } }
/** * Updates an existing Grades model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate() { $username = Yii::$app->user->identity->username; $users = User::find()->all(); $grades = Grades::find()->all(); $model = new Grades(); foreach ($users as $user) { foreach ($grades as $grade) { if ($user->username == $username && $user->id == $grade->grade_scholar_id) { $id = $grade->grade_id; $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { $fileName = $model->grade_id . "gradeform"; $model->file = UploadedFile::getInstance($model, 'file'); if ($model->file != null) { $model->file->saveAs('GradeForm/' . $fileName . '.' . $model->file->extension); $model->grade_grade_form = 'GradeForm/' . $fileName . '.' . $model->file->extension; } $model->save(); return $this->redirect(['view', 'id' => $model->grade_id]); return $this->redirect(['view', 'id' => $model->grade_id]); } else { return $this->render('update', ['model' => $model]); } } } } }
/** * Creates a new Parttimejobs model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $username=Yii::$app->user->identity->username; $users = User::find()->all(); $scholars = Scholars::find()->all(); $model = new Parttimejobs(); foreach($users as $user){ foreach($scholars as $scholar){ if($user->username==$username&&$user->id==$scholar->scholar_id){ $model->job_scholar_id=$scholar->scholar_id; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, ]); } } } } }