本文整理汇总了PHP中frontend\models\User类的典型用法代码示例。如果您正苦于以下问题:PHP User类的具体用法?PHP User怎么用?PHP User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
/**
*
* POST /9999999/campaigns/99999/subscribers
Content-Type: application/vnd.api+json
*
* {
"subscribers": [{
"email": "[email protected]",
"utc_offset": 660,
"double_optin": true,
"starting_email_index": 0,
"reactivate_if_removed": true,
"custom_fields": {
"name": "John Doe"
}
}]
}
*/
if ($this->validate()) {
$user = new User();
//$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
$this->subscribe();
\Yii::$app->mailer->compose(['html' => 'signUp-html', 'text' => 'signUp-text'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Sign Up to ' . \Yii::$app->name)->send();
return $user;
}
}
return null;
}
开发者ID:skamnev,项目名称:members,代码行数:39,代码来源:SignupForm.php
示例2: actionAdd
public function actionAdd($password, $discuz_uid, $type = 'User')
{
//TODO 这个之后一定要写进配置文件而非硬编码
if ($password !== 'ngpt_2333') {
Yii::warning("Wrong Password!!!!!!" . $password . "uid : {$discuz_uid}");
return ['result' => 'failed', 'extra' => 'wrong password'];
}
if (is_numeric($discuz_uid) && intval($discuz_uid) <= 0) {
Yii::warning("uid not a number : {$discuz_uid}");
return ['result' => 'failed', 'extra' => 'discuz_uid should be numeric'];
}
$discuz_uid = intval($discuz_uid);
/** @var User $user */
$user = User::findOne(['discuz_user_id' => $discuz_uid]);
if (!empty($user)) {
return ['result' => 'succeed', 'extra' => $user->passkey];
}
$user = new User();
$user->discuz_user_id = $discuz_uid;
$user->passkey = User::genPasskey();
Yii::info($user->attributes);
if ($user->insert()) {
return ['result' => 'succeed', 'extra' => $user->passkey];
} else {
Yii::warning("Insert to user table failed");
return ['result' => 'failed', 'extra' => 'Database error'];
}
}
开发者ID:KKRainbow,项目名称:ngpt_seed,代码行数:28,代码来源:UserController.php
示例3: actionSignIn
public function actionSignIn()
{
$model = new User();
$model->scenario = $model::SCENARIO_SIGN_IN;
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
}
return $this->render('sign-in', ['model' => $model]);
}
开发者ID:Youxiang11,项目名称:product,代码行数:8,代码来源:UserController.php
示例4: 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()) {
try {
if (!Purina::init()->login($this->email, $this->password)) {
$db_user = User::findByEmail($this->email);
if ($db_user) {
$db_user->status = User::STATUS_DISABLED;
$db_user->save();
}
$data = Purina::getData();
if ($data->message) {
$this->addError('password', Yii::t('frontend/base', $data->message));
} else {
$this->addError('password', 'Не верный логин или пароль.');
}
return false;
} else {
$user = Purina::getData();
$db_user = User::findByEmail($this->email);
if (!$db_user) {
$db_user = new User();
$db_user->id = $user->id;
$db_user->firstname = $user->firstname;
$db_user->lastname = $user->lastname;
$db_user->email = $user->email;
$db_user->token = $user->token->key;
$db_user->token_expire = $user->token->expire;
$db_user->created_at = Yii::$app->formatter->asTimestamp($user->register_date);
$db_user->updated_at = $db_user->created_at;
$db_user->setPassword($this->password);
} else {
$db_user->token = $user->token->key;
$db_user->token_expire = $user->token->expire;
}
$db_user->status = User::STATUS_ACTIVE;
if (!$db_user->save()) {
return false;
}
$duration = $user->token->expire - Yii::$app->formatter->asTimestamp('now');
if (!Yii::$app->user->login($db_user, $duration)) {
$this->addError('password', 'Не удалось авторизоваться.');
return false;
} else {
return true;
}
}
} catch (\Exception $e) {
$this->addError('password', 'Не удалось авторизоваться.');
return false;
}
}
return false;
}
开发者ID:an2riy,项目名称:purina,代码行数:59,代码来源:LoginForm.php
示例5: register
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function register()
{
if ($this->validate()) {
$user = new User();
$user->email = $this->email;
$user->password = $this->password;
if ($user->save()) {
return $user;
}
}
return null;
}
开发者ID:brygom,项目名称:yii2-advanced-template-rbac,代码行数:17,代码来源:RegisterForm.php
示例6: createSteamUser
/**
* Create new user based on Steam profile
* @param \frontend\components\SteamAuth $client
* @return \frontend\models\User|boolean
*/
public static function createSteamUser($client)
{
$user = new User(['steamid' => $client->steamId, 'registered' => date('Y-m-d')]);
$steam_data = $client->steamData;
$user->name = $steam_data['response']['players'][0]['personaname'];
$user->avatar = $steam_data['response']['players'][0]['avatarmedium'];
if ($user->save()) {
return $user;
}
Yii::error($user->errors);
return false;
}
开发者ID:stmswitcher,项目名称:d3-santa,代码行数:17,代码来源:User.php
示例7: actionNew
public function actionNew($type)
{
$model = new Razz();
$model->scenario = 'create';
if ($type == 'any') {
$model->type = $model::ANYONE;
}
if ($type == 'some') {
$model->type = $model::SOMEONE;
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if ($model->type == 1 && !$model->fb_friend) {
$this->redirect(['/razz/vote-on-challenges', 't' => 'some']);
}
if ($model->fb_friend) {
$Razz = Yii::$app->request->post('Razz', null);
if ($Razz['fileName'] != "") {
$linkToImg = \common\helpers\Ziggeo::getPreview($Razz['fileName']);
} else {
$linkToImg = $model->preview;
}
$twitter = new \common\helpers\Twitter();
$userModel = new \frontend\models\User();
$userName = ucfirst($userModel->getFullname(Yii::$app->user->id));
$recipientNick = $model->screen_name;
$linkToRazzd = Url::base(true) . "/razz/respond/" . $model->id;
$text = "@{$recipientNick} You have been Razzd by {$userName}: '{$model->title}' {$linkToRazzd}";
$r = $twitter->tweet($text, ['image' => $linkToImg]);
if ($twitter->hasErrors()) {
// Error
} else {
if (isset($r['id'])) {
// Success
}
}
$this->redirect(['/razz/vote-on-challenges', 't' => 'some']);
/*
* Facebook
$client = Yii::$app->authClientCollection->getClient('facebook');
$host = 'http://' . $_SERVER['HTTP_HOST'];
$this->redirect('http://www.facebook.com/dialog/send?app_id=' . $client->clientId . '&to=' . $model->fb_friend . '&link=' . $host . '/razz/respond?hash=' . $model->hash . '&redirect_uri=' . $host . '/razz/vote-on-challenges?t=some');
*/
}
if ($model->type == 2) {
$this->redirect(['/razz/vote-on-challenges', 't' => 'any']);
}
} else {
//print_r($model->getErrors());
//exit();
}
return $this->render('new', ['model' => $model]);
}
开发者ID:babagay,项目名称:razzd,代码行数:52,代码来源:RazzController.php
示例8: 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->username = $this->username;
$user->setPassword($this->password);
$user->create_time = time();
if ($user->save()) {
return $user;
}
}
return null;
}
开发者ID:jia253,项目名称:centosYii2,代码行数:18,代码来源:SignupForm.php
示例9: checkLogin
public function checkLogin()
{
$userInfo = $this->getUserInfo();
if ($userInfo) {
$user = new User();
$user->load($userInfo, '');
$user->saveUserInfo();
if (Yii::$app->user->login($user, 3600 * 24)) {
return true;
}
}
return false;
}
开发者ID:froyot,项目名称:yii-sso-eg,代码行数:13,代码来源:SsoModel.php
示例10: updateProfile
/**
* Signs user up.
* @return User|null the saved model or null if saving fails
*/
public function updateProfile()
{
if ($this->validate()) {
$user = new User();
$user->setScenario('updateProfile');
$user->username = $this->username;
$user->email = $this->email;
$user->updated_at = time();
if ($user->save()) {
return $user;
}
}
return false;
}
开发者ID:MarketPlaceDaniel,项目名称:WangYi,代码行数:18,代码来源:UserUpdateProfileForm.php
示例11: 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->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
return $user;
}
}
return null;
}
开发者ID:sabih3,项目名称:hotpot,代码行数:19,代码来源:SignupForm.php
示例12: getUser
/**
* Finds user by [[username]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
开发者ID:jia253,项目名称:centosYii2,代码行数:12,代码来源:SiteLoginForm.php
示例13: search
/**
* 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;
}
$query->andFilterWhere([
'id' => $this->id,
'status' => $this->status,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'username', $this->username])
->andFilterWhere(['like', 'user_type', $this->user_type])
->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]);
return $dataProvider;
}
开发者ID:seans888,项目名称:SMF-Project,代码行数:39,代码来源:UserSearch.php
示例14: insert_user
private function insert_user($data)
{
$user = new User();
$salt = substr(uniqid(rand()), -6);
$time = time();
$ip = getRealIp();
$password = md5(md5($data['password']) . $salt);
$authkey = Yii::$app->security->generateRandomString();
$password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
$password_hash = Yii::$app->security->generatePasswordHash($data['password']);
$user->username = $data['username'];
$user->password = $password;
$user->auth_key = $authkey;
$user->password_hash = $password_hash;
$user->password_reset_token = $password_reset_token;
$user->mobile = $data['mobile'];
$user->email = $data['email'];
$user->card_id = $data['card_id'];
$user->reg_date = $time;
$user->reg_ip = $ip;
$user->last_login_date = $time;
$user->last_login_ip = $ip;
$user->salt = $salt;
$result = $user->save();
if ($result) {
$session = Yii::$app->session;
if (!$session->isActive) {
$session->open();
}
$session['user'] = ['id' => $result, 'username' => $user->username];
}
return $result;
}
开发者ID:songhongyu,项目名称:datecenter,代码行数:33,代码来源:RegisterController.php
示例15: getUser
/**
* Finds user by [[username]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findOne(Yii::$app->user->identity->id);
}
return $this->_user;
}
开发者ID:CTaiDeng,项目名称:funshop,代码行数:12,代码来源:ChangePasswordForm.php
示例16: getUser
/**
* Finds user by [[username]]
*
* @return User|null
*/
protected function getUser()
{
if ($this->_user === null) {
$this->_user = User::findByEmail($this->email);
}
return $this->_user;
}
开发者ID:skamnev,项目名称:members,代码行数:12,代码来源:LoginForm.php
示例17: getUser
/**
* Finds user by [[username]]
*
* @return User|null
*/
protected function getUser()
{
if ($this->_user === null) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
开发者ID:BoBRoID,项目名称:plochadka,代码行数:12,代码来源:LoginForm.php
示例18: findPasswords
public function findPasswords($attribute, $params)
{
$user = User::findOne(Yii::$app->user->getId());
if (!Yii::$app->getSecurity()->validatePassword($this->oldpass, $user->password_hash)) {
$this->addError($attribute, Yii::t('app/user', 'Old password is incorrect'));
}
}
开发者ID:vilariel,项目名称:remisesramallo,代码行数:7,代码来源:PasswordForm.php
示例19: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->password != $this->password2) {
$this->addError('password2', \Yii::t('site', 'Пароли не совпадают!'));
}
if ($this->validate()) {
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
return $user;
}
}
return null;
}
开发者ID:BoBRoID,项目名称:plochadka,代码行数:22,代码来源:SignupForm.php
示例20: myValidatePassword
/**
* @param $attribute
* @param $params
* @return bool
*/
public function myValidatePassword($attribute, $params)
{
$model = User::find()->where(['username' => $this->username])->andWhere(['status' => 1])->one();
if (!empty($model) && $model->setPassword($this->{$attribute}) == $model->password) {
return true;
}
$this->addError($attribute, 'The username or password is error!');
}
开发者ID:MarketPlaceDaniel,项目名称:WangYi,代码行数:13,代码来源:UserLoginForm.php
注:本文中的frontend\models\User类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论