本文整理匯總了PHP中UserIdentity::fakeAuthenticate方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserIdentity::fakeAuthenticate方法的具體用法?PHP UserIdentity::fakeAuthenticate怎麽用?PHP UserIdentity::fakeAuthenticate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UserIdentity
的用法示例。
在下文中一共展示了UserIdentity::fakeAuthenticate方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: becomeUser
public function becomeUser($username)
{
Yii::import('application.modules_core.user.components.*');
$newIdentity = new UserIdentity($username, '');
$newIdentity->fakeAuthenticate();
Yii::app()->user->setId($newIdentity->getId());
Yii::app()->user->setName($newIdentity->getName());
Yii::app()->user->reload();
}
示例2: actionEdit
/**
* Edits a user
*
* @return type
*/
public function actionEdit()
{
$_POST = Yii::app()->input->stripClean($_POST);
$id = (int) Yii::app()->request->getQuery('id');
$user = User::model()->resetScope()->findByPk($id);
if ($user == null) {
throw new CHttpException(404, Yii::t('AdminModule.controllers_UserController', 'User not found!'));
}
$user->scenario = 'adminEdit';
$user->profile->scenario = 'adminEdit';
$profile = $user->profile;
// Build Form Definition
$definition = array();
$definition['elements'] = array();
$groupModels = Group::model()->findAll(array('order' => 'name'));
// Add User Form
$definition['elements']['User'] = array('type' => 'form', 'title' => 'Account', 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'email' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 100), 'group_id' => array('type' => 'dropdownlist', 'class' => 'form-control', 'items' => CHtml::listData($groupModels, 'id', 'name')), 'super_admin' => array('type' => 'checkbox'), 'status' => array('type' => 'dropdownlist', 'class' => 'form-control', 'items' => array(User::STATUS_ENABLED => Yii::t('AdminModule.controllers_UserController', 'Enabled'), User::STATUS_DISABLED => Yii::t('AdminModule.controllers_UserController', 'Disabled'), User::STATUS_NEED_APPROVAL => Yii::t('AdminModule.controllers_UserController', 'Unapproved')))));
// Add Profile Form
$definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profile->getFormDefinition());
// Get Form Definition
$definition['buttons'] = array('save' => array('type' => 'submit', 'label' => Yii::t('AdminModule.controllers_UserController', 'Save'), 'class' => 'btn btn-primary'), 'become' => array('type' => 'submit', 'label' => Yii::t('AdminModule.controllers_UserController', 'Become this user'), 'class' => 'btn btn-danger'), 'delete' => array('type' => 'submit', 'label' => Yii::t('AdminModule.controllers_UserController', 'Delete'), 'class' => 'btn btn-danger'));
$form = new HForm($definition);
$form['User']->model = $user;
$form['Profile']->model = $profile;
if ($form->submitted('save') && $form->validate()) {
$this->forcePostRequest();
if ($form['User']->model->save()) {
$form['Profile']->model->save();
$this->redirect(Yii::app()->createUrl('admin/user'));
return;
}
}
// This feature is used primary for testing, maybe remove this in future
if ($form->submitted('become')) {
// Switch Identity
Yii::import('application.modules_core.user.components.*');
$newIdentity = new UserIdentity($user->username, '');
$newIdentity->fakeAuthenticate();
Yii::app()->user->login($newIdentity);
$this->redirect(Yii::app()->createUrl('//'));
}
if ($form->submitted('delete')) {
$this->redirect(Yii::app()->createUrl('admin/user/delete', array('id' => $user->id)));
}
$this->render('edit', array('form' => $form));
}
示例3: actionIndex
public function actionIndex()
{
$_POST = Yii::app()->input->stripClean($_POST);
$assetPrefix = Yii::app()->assetManager->publish(dirname(__FILE__) . '/../resources', true, 0, defined('YII_DEBUG'));
Yii::app()->clientScript->registerScriptFile($assetPrefix . '/md5.min.js');
Yii::app()->clientScript->registerScriptFile($assetPrefix . '/jdenticon-1.3.0.min.js');
$needApproval = HSetting::Get('needApproval', 'authentication_internal');
if (!Yii::app()->user->isGuest) {
throw new CHttpException(401, 'Your are already logged in! - Logout first!');
}
// Check for valid user invite
$userInvite = UserInvite::model()->findByAttributes(array('token' => Yii::app()->request->getQuery('token')));
if (!$userInvite) {
throw new CHttpException(404, 'Token not found!');
}
if ($userInvite->language) {
Yii::app()->setLanguage($userInvite->language);
}
$userModel = new User('register');
$userModel->email = $userInvite->email;
$userPasswordModel = new UserPassword('newPassword');
$profileModel = $userModel->profile;
$profileModel->scenario = 'register';
///////////////////////////////////////////////////////
// Generate a random first name
$firstNameOptions = explode("\n", HSetting::GetText('anonAccountsFirstNameOptions'));
$randomFirstName = trim(ucfirst($firstNameOptions[array_rand($firstNameOptions)]));
// Generate a random last name
$lastNameOptions = explode("\n", HSetting::GetText('anonAccountsLastNameOptions'));
$randomLastName = trim(ucfirst($lastNameOptions[array_rand($lastNameOptions)]));
// Pre-set the random first and last name
$profileModel->lastname = $randomLastName;
$profileModel->firstname = $randomFirstName;
// Make the username from the first and lastnames (only first 25 chars)
$userModel->username = substr(str_replace(" ", "_", strtolower($profileModel->firstname . "_" . $profileModel->lastname)), 0, 25);
///////////////////////////////////////////////////////
// Build Form Definition
$definition = array();
$definition['elements'] = array();
$groupModels = Group::model()->findAll(array('order' => 'name'));
$defaultUserGroup = HSetting::Get('defaultUserGroup', 'authentication_internal');
$groupFieldType = "dropdownlist";
if ($defaultUserGroup != "") {
$groupFieldType = "hidden";
} else {
if (count($groupModels) == 1) {
$groupFieldType = "hidden";
$defaultUserGroup = $groupModels[0]->id;
}
}
// Add Identicon Form
$identiconForm = new IdenticonForm();
$definition['elements']['IdenticonForm'] = array('type' => 'form', 'elements' => array('image' => array('type' => 'hidden', 'class' => 'form-control', 'id' => 'image')));
// Add Profile Form
$definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition());
// Add User Form
$definition['elements']['User'] = array('type' => 'form', 'title' => 'Password', 'elements' => array('username' => array('type' => 'hidden', 'class' => 'form-control', 'maxlength' => 25), 'email' => array('type' => 'hidden', 'class' => 'form-control'), 'group_id' => array('type' => $groupFieldType, 'class' => 'form-control', 'items' => CHtml::listData($groupModels, 'id', 'name'), 'value' => $defaultUserGroup)));
// Add User Password Form
$definition['elements']['UserPassword'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255)));
// Get Form Definition
$definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('UserModule.controllers_AuthController', 'Create account')));
$form = new HForm($definition);
$form['User']->model = $userModel;
$form['UserPassword']->model = $userPasswordModel;
$form['Profile']->model = $profileModel;
$form['IdenticonForm']->model = $identiconForm;
/// ----- WE DONT WANT TO SAVE YET -------
if ($form->submitted('save') && $form->validate() && $identiconForm->validate()) {
$this->forcePostRequest();
// Registe User
$form['User']->model->email = $userInvite->email;
$form['User']->model->language = Yii::app()->getLanguage();
if ($form['User']->model->save()) {
// Save User Profile
$form['Profile']->model->user_id = $form['User']->model->id;
$form['Profile']->model->save();
// Save User Password
$form['UserPassword']->model->user_id = $form['User']->model->id;
$form['UserPassword']->model->setPassword($form['UserPassword']->model->newPassword);
$form['UserPassword']->model->save();
// Autologin user
if (!$needApproval) {
$user = $form['User']->model;
$newIdentity = new UserIdentity($user->username, '');
$newIdentity->fakeAuthenticate();
Yii::app()->user->login($newIdentity);
// Prepend Data URI scheme (stripped out for safety)
$identiconForm->image = str_replace("[removed]", "data:image/png;base64,", $identiconForm->image);
// Upload new Profile Picture for user
$this->uploadProfilePicture(Yii::app()->user->guid, $identiconForm->image);
// Redirect to dashboard
$this->redirect(array('//dashboard/dashboard'));
return;
}
$this->render('createAccount_success', array('form' => $form, 'needApproval' => $needApproval));
return;
}
}
$this->render('createAccount', array('form' => $form, 'identiconForm' => $identiconForm, 'needAproval' => $needApproval));
}
示例4: actionCreateAccount
/**
* Create an account
*
* This action is called after e-mail validation.
*/
public function actionCreateAccount()
{
$_POST = Yii::app()->input->stripClean($_POST);
$needApproval = HSetting::Get('needApproval', 'authentication_internal');
if (!Yii::app()->user->isGuest) {
throw new CHttpException(401, 'Your are already logged in! - Logout first!');
}
// Check for valid user invite
$userInvite = UserInvite::model()->findByAttributes(array('token' => Yii::app()->request->getQuery('token')));
if (!$userInvite) {
throw new CHttpException(404, 'Token not found!');
}
$userModel = new User('register');
$userModel->email = $userInvite->email;
$userPasswordModel = new UserPassword('newPassword');
$profileModel = $userModel->profile;
$profileModel->scenario = 'register';
// Build Form Definition
$definition = array();
$definition['elements'] = array();
$groupModels = Group::model()->findAll(array('order' => 'name'));
$defaultUserGroup = HSetting::Get('defaultUserGroup', 'authentication_internal');
$groupFieldType = "dropdownlist";
if ($defaultUserGroup != "") {
$groupFieldType = "hidden";
} else {
if (count($groupModels) == 1) {
$groupFieldType = "hidden";
$defaultUserGroup = $groupModels[0]->id;
}
}
// Add User Form
$definition['elements']['User'] = array('type' => 'form', 'title' => Yii::t('UserModule.controllers_AuthController', 'Account'), 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 32), 'group_id' => array('type' => $groupFieldType, 'class' => 'form-control', 'items' => CHtml::listData($groupModels, 'id', 'name'), 'value' => $defaultUserGroup)));
// Add User Password Form
$definition['elements']['UserPassword'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255)));
// Add Profile Form
$definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition());
// Get Form Definition
$definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('UserModule.controllers_AuthController', 'Create account')));
$form = new HForm($definition);
$form['User']->model = $userModel;
$form['UserPassword']->model = $userPasswordModel;
$form['Profile']->model = $profileModel;
if ($form->submitted('save') && $form->validate()) {
$this->forcePostRequest();
// Registe User
$form['User']->model->email = $userInvite->email;
if ($form['User']->model->save()) {
// Save User Profile
$form['Profile']->model->user_id = $form['User']->model->id;
$form['Profile']->model->save();
// Save User Password
$form['UserPassword']->model->user_id = $form['User']->model->id;
$form['UserPassword']->model->setPassword($form['UserPassword']->model->newPassword);
$form['UserPassword']->model->save();
// Autologin user
if (!$needApproval) {
$user = $form['User']->model;
$newIdentity = new UserIdentity($user->username, '');
$newIdentity->fakeAuthenticate();
Yii::app()->user->login($newIdentity);
$this->redirect(array('//dashboard/dashboard'));
return;
}
$this->render('createAccount_success', array('form' => $form, 'needApproval' => $needApproval));
return;
}
}
$this->render('createAccount', array('form' => $form, 'needAproval' => $needApproval));
}
示例5: actionCreateAccount
/**
* Create an account
*
* This action is called after e-mail validation.
*/
public function actionCreateAccount()
{
$_POST = Yii::app()->input->stripClean($_POST);
$check = UserInvite::model()->findByAttributes(array('token' => Yii::app()->request->getQuery('token')));
if ($check != "") {
$now = new DateTime(date("Y-m-d"));
$diff = 0;
$token = Yii::app()->request->getQuery('token');
$timestamp = strtotime($check->created_at);
$created_at = new DateTime(date("Y-m-d", $timestamp));
$diff = date_diff($created_at, $now);
$diff = (int) $diff->format('%a');
if ($diff > 3) {
$this->redirect(array("//user/auth/timeout", 'token' => $token, 'email' => $check->email));
}
if (Yii::app()->request->getQuery('mail') == "ok" && $check->flag == "R") {
if (!Yii::app()->user->isGuest) {
Yii::app()->user->logout();
}
$verf = Yii::app()->db->createCommand()->delete('user_invite', 'token=:token', array(':token' => Yii::app()->request->getQuery('token')));
$this->redirect(array('//user/auth/vsuccess'));
}
}
$needApproval = HSetting::Get('needApproval', 'authentication_internal');
if (!Yii::app()->user->isGuest) {
throw new CHttpException(401, 'Your are already logged in! - Logout first!');
}
// Check for valid user invite
$userInvite = UserInvite::model()->findByAttributes(array('token' => Yii::app()->request->getQuery('token')));
if (!$userInvite) {
throw new CHttpException(404, 'Token not found!');
}
if ($userInvite->language) {
Yii::app()->setLanguage($userInvite->language);
}
$userModel = new User('register');
$userModel->email = $userInvite->email;
$userPasswordModel = new UserPassword('newPassword');
$profileModel = $userModel->profile;
$profileModel->scenario = 'register';
// Build Form Definition
$definition = array();
$definition['elements'] = array();
$groupModels = Group::model()->findAll(array('order' => 'name DESC'));
$defaultUserGroup = HSetting::Get('defaultUserGroup', 'authentication_internal');
$groupFieldType = "dropdownlist";
if ($defaultUserGroup != "") {
$groupFieldType = "hidden";
} else {
if (count($groupModels) == 1) {
$groupFieldType = "hidden";
$defaultUserGroup = $groupModels[0]->id;
}
}
// Add User Form
$definition['elements']['User'] = array('type' => 'form', 'title' => Yii::t('UserModule.controllers_AuthController', 'Account'), 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'group_id' => array('type' => $groupFieldType, 'class' => 'form-control', 'items' => CHtml::listData($groupModels, 'id', 'name'), 'value' => $defaultUserGroup)));
// Add User Password Form
$definition['elements']['UserPassword'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255)));
// Add Profile Form
$definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition());
// Get Form Definition
$definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('UserModule.controllers_AuthController', 'Create account')));
$form = new HForm($definition);
$form['User']->model = $userModel;
$form['UserPassword']->model = $userPasswordModel;
$form['Profile']->model = $profileModel;
if ($form->submitted('save') && $form->validate()) {
$this->forcePostRequest();
// Registe User
$form['User']->model->email = $userInvite->email;
$form['User']->model->language = Yii::app()->getLanguage();
if ($form['User']->model->save()) {
// Save User Profile
$form['Profile']->model->user_id = $form['User']->model->id;
$form['Profile']->model->save();
// Save User Password
$form['UserPassword']->model->user_id = $form['User']->model->id;
$form['UserPassword']->model->setPassword($form['UserPassword']->model->newPassword);
$form['UserPassword']->model->save();
if (Yii::app()->request->getQuery('mail') == NULL) {
$flag = Yii::app()->db->createCommand()->update('user_invite', array('flag' => 'R'), 'token=:token', array(':token' => Yii::app()->request->getQuery('token')));
} else {
$flag = Yii::app()->db->createCommand()->delete('user_invite', 'token=:token', array(':token' => Yii::app()->request->getQuery('token')));
}
// Autologin user
if (!$needApproval) {
$user = $form['User']->model;
$newIdentity = new UserIdentity($user->username, '');
$newIdentity->fakeAuthenticate();
Yii::app()->user->login($newIdentity);
$this->redirect(array('//user/profile', 'uguid' => Yii::app()->user->guid));
return;
}
$this->render('createAccount_success', array('form' => $form, 'needApproval' => $needApproval));
return;
//.........這裏部分代碼省略.........
示例6: actionAdmin
/**
* Setup Administrative User
*
* This should be the last step, before the user is created also the
* application secret will created.
*/
public function actionAdmin()
{
Yii::import('installer.forms.*');
$userModel = new User('register');
$userPasswordModel = new UserPassword('newPassword');
$profileModel = $userModel->profile;
$profileModel->scenario = 'register';
// Build Form Definition
$definition = array();
$definition['elements'] = array();
// Add User Form
$definition['elements']['User'] = array('type' => 'form', 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'email' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 100)));
// Add User Password Form
$definition['elements']['UserPassword'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255)));
// Add Profile Form
$definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition());
// Get Form Definition
$definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('InstallerModule.base', 'Create Admin Account')));
$form = new HForm($definition);
$form['User']->model = $userModel;
$form['User']->model->group_id = 1;
$form['UserPassword']->model = $userPasswordModel;
$form['Profile']->model = $profileModel;
if (isset($_POST['Profile'])) {
$_POST['Profile'] = Yii::app()->input->stripClean($_POST['Profile']);
}
if (isset($_GET['Profile'])) {
$_GET['Profile'] = Yii::app()->input->stripClean($_GET['Profile']);
}
if ($form->submitted('save') && $form->validate()) {
$this->forcePostRequest();
if (HSetting::Get('secret') == "") {
HSetting::Set('secret', UUID::v4());
}
$form['User']->model->status = User::STATUS_ENABLED;
$form['User']->model->super_admin = true;
$form['User']->model->language = '';
$form['User']->model->last_activity_email = new CDbExpression('NOW()');
$form['User']->model->save();
$form['Profile']->model->user_id = $form['User']->model->id;
$form['Profile']->model->title = "System Administration";
$form['Profile']->model->save();
// Save User Password
$form['UserPassword']->model->user_id = $form['User']->model->id;
$form['UserPassword']->model->setPassword($form['UserPassword']->model->newPassword);
$form['UserPassword']->model->save();
$userId = $form['User']->model->id;
// Switch Identity
Yii::import('application.modules_core.user.components.*');
$newIdentity = new UserIdentity($form['User']->model->username, '');
$newIdentity->fakeAuthenticate();
Yii::app()->user->login($newIdentity);
// Create Welcome Space
$space = new Space();
$space->name = 'Welcome Space';
$space->description = 'Your first sample space to discover the platform.';
$space->join_policy = Space::JOIN_POLICY_FREE;
$space->visibility = Space::VISIBILITY_ALL;
$space->created_by = $userId;
$space->auto_add_new_members = 1;
$space->save();
$profileImage = new ProfileImage($space->guid);
$profileImage->setNew($this->getModule()->getPath() . DIRECTORY_SEPARATOR . "resources" . DIRECTORY_SEPARATOR . 'welcome_space.jpg');
// Add Some Post to the Space
$post = new Post();
$post->message = "Yay! I've just installed HumHub :-)";
$post->content->container = $space;
$post->content->visibility = Content::VISIBILITY_PUBLIC;
$post->save();
$this->redirect($this->createUrl('finished'));
}
$this->render('admin', array('form' => $form));
}