本文整理汇总了PHP中common\models\User类的典型用法代码示例。如果您正苦于以下问题:PHP User类的具体用法?PHP User怎么用?PHP User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signup
/**
* Регистрация нового пользователя
*
* @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;
$randLength = mt_rand(6, 9);
$this->password = Yii::$app->security->generateRandomString($randLength);
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
//$profile = new Profile();
//$profile->user_id = $user->id;
//$profile->name = $this->name;
////если в куках есть id аффилиата, сохраняем его
//$affiliateId = (int) Yii::$app->request->cookies['affiliate'];
//if ($affiliateId > 0 && User::findIdentity($affiliateId)) {
//$profile->user_affiliate_id = $affiliateId;
//}
//$profile->save();
// Присвоить роль пользователю можно при создании нового пользователя.
// присвоить Роль "user" новому пользователю
// `auth_assignment`
$userRole = Yii::$app->authManager->getRole('user');
Yii::$app->authManager->assign($userRole, $user->getId());
return $this->sendRegistrationEmail();
}
}
return null;
}
示例2: 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->nama = $this->nama;
$user->email = $this->email;
$user->setPassword($this->password);
$user->tanggal_lahir = $this->tanggal_lahir;
$user->fakultas = $this->fakultas;
$user->jurusan = $this->jurusan;
$user->angkatan = $this->angkatan;
$user->pekerjaan = $this->pekerjaan;
$user->alamat_rumah = $this->alamat_rumah;
$user->alamat_domilisi = $this->alamat_domilisi;
$user->no_hp = $this->no_hp;
$user->id_line = $this->id_line;
$user->foto = 'uploads/' . $this->foto;
$user->generateAuthKey();
if ($user->save()) {
return $user;
}
}
return null;
}
示例3: 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();
// Add field for project lifeguard 9/2015
$user->code = $this->code;
$user->referrer = $this->referrer;
$user->first_name = $this->first_name;
$user->last_name = $this->last_name;
$user->sex = $this->sex;
$user->graduate_high_school = $this->graduate_high_school;
$user->city = $this->city;
$user->state = $this->state;
$user->zip = $this->zip;
$user->mobile = $this->mobile;
$user->status = $this->status;
if (!$user->save()) {
throw new ErrorException("Error save information user");
}
return $user;
}
return null;
}
示例4: 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();
$user->status = User::STATUS_NOTACTIVATED;
$b = $user->save();
$activationToken = new UserTokens();
$activationToken->user_id = $user->id;
$activationToken->token_type = ETokenType::ACCOUNT_ACTIVATION;
$activationToken->token = sha1(mt_rand(10000, 99999) . time() . $user->email);
$activationToken->save();
$auth = Yii::$app->authManager;
$userRole = $auth->getRole('user');
$auth->assign($userRole, $user->id);
if ($b) {
$x = new UserInfo();
$x->user_id = $user->id;
$x->save();
EventService::createEvent(EEvent::ACCOUNT_CREATE(), new UserId($user->id));
$this->sendActivationMail($user, $activationToken->token);
return $user;
}
}
return null;
}
示例5: signup
/**
* Signs user up.
*
* @return true|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->phone = $this->phone;
$user->email = $this->email;
$randLength = mt_rand(6, 9);
$this->password = Yii::$app->security->generateRandomString($randLength);
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
$profile = new Profile();
$profile->user_id = $user->id;
$profile->name = $this->name;
//если в куках есть id аффилиата, сохраняем его
$affiliateId = (int) Yii::$app->request->cookies['affiliate'];
if ($affiliateId > 0 && User::findIdentity($affiliateId)) {
$profile->user_affiliate_id = $affiliateId;
}
$profile->save();
return $this->sendRegistrationEmail();
}
}
return null;
}
示例6: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new Admin();
$user->fname = $this->fname;
$user->lname = $this->lname;
$user->contact_no = $this->contact_no;
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->company_name = $this->company_name;
$user->company_description = $this->company_description;
$user->shipping_address = $this->shipping_address;
$user->generateAuthKey();
$user1 = new User();
$user1->fname = $this->fname;
$user1->lname = $this->lname;
$user1->contact_no = $this->contact_no;
$user1->username = $this->username;
$user1->email = $this->email;
$user1->setPassword($this->password);
$user1->company_name = $this->company_name;
$user1->company_description = $this->company_description;
$user1->shipping_address = $this->shipping_address;
$user1->generateAuthKey();
if ($user->save() && $user1->save()) {
return $user;
return $user1;
}
}
return null;
}
示例7: actionLogin
/**
* Logs in a user.
*
* @return mixed
*/
public function actionLogin()
{
/** @var $eauth \nodge\eauth\ServiceBase */
$eauth = Yii::$app->get('eauth')->getIdentity('steam');
$eauth->setRedirectUrl(Yii::$app->getUser()->getReturnUrl());
$eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login'));
try {
if ($eauth->authenticate()) {
$identity = User::findByEAuth($eauth);
$user = User::findOne(['steamid' => $identity->steamid]);
if (!$user) {
$user = new User();
}
$user->username = $identity->username;
$user->steamid = $identity->steamid;
$user->profile_url = $identity->profile_url;
$user->avatar = $identity->avatar;
$user->avatar_md = $identity->avatar_md;
$user->avatar_lg = $identity->avatar_lg;
$user->generateAuthKey();
$user->save();
Yii::$app->getUser()->login($identity);
$eauth->redirect();
} else {
$eauth->cancel();
}
} catch (ErrorException $e) {
Yii::$app->getSession()->setFlash('error', 'EAuthException: ' . $e->getMessage());
$eauth->redirect($eauth->getCancelUrl());
}
}
示例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->company_id = $this->company_id;
$user->first_name = $this->first_name;
$user->last_name = $this->last_name;
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
$permissionList = $_POST['SignupForm']['permissions'];
foreach ($permissionList as $value) {
$newPermissions = new AuthAssignment();
$newPermissions->user_id = $user->id;
$newPermissions->item_name = $value;
$newPermissions->save();
$newPermissions->getErrors();
}
return $user;
}
}
return null;
}
示例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->username = $this->username;
$user->type = $this->type;
$user->first_name = $this->first_name;
$user->last_name = $this->last_name;
$user->full_name = $this->first_name . " " . $this->last_name;
$user->age = $this->age;
$user->gender = $this->gender;
$user->birthdate = $this->birthdate;
$user->address = $this->address;
if ($this->type == 'Student') {
$user->section_id = $this->section_id;
$user->level_id = $this->level_id;
} else {
$user->section_id = '';
$user->level_id = '';
}
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
Yii::$app->session->setFlash('success');
} else {
Yii::$app->session->setFlash('failed');
}
}
return null;
}
示例10: signupCompany
/**
* Signs company up.
*
* @return User|null the saved model or null if saving fails
*/
public function signupCompany()
{
if ($this->validate()) {
$user = new User();
$user->username = $this->name;
$user->email = $this->email;
$user->phone = $this->phone;
$user->setPassword($this->password);
$user->generateAuthKey();
$check_user = $user->save();
$service = new Service();
$service->category_id = $this->category_id;
$service->owner = $user->id;
$service->name = $this->name;
$service->phone = $this->phone;
$service->description = $this->description;
$check_service = $service->save();
if ($check_user && $check_service) {
return $user;
}
VarDumper::dump($service->getErrors(), 6, 1);
die;
}
return null;
}
示例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->gender = $this->gender;
$user->firstname = $this->firstname;
$user->lastname = $this->lastname;
$user->username = $this->email;
$user->email = $this->email;
$user->birthday = $this->birthday;
$user->user_role = $this->user_role;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
if ($user->user_role == 'host') {
$auth = Yii::$app->authManager;
$hostRole = $auth->getRole('host');
$auth->assign($hostRole, $user->id);
} elseif ($user->user_role == 'traveller') {
$auth = Yii::$app->authManager;
$hostRole = $auth->getRole('traveller');
$auth->assign($hostRole, $user->id);
}
return $user;
}
}
return null;
}
示例12: actionCreate
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new User();
$model->scenario = 'create';
$userData = new UserData();
//$hotelMapping = new UserHotelMapping();
if ($model->load(Yii::$app->request->post()) && $userData->load(Yii::$app->request->post())) {
$validUser = $model->validate();
$validUserData = $userData->validate();
//$validHotelMapping = $hotelMapping->validate();
if ($validUser && $validUserData) {
// && $validHotelMapping
$model->setPassword($model->password);
$model->generateAuthKey();
if ($model->save()) {
$userData->user_id = $model->id;
//$hotelMapping->user_id = $model->id;
$userData->save(false);
//$hotelMapping->save(false);
return $this->redirect(['view', 'id' => $model->id]);
}
}
}
return $this->render('create', ['model' => $model, 'userData' => $userData]);
}
示例13: saveProject
private function saveProject($model, $customer)
{
if (empty($model->customer_id)) {
if (!empty($customer->name)) {
// Save the project
$user = new User();
$user->username = $customer->email_address;
$user->email = $user->username;
$user->status = User::STATUS_AWAITING_REQUEST;
$user->save(false);
$customer->user_id = $user->id;
if ($customer->save(false)) {
// We can save the contact
$model->customer_id = $customer->customer_id;
$model->creator_id = Yii::$app->user->id;
return $model->save(false);
} else {
return false;
}
}
} else {
return $model->save(false);
}
return false;
}
示例14: signup
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->last_name = $this->last_name;
$user->first_name = $this->first_name;
$user->middle_name = $this->middle_name;
$user->city_address = $this->city_address;
$user->telephone_no = $this->telephone_no;
$user->email = $this->email;
$user->cellphone_no = $this->cellphone_no;
$user->birth_month = $this->birth_month;
$user->birth_date = $this->birth_date;
$user->birth_year = $this->birth_year;
$user->status = $this->status;
$user->sex = $this->sex;
$user->birth_place = $this->birth_place;
$user->nationality = $this->nationality;
$user->height = $this->height;
$user->weight = $this->weight;
$user->religion = $this->religion;
if ($user->save()) {
return $user;
}
}
return null;
}
示例15: findByEAuth
/**
* @param \nodge\eauth\ServiceBase $service
* @return User
* @throws ErrorException
*/
public static function findByEAuth($service)
{
if (!$service->getIsAuthenticated()) {
throw new ErrorException('EAuth user should be authenticated before creating identity.');
}
$service_id = $service->getServiceName() . '-' . $service->getId();
// find user auth
$user_auth = AuthRecords::find()->where(["id" => $service_id])->one();
if (!isset($user_auth->user_id)) {
$attributes = $service->getAttributes();
$nameFromService = isset($attributes['name']) ? $attributes['name'] : null;
// add user
$model = new User();
$model->username = $nameFromService ? $nameFromService : $service_id;
$model->auth_key = md5($service_id);
$model->password_hash = "asd" . rand(0, 1045693);
// $model->email = "";
$model->save();
$user_id = $model->id;
// add auth
$new_auth = new AuthRecords();
$new_auth->id = $service_id;
$new_auth->user_id = $user_id;
$new_auth->attributes = serialize($service->getAttributes());
$new_auth->save();
} else {
$user_id = $user_auth->user_id;
}
return user::findIdentity($user_id);
}