本文整理汇总了PHP中common\models\User::findByUsername方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findByUsername方法的具体用法?PHP User::findByUsername怎么用?PHP User::findByUsername使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\User
的用法示例。
在下文中一共展示了User::findByUsername方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUser
/**
* Finds user by [[username]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
示例2: actionIndex
/**
* 上传头像
* 图片上传成功后做标记,渲染裁剪功能,裁剪后坐标传送给Headcut,Headcut进行裁剪,保存图片,标记。
*/
public function actionIndex()
{
$accessKey = 'l5Y69nZUNTSeeqJx1LqCJP1KuLWIGU_3JVZXLzN-';
$secretKey = '6-4HOEBkNlJpo_TuFrM9W8ZEjytRZAYjuiG0F8Df';
$auth = new Auth($accessKey, $secretKey);
$bucketMgr = new BucketManager($auth);
$bucket = 'colfans-uploads-public';
$key = 'fun.jpg';
list($ret, $err) = $bucketMgr->stat($bucket, $key);
echo "\n====> stat result: \n";
if ($err !== null) {
var_dump($err);
} else {
var_dump($ret);
}
if (!empty($_FILES['headpic'])) {
$user = User::findByUsername(Yii::$app->user->identity->username);
$image = UploadedFile::getInstanceByName('headpic');
$imageName = $user->id . '_' . time() . '.' . $image->getExtension();
if ($image->saveAs('uploads/head/' . $imageName)) {
// file is uploaded successfully
echo 'yes';
die;
} else {
echo 'no';
die;
}
} else {
return $this->render('headupload', ['title' => '个人资料', 'category' => '账号管理', 'subcate' => '个人资料']);
}
}
示例3: actionIndex
/**
* Lists all Posts models.
* @return mixed
*/
public function actionIndex($username)
{
$userid = \common\models\User::findByUsername($username)->id;
$ingredients = Cocktails::getAvaliableIngredients();
$userIngredients = Cocktails::getUserIngredients();
return $this->render('index', ['ingredients' => $ingredients, 'userIngredients' => $userIngredients, 'username' => $username]);
}
开发者ID:vladimirgolovanov,项目名称:purrfect-awesome-friends-feed-decorator,代码行数:11,代码来源:CocktailsController.php
示例4: actionView
public function actionView($username)
{
if (($model = User::findByUsername($username)) === null) {
throw new NotFoundHttpException('The requested page does not exist.');
}
return $this->render('index', ['model' => $model]);
}
示例5: getUser
/**
* Finds user by [[username]]
*
* @return User|null
*/
protected function getUser()
{
if ($this->_user === null) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
示例6: 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'];
}
}
示例7: actionAdduser
/**
* Lists all Opduser models.
* @return mixed
*/
public function actionAdduser()
{
//$request = Yii::$app->request;
//if ($request->isAjax) { /* ตรวจสอบว่าเป็น ajax */ }
//if ($request->isGet) { echo "Is Get"; }
//if ($request->isPost) { echo "Is Post"; }
//if ($request->isPut) { /* ตรวจสอบว่าเป็น PUT */ }
$username = Yii::$app->request->get('username');
$email = Yii::$app->request->get('email');
$password = Yii::$app->request->get('passweb');
//return $username;
if (!User::findByUsername($username)) {
$user = new User();
$user->username = $username;
$user->email = $email;
$user->setPassword($password);
$user->generateAuthKey();
$user->status = User::STATUS_ACTIVE;
if ($user->save()) {
Yii::$app->session->setFlash('success', 'Successes');
$this->redirect(\Yii::$app->urlManager->createUrl("opduser/index"));
//return 'successes';
} else {
Yii::$app->session->setFlash('error', 'failed');
$this->redirect(\Yii::$app->urlManager->createUrl("opduser/index"));
//return 'failed';
}
}
return 'aleadyexists';
}
示例8: getUser
/**
* Finds user by [[username]]
*
* @return User|null
*/
protected function getUser()
{
if ($this->_user === null) {
$this->_user = User::findByUsername($this->nombreDeUsuario);
}
return $this->_user;
}
示例9: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->login = $this->username ?: $this->email;
$user->email = $this->email;
$user->password = $this->password;
$seller = User::findByUsername($this->seller ?: 'ahnames');
if (!$seller->id) {
throw new InvalidParamException('wrong seller given');
}
$user->seller_id = $seller->id;
//$user->setPassword($this->password);
//$user->generateAuthKey();
$user->save();
$user = User::findByUsername($user->login);
if (!$user) {
throw new IntegrityException('failed create user');
}
$contact = Contact::findOne($user->id);
$contact->load([$contact->formName() => $this->getAttributes()]);
$contact->save();
return $user;
}
return null;
}
示例10: actionIndex
public function actionIndex($username)
{
$userid = \common\models\User::findByUsername($username)->id;
$data = Wishlist::getWishlistData($userid);
if ($userid) {
return $this->render('wishlist', ['data' => $data, 'username' => $username]);
}
}
开发者ID:vladimirgolovanov,项目名称:purrfect-awesome-friends-feed-decorator,代码行数:8,代码来源:WishlistController.php
示例11: auth
public function auth($username, $password)
{
$user = User::findByUsername($username);
if ($user && $user->validatePassword($password)) {
return $user;
} else {
return null;
}
}
示例12: getUser
/**
* Finds user by [[username]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
$session = Yii::$app->session;
$session->set('user_id', $this->_user->id);
}
return $this->_user;
}
示例13: safeDown
public function safeDown()
{
$auth = Yii::$app->authManager;
$user = User::findByUsername($this->userLogin);
$auth->revokeAll($user->id);
$user->delete();
$auth->remove($auth->getPermission($this->permissionName));
$auth->remove($auth->getRole($this->roleName));
return true;
}
示例14: validatePassword
/**
* Validates the password.
* This method serves as the inline validation for password.
*
* @param string $attribute the attribute currently being validated
* @param array $params the additional name-value pairs given in the rule
*/
public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) {
$user = User::findByUsername(Yii::$app->user->identity->username);
$this->user = $user;
if (!$user || !$user->validatePassword($this->password)) {
$this->addError($attribute, '现用密码错误');
}
}
}
示例15: login
/**
* 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()) {
$user = User::findByUsername($this->username);
Yii::$app->user->login($user, $this->rememberMe ? 3600 * 24 * 30 : 0);
return true;
} else {
return false;
}
}