本文整理汇总了PHP中common\models\User::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findOne方法的具体用法?PHP User::findOne怎么用?PHP User::findOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\User
的用法示例。
在下文中一共展示了User::findOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new Message model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @param $receiver : to some body send a msg
* @return mixed
* @throws BadRequestHttpException
*/
public function actionCreate($receiver)
{
$this->layout = '//i';
if ($receiver == Yii::$app->user->id) {
throw new BadRequestHttpException('给自己发消息有意思不', 403);
}
$receiverUser = User::findOne($receiver);
$model = new Message();
$model->receiver = $receiver;
$model->sender = Yii::$app->user->id;
$model->user_id = $receiver;
$model->friend_id = Yii::$app->user->id;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$msg = new Message();
$msg->receiver = $receiver;
$msg->sender = Yii::$app->user->id;
$msg->user_id = $model->sender;
$msg->friend_id = $model->receiver;
$msg->content = $model->content;
$msg->save(false);
return $this->redirect(['index']);
} else {
var_dump($model->errors);
return $this->render('create', ['model' => $model, 'receiverUser' => $receiverUser]);
}
}
示例2: actionLogin
public function actionLogin()
{
$result = false;
$token = '';
$accessToken = Yii::$app->request->get('access_token');
if ($accessToken) {
if (User::findOne(['access_token' => $accessToken])) {
$result = true;
}
} elseif (Yii::$app->request->post('username') && Yii::$app->request->post('password')) {
$user = User::findByUsername(Yii::$app->request->post('username'));
if ($user && $user->validatePassword(Yii::$app->request->post('password'))) {
if ($user->access_token) {
$token = $user->access_token;
} else {
$token = hash('sha256', Yii::$app->request->get('username'));
Yii::$app->db->createCommand()->update("user", ['access_token' => $token], 'id = ' . $user->id)->execute();
}
$result = true;
}
}
if ($result) {
return ['result' => 'success', 'access_token' => $token];
} else {
return ['result' => 'failed'];
}
}
示例3: create
public function create()
{
$isValid = false;
$this->imageFile = UploadedFile::getInstance($this, 'imageFile');
$user = User::findOne(Yii::$app->user->getId());
$bulletin = new Bulletin();
if (isset($this->imageFile)) {
$imagePath = '/uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension;
$this->imageFile->saveAs(Yii::getAlias('@webroot') . $imagePath);
$m_image = new Image();
$m_image->url = $imagePath;
if ($m_image->save()) {
$image = Image::findOne($m_image->getPrimaryKey());
$bulletin->link('image', $image);
$bulletin->link('user', $user);
$isValid = true;
} else {
$isValid = false;
}
}
$bulletin->title = $this->title;
$bulletin->description = $this->description;
if ($bulletin->save()) {
$isValid = true;
} else {
$isValid = false;
}
return $isValid;
}
示例4: isAdminSelfEdit
private function isAdminSelfEdit()
{
if (!Yii::$app->user->isGuest) {
return $this->username === User::findOne(Yii::$app->user->id)->username;
}
return false;
}
示例5: actionComment
public function actionComment()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
$data = Yii::$app->request->post();
$user = User::findOne(Yii::$app->user->getId());
$whom = User::findOne($data['whom_id']);
$rate = $whom->profile->rate;
if ($rate == 0) {
$whom->profile->rate = (double) $data['rate'];
} else {
$whom->profile->rate = ($rate + (double) $data['rate']) / 2;
}
$whom->profile->save();
$comment = new Comment();
$comment->rate = $data['rate'];
$comment->description = $data['comment'];
$comment->whom_id = $data['whom_id'];
$comment->link('owner', $user);
if ($comment->save()) {
return array('success' => true);
}
return array('success' => false);
}
}
示例6: actionCreateuser
public function actionCreateuser()
{
$userModel = User::findOne(['user_name' => yii::$app->request->post('user_name')]);
if ($userModel === null) {
$userModel = new User();
$userModel->load(yii::$app->request->post());
if ($userModel->save()) {
yii::$app->AjaxResponse->error = false;
yii::$app->AjaxResponse->message = ['User has been created'];
yii::$app->UserComponent->sendWelcomeEmail($userModel->first_name, $userModel->email);
} else {
yii::$app->AjaxResponse->message = array_values($userModel->getErrors());
}
} else {
// user exits but is not active
if ($userModel->status_id != Types::$status['active']['id']) {
$userModel->status_id = Types::$status['active']['id'];
$userModel->save();
yii::$app->AjaxResponse->error = false;
yii::$app->AjaxResponse->message = ['User reactivated'];
} else {
yii::$app->AjaxResponse->message = ['User already exists'];
}
}
yii::$app->AjaxResponse->sendContent();
}
示例7: getUser
/**
* Finds user by [[email]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findOne(['email' => $this->email]);
}
return $this->_user;
}
示例8: finishReg
public function finishReg($id)
{
/* @var $modelUser \common\models\User */
/* @var $modelPlaceCountry \common\models\PlaceCountry */
$modelUser = User::findOne($id);
if ($this->scenario === 'phoneFinish') {
$modelUser->phone = $this->getPhoneNumber();
$modelUser->status = User::STATUS_ACTIVE;
$modelUser->country_id = $this->country_id;
$modelUser->setPassword(time());
$modelUser->generateAuthKey();
$modelUser->save();
return RbacHelper::assignRole($modelUser->getId()) ? $modelUser : null;
} elseif ($this->scenario === 'phoneAndEmailFinish') {
$modelUser->phone = $this->getPhoneNumber();
$modelUser->email = $this->email;
$modelUser->country_id = $this->country_id;
$modelUser->setPassword($this->password);
$modelUser->generateAuthKey();
$modelUser->generateSecretKey();
$modelUser->validate();
$modelUser->save();
return RbacHelper::assignRole($modelUser->getId()) ? $modelUser : null;
}
return false;
}
示例9: actionIndex
/**
* Lists all Acts models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new ActsSearch();
$usr = User::findOne(Yii::$app->user->id);
$dataProvider = $searchModel->search(Yii::$app->request->queryParams, $usr->_1c_id);
return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
}
示例10: findOne
/**
* @param $id
* @return $this
*/
public function findOne($id)
{
$user = User::findOne($id);
$this->username = $user->username;
$this->email = $user->email;
return $this;
}
示例11: execute
public function execute($user, $item, $params)
{
//Получаем массив пользователя из базы
$cacheUser = 'User_role:' . Yii::$app->user->id;
if (false === ($_user = Yii::$app->cache->get($cacheUser))) {
if (null === ($_user = User::findOne($user))) {
return FALSE;
//throw new NotFoundHttpException;
}
Yii::$app->cache->set($cacheUser, $_user, 86400);
}
$user = ArrayHelper::getValue($params, 'user', $_user);
if ($user) {
$role = $user->role;
//Значение из поля role базы данных
if ($item->name === 'admin') {
return $role == User::ROLE_ADMIN;
} elseif ($item->name === 'moder') {
//moder является потомком admin, который получает его права
return $role == User::ROLE_ADMIN || $role == User::ROLE_MODER;
} elseif ($item->name === 'user') {
return $role == User::ROLE_ADMIN || $role == User::ROLE_MODER || $role == User::ROLE_USER;
}
}
return false;
}
示例12: getUser
/**
* @return null|User
*/
protected function getUser()
{
if ($this->_user === null) {
$this->_user = User::findOne($this->user_id);
}
return $this->_user;
}
示例13: actionCreateEvent
public function actionCreateEvent()
{
$model = new EventCreateForm();
$model->own_id = \Yii::$app->user->getId();
$model->create_at = date('Y-m-d h:i');
if ($model->load(\Yii::$app->request->post())) {
if (!$model->validate()) {
return $this->render('error');
}
if (sizeof($model->friend) > 0) {
$title = $model->title . ' (Member: ' . User::findOne(['id' => \Yii::$app->user->getId()])->username;
foreach ($model->friend as $userId) {
$title = $title . ', ' . User::findOne(['id' => $userId])->username;
}
$title = $title . ')';
} else {
$title = $model->title;
}
$eventId = $model->addEvent($title);
if (sizeof($model->friend) > 0) {
foreach ($model->friend as $userId) {
$scheduleNotify = new ScheduleNotification();
$scheduleNotify['schedule_id'] = $eventId;
$scheduleNotify['receiver_id'] = $userId;
$scheduleNotify['action_id'] = \Yii::$app->user->getId();
$scheduleNotify['create_at'] = $model->create_at;
$scheduleNotify->save();
}
}
$this->refresh();
}
return $this->render('show', ['model' => $model]);
}
示例14: actionIndex
public function actionIndex()
{
$user = \Yii::$app->user->identity;
$parent = null;
$child = null;
if (!\Yii::$app->user->can('admin')) {
$user->parent_id ? $parent = \common\models\User::findOne(['id' => $user->parent_id]) : '';
$child = new \yii\data\ActiveDataProvider(['query' => \common\models\User::find()->where(['parent_id' => $user->id])]);
} else {
$userList = \common\models\User::find()->where(['parent_id' => null])->orderBy('id')->all();
$tree = [];
foreach ($userList as $key => $item) {
$tree[] = $item;
$branch = $this->makeTree($item->id, 0, array());
$tree = array_merge($tree, $branch);
}
$userList = $tree;
// print_r('<pre>');
// print_r($userList);
// print_r('</pre>');
// die();
}
$crypt = openssl_encrypt($user->email, 'aes-128-ecb', '304c6528f659c77866a510d9c1d6ae5e', false);
return $this->render('index', ['parent' => $parent, 'child' => $child, 'crypt' => $crypt, 'userList' => $userList]);
}
示例15: addRate
/**
* добавляет в базу новую ставку
* @param Model $fantasy
*/
public function addRate($fantasy)
{
$draftModel = new PokerDraft();
$PokerDraftPlayer = new PokerDraftPlayer();
$draftModel->attributes = $this->attributes;
$draftModel->save();
//echo'<pre>'; print_r($draftModel);echo'</pre>';die;
$PokerDraftPlayer->addPlayersRows($this->players, $draftModel->id);
//снимаем взнос+комиссия у игрока
$user = User::findOne(Yii::$app->user->id);
$deposit_before = $user->deposit;
$user->deposit = $user->deposit - $fantasy->deposit - $fantasy->fee;
if ($user->save()) {
//заносим в лог
$data = ['fantasy_id' => $fantasy->id, 'game' => Transaction::TR_GAME_POKER];
$trans_descr = Transaction::buildTransactionDescrForSave(Transaction::TR_TYPE_FANTASY_PAYMENT, $data);
Transaction::saveTransaction($user->id, $deposit_before, -($fantasy->deposit + $fantasy->fee), $trans_descr);
}
//если нужно - увеличиваем призовой фонд
//$total_sum_rates = PokerDraft::getCountFantasyDrafts($fantasy->id) * $fantasy->deposit;
$total_sum_rates = $draftModel->getCountFantasyDrafts($fantasy->id) * $fantasy->deposit;
if ($total_sum_rates > $fantasy->prize_pool_real) {
PokerFantasy::upateRealPrizePool($fantasy->id, $total_sum_rates);
}
}