本文整理汇总了PHP中frontend\models\User类的典型用法代码示例。如果您正苦于以下问题:PHP User类的具体用法?PHP User怎么用?PHP User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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": "john@acme.com",
"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;
}
示例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'];
}
}
示例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]);
}
示例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;
}
示例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;
}
示例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;
}
示例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]);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}