本文整理汇总了PHP中Rights::assign方法的典型用法代码示例。如果您正苦于以下问题:PHP Rights::assign方法的具体用法?PHP Rights::assign怎么用?PHP Rights::assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rights
的用法示例。
在下文中一共展示了Rights::assign方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new User();
$profile = new Profile();
if (isset($_POST['User'])) {
$model->attributes = $_POST['User'];
$model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
$model->createtime = time();
$model->lastvisit = time();
$profile->attributes = $_POST['Profile'];
$profile->user_id = 0;
if ($model->validate() && $profile->validate()) {
$model->password = Yii::app()->controller->module->encrypting($model->password);
if ($model->save()) {
$profile->user_id = $model->id;
$profile->save();
// assign user the 'Authenticated' role for Rights module
$authenticatedName = Rights::module()->authenticatedName;
Rights::assign($authenticatedName, $model->id);
// end of change
}
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model, 'profile' => $profile));
}
示例2: authenticate
/**
* Authenticates a user.
* The example implementation makes sure if the username and password
* are both 'demo'.
* In practical applications, this should be changed to authenticate
* against some persistent user identity storage (e.g. database).
* @return boolean whether authentication succeeds.
*/
public function authenticate()
{
/**
* @var $user XfUser
*/
$user = XfUser::model()->find('LOWER(username)=?', array(strtolower($this->username)));
$xfAuth = new XfAuthentication();
if ($user === null) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
} else {
if (!$xfAuth->checkAuth($this->username, $this->password)) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
$userInfo = $xfAuth->login($this->username, $this->password);
//var_dump($userInfo);die;
if ($userInfo) {
$this->_id = $userInfo['user_id'];
$this->username = $userInfo['username'];
Rights::assign($user['role'], $this->_id);
$this->errorCode = self::ERROR_NONE;
} else {
$this->errorCode = self::ERROR_USERNAME_INVALID;
}
}
}
//unset($xfAuth);
return !$this->errorCode;
}
示例3: actionEdit
/**
* Edit a user.
*/
public function actionEdit($id = 0)
{
if (isset($_POST['User'])) {
$data = $_POST['User'];
if ($id > 0) {
$model = User::model()->findByPk($id);
} else {
$model = new User();
$model->email = $data['email'];
}
$model->name = $data['name'];
$model->publisherid = $data['publisherid'];
$newPassword1 = $_POST['newpassword1'];
$newPassword2 = $_POST['newpassword2'];
// if new password is entered
if ($newPassword1 != '' || $newPassword2 != '') {
if ($newPassword1 != $newPassword2) {
Yii::app()->user->setFlash('errormsg', 'New passwords are not the same');
$this->redirect('/user/edit/id/' . $id);
exit;
} else {
$model->password = $newPassword1;
}
}
// if new email is entered
if ($model->email != $data['email']) {
$emailmodel = User::model()->findAllByAttributes(array(), 'email = :email AND id <> :userId', array(':userId' => $id, ':email' => $data['email']));
if ($emailmodel != null) {
Yii::app()->user->setFlash('errormsg', 'New email already exists');
$this->redirect('/user/edit/id/' . $id);
exit;
} else {
$model->email = $data['email'];
}
}
if ($model->validate() && $model->save()) {
// if a new user, assign the 'Publisher' role for Rights module
if ($id == 0) {
Rights::assign('Publisher', $model->id);
}
Yii::app()->user->setFlash('successmsg', 'The changes have been saved.');
$this->redirect('/user/index');
} else {
Yii::app()->user->setFlash('errormsg', 'Error saving the changes');
$this->render('edit', array('model' => $model));
}
} else {
if ($id > 0) {
$model = User::model()->findByPk($id);
} else {
$model = new User();
}
$this->render('edit', array('model' => $model));
}
}
示例4: actionRegistration
/**
* Registration user
*/
public function actionRegistration()
{
$model = new RegistrationForm();
$profile = new Profile();
$profile->regMode = true;
if (Yii::app()->user->id) {
$this->redirect(Yii::app()->controller->module->profileUrl);
} else {
if (isset($_POST['RegistrationForm'])) {
$model->attributes = $_POST['RegistrationForm'];
$profile->attributes = $_POST['Profile'];
if ($model->validate() && $profile->validate()) {
$soucePassword = $model->password;
$model->activkey = UserModule::encrypting(microtime() . $model->password);
$model->password = UserModule::encrypting($model->password);
$model->verifyPassword = UserModule::encrypting($model->verifyPassword);
$model->createtime = time();
$model->lastvisit = (Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin ? time() : 0;
$model->superuser = 0;
$model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
if ($model->save()) {
$profile->user_id = $model->id;
$profile->save();
// assign user the 'Authenticated' role for Rights module
$authenticatedName = Rights::module()->authenticatedName;
Rights::assign($authenticatedName, $model->id);
// end of change
if (Yii::app()->controller->module->sendActivationMail) {
$activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
UserModule::sendMail($model->email, UserModule::t("You have registered at {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please activate your account. Go to {activation_url}", array('{activation_url}' => $activation_url)));
}
if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) {
$identity = new UserIdentity($model->username, $soucePassword);
$identity->authenticate();
Yii::app()->user->login($identity, 0);
$this->redirect(Yii::app()->controller->module->returnUrl);
} else {
if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
Yii::app()->user->setFlash('registration', UserModule::t("Thank you for registering. Contact Admin to activate your account."));
} elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
Yii::app()->user->setFlash('registration', UserModule::t("Thank you for registering. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl))));
} elseif (Yii::app()->controller->module->loginNotActiv) {
Yii::app()->user->setFlash('registration', UserModule::t("Thank you for registering. Please check your email or login."));
} else {
Yii::app()->user->setFlash('registration', UserModule::t("Thank you for registering. Please check your email."));
}
$this->refresh();
}
}
}
}
$this->render('/user/registration', array('form' => $model, 'profile' => $profile));
}
}
示例5: actionCreate
public function actionCreate()
{
$model = new User();
$this->performAjaxValidation($model, 'user-form');
if (isset($_POST['User'])) {
$model->setAttributes($_POST['User']);
$model->password = $model->hashPassword($model->password, $model->salt);
if ($model->save()) {
Rights::assign($model->tipo, $model->id);
if (Yii::app()->getRequest()->getIsAjaxRequest()) {
Yii::app()->end();
} else {
$this->redirect(array('view', 'id' => $model->id));
}
}
}
$this->render('create', array('model' => $model));
}
示例6: actionUpdate
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
*/
public function actionUpdate()
{
$model = $this->loadModel();
$profile = $model->profile;
$this->performAjaxValidation(array($model, $profile));
/* Get current user role. Added by Phihx. date 14/02/2014*/
$assignedItems = Rights::getAuthorizer()->getAuthItems(null, $model->id);
$userCurrenRole = array_keys($assignedItems);
if (isset($_POST['User'])) {
$model->attributes = $_POST['User'];
$profile->attributes = $_POST['Profile'];
if ($model->validate() && $profile->validate()) {
/*$old_password = User::model()->notsafe()->findByPk($model->id);
if ($old_password->password!=$model->password) {
$model->password=Yii::app()->controller->module->encrypting($model->password);
$model->activkey=Yii::app()->controller->module->encrypting(microtime().$model->password);
}*/
if (!empty($_POST['newPassword'])) {
$model->password = Yii::app()->controller->module->encrypting($_POST['newPassword']);
$model->activkey = Yii::app()->controller->module->encrypting(microtime() . $_POST['newPassword']);
}
$model->save();
$profile->save();
/*remove role for user. added by phihx. date 14/02/2014*/
if (!empty($userCurrenRole)) {
foreach ($userCurrenRole as $role) {
Rights::revoke($role, $model->id);
}
}
/*Add role for user. added by phihx. date 14/02/2014*/
if (!empty($_POST['user_role'])) {
//foreach($_POST['user_role'] as $role){
Rights::assign($_POST['user_role'], $model->id);
//}
}
Yii::app()->user->setFlash('success', translate('Chỉnh sửa người dùng thành công.'));
$this->redirect(PIUrl::createUrl('/user'));
} else {
$profile->validate();
}
}
/* Get All role. Added by Phihx. date 14/02/2014*/
$allRoles = $this->getAllRoleUser();
//$allClass = Classes::model()->findAll();
$arrClass[''] = '---Chọn lớp---';
Yii::app()->theme = 'flatlab';
$this->render('update', array('model' => $model, 'profile' => $profile, 'allRoles' => $allRoles, 'userCurrenRole' => $userCurrenRole));
}
示例7: setRoles
public function setRoles($roles)
{
// $authorizer = Yii::app()->getModule("rights")->getAuthorizer();
if (!is_array($roles)) {
return false;
}
foreach ($this->roles as $role) {
Rights::revoke($role, $this->id);
}
foreach ($roles as $role) {
Rights::assign($role, $this->id);
}
return true;
}
示例8: createUser
/**
* for person create user, assign Customer office role, send Inivation email
* @param int $person_id
* @return boolean
*/
public function createUser($person_id)
{
$m = Person::model();
$model = $m->findByPk($person_id);
//person may be already registred as user
if (!empty($model->user_id)) {
return TRUE;
}
//create user
$password = $this->randomPassword();
$mUser = new User();
$mUser->attributes = array('username' => $model->email, 'password' => UserModule::encrypting($password), 'email' => $model->email, 'superuser' => 0, 'status' => User::STATUS_ACTIVE);
$mUser->activkey = UserModule::encrypting(microtime() . $password);
if (!$mUser->save()) {
return FALSE;
}
//attach user to person
$model->user_id = $mUser->id;
$model->save();
//create user profile
$profile = new Profile();
$profile->user_id = $mUser->id;
$profile->first_name = $model->first_name;
$profile->last_name = $model->last_name;
$profile->save();
unset($profile);
//add Customer office role
Rights::assign(DbrUser::RoleCustomerOffice, $mUser->id);
//send email
Yii::import('vendor.dbrisinajumi.person.components.invitationEmail');
$e = new invitationEmail();
$name = $model->first_name . ' ' . $model->last_name;
$e->sendInvitate($model->email, $password, $model->email, $name);
return true;
}