public function testSetGetIdMethods() { $expected = 10; $user = new User(); $user->setId($expected); $this->assertEquals($expected, $user->getId()); }
public function userCreateOrUpdate(User $user) { if (false == env('INTERCOM_ENABLED')) { return false; } $user_data = ['user_id' => $user->getId(), 'email' => $user->email, 'last_request_at' => time(), 'custom_attributes' => ['username' => $user->username, 'first_name' => $user->first_name, 'last_name' => $user->last_name]]; $this->intercom->updateUser($user_data, true); }
protected function userCreateOrUpdate(User $user, $type) { if (false == env('MIXPANEL_ENABLED')) { return false; } $this->mixpanel->setIdentity($user->getId()); $this->mixpanel->setIp($this->getIp()); $this->mixpanel->addTrackEvent($type, ['created_at' => time(), 'username' => $user->username, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'email' => $user->email]); $this->mixpanel->addUserEvent('set', $type, ['$email' => $user->email, '$username' => $user->username, '$first_name' => $user->first_name, '$last_name' => $user->last_name]); }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->name = $this->name; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); $user->save(false); Yii::$app->authManager->assign(Yii::$app->authManager->getRole('user'), $user->getId()); return $user; } return null; }
/** * Signs up the user. * If scenario is set to "rna" (registration needs activation), this means * that user need to activate his account using email confirmation method. * * @return User|null The saved model or null if saving fails. */ public function signup() { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); $user->status = $this->status; // if scenario is "rna" we will generate account activation token if ($this->scenario === 'rna') { $user->generateAccountActivationToken(); } // if user is saved and role is assigned return user object return $user->save() && RbacHelper::assignRole($user->getId()) ? $user : null; }
/** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'view' page. * * @return string|\yii\web\Response */ public function actionCreate() { $user = new User(['scenario' => 'create']); $role = new Role(); if ($user->load(Yii::$app->request->post()) && $role->load(Yii::$app->request->post()) && Model::validateMultiple([$user, $role])) { $user->setPassword($user->password); $user->generateAuthKey(); if ($user->save()) { $role->user_id = $user->getId(); $role->save(); } return $this->redirect('index'); } else { return $this->render('create', ['user' => $user, 'role' => $role]); } }
/** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'view' page. * * @return string|\yii\web\Response */ public function actionCreate() { $user = new User(['scenario' => 'create']); $role = new Role(); if ($user->load(Yii::$app->request->post()) && $role->load(Yii::$app->request->post()) && Model::validateMultiple([$user, $role])) { $user->setPassword($user->password); $user->generateAuthKey(); if ($user->save()) { $role->user_id = $user->getId(); $role->save(); } Yii::$app->session->setFlash('success', implode(' ', [ucfirst($user->username), ' successfully created!'])); return $this->redirect('index'); } else { return $this->render('create', ['user' => $user, 'role' => $role]); } }
/** * 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()) { $auth = Yii::$app->authManager; $authorRole = $auth->getRole('author'); $auth->assign($authorRole, $user->getId()); return $user; } } return null; }
public function reg() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->status = $this->status; $user->setPassword($this->password); $user->generateAuthKey(); if ($this->scenario === 'emailActivation') { $user->generateSecretKey(); } $user->save(); $auth = Yii::$app->authManager; $simpleUser = $auth->getRole('simpleUser'); $auth->assign($simpleUser, $user->getId()); return $user; } }
public function reg() { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); $user->create_at = time(); if ($this->scenario === 'emailActivation') { $user->generateSecretKey(); } if ($user->save()) { $userRole = Yii::$app->authManager->getRole('pay'); Yii::$app->authManager->assign($userRole, $user->getId()); return $user; } else { return null; } }
/** * Finds a throttler by the given Model. * * @param \App\Models\User $user * @param string $ipAddress * * @return \App\Models\Throttle */ public function findByUser($user, $ipAddress = null) { $model = $this->model; $query = $model->query()->where('user_id', '=', $userId = $user->getId()); if ($ipAddress) { $query->where(function ($query) use($ipAddress) { $query->where('ip_address', '=', $ipAddress); $query->orWhere('ip_address', '=', null); }); } if (!($throttle = $query->first())) { $throttle = $this->model; $throttle->user_id = $userId; if ($ipAddress) { $throttle->ip_address = $ipAddress; } $throttle->save(); } return $throttle; }
/** * 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->status = User::STATUS_WAIT; $user->setPassword($this->password); $user->generateAuthKey(); $user->generateEmailConfirmToken(); if ($user->save()) { $auth = Yii::$app->authManager; $role = $auth->getRole('author'); $auth->assign($role, $user->getId()); Yii::$app->session->setFlash('success', 'bilo vislanno pismo dlya pottverjdeniya regi'); Yii::$app->mailer->compose(['html' => 'emailConfirm-html', 'text' => 'emailConfirm-text'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Account confirmation for ' . \Yii::$app->name)->send(); return $user; } } return null; }
public function registrations($link) { $data = time(); $user = new User(); $user->username = $this->username; $user->password = ''; $user->generateAuthKey(); $user->u_snp = $this->name; $user->u_company = $this->company; $user->u_status = 0; $user->u_activation_link = $link; $user->u_time_link = $data; $user->date_post = $data; $user->update_post = $data; $check = $user->save() ? $user : null; // нужно добавить следующие три строки: $auth = Yii::$app->authManager; $authorRole = $auth->getRole('user'); $auth->assign($authorRole, $user->getId()); return $check; // сохраняем нового пользователя, если все ок то тру, елсе фолс }
/** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->user->can('user')) { $model = new User(); $model->generateAuthKey(); $model->create_at = time(); $roles = ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'description'); $user_permit = array_keys(Yii::$app->authManager->getRolesByUser($model->id)); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->authManager->revokeAll($model->getId()); if (Yii::$app->request->post('role')) { foreach (Yii::$app->request->post('role') as $role) { $new_role = Yii::$app->authManager->getRole($role); Yii::$app->authManager->assign($new_role, $model->getId()); } } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'roles' => $roles, 'user_permit' => $user_permit]); } } else { Yii::$app->session->setFlash('error', 'Нет доступа!'); $this->redirect('/'); } }
/** * @param \app\models\User $user * @return array * [ * 'id' => идентификатор пользователя * 'name' => Имя и фамилия * 'avatar' => '/' относительный путь к аватару * ] */ public function getUserData($user) { return ['id' => $user->getId(), 'name' => $user->getField('name_first') . ' ' . $user->getField('name_last'), 'avatar' => $user->getAvatar()]; }
public function one(User $user) { return ['id' => $user->getId(), 'first_name' => $user->getFirstName(), 'last_name' => $user->getLastName(), 'email' => $user->getEmail()]; }
/** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->user->can('userCreate')) { //The permission name //The actions... $model = new User(); $role = new AuthItem(); $model->scenario = 'create'; if ($model->load(Yii::$app->request->post())) { $role->load(Yii::$app->request->post()); $model->accessToken = md5(rand(0, 1000)); $model->score = 0; if ($model->save()) { $auth = Yii::$app->authManager; $newRole = $auth->getRole($role->name); $auth->assign($newRole, $model->getId()); return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', ['model' => $model, 'role' => $role]); } } else { if (Yii::$app->user->isGuest) { Yii::$app->user->loginRequired(); } else { throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.')); } } }
/** * Set status edit feedback * * @param $id * @param $message * @return bool|string */ public static function edit($id, $message) { $userId = User::getId(); if ($userId) { try { $db = Db::getConnection(); $sqlInsert = "UPDATE `feedback` SET `message` = '{$message}', `edit` = '{$userId}' WHERE `id` =" . $id; $preparedStatement = $db->prepare($sqlInsert); $preparedStatement->execute(); return $message; } catch (PDOException $e) { return $e->getMessage(); } } return $error['error'] = self::ERROR_TOKEN_EXCEPTION; }