作者:skamne
项目:member
/**
* 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;
}
作者:KKRainbo
项目:ngpt_see
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'];
}
}
作者:Youxiang1
项目:produc
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]);
}
作者:an2ri
项目:purin
/**
* 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;
}
作者:brygo
项目:yii2-advanced-template-rba
/**
* 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;
}
作者:stmswitche
项目:d3-sant
/**
* 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;
}
作者:babaga
项目:razz
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]);
}
作者:jia25
项目:centosYii
/**
* 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;
}
作者:froyo
项目:yii-sso-e
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;
}
作者:MarketPlaceDanie
项目:WangY
/**
* 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;
}
作者:sabih
项目:hotpo
/**
* 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;
}
作者:jia25
项目:centosYii
/**
* Finds user by [[username]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
作者:seans88
项目:SMF-Projec
/**
* 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;
}
作者:songhongy
项目:datecente
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;
}
作者:CTaiDen
项目:funsho
/**
* 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;
}
作者:skamne
项目:member
/**
* Finds user by [[username]]
*
* @return User|null
*/
protected function getUser()
{
if ($this->_user === null) {
$this->_user = User::findByEmail($this->email);
}
return $this->_user;
}
作者:BoBRoI
项目:plochadk
/**
* Finds user by [[username]]
*
* @return User|null
*/
protected function getUser()
{
if ($this->_user === null) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
作者:vilarie
项目:remisesramall
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'));
}
}
作者:BoBRoI
项目:plochadk
/**
* 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;
}
作者:MarketPlaceDanie
项目:WangY
/**
* @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!');
}