本文整理汇总了PHP中UserModel::can方法的典型用法代码示例。如果您正苦于以下问题:PHP UserModel::can方法的具体用法?PHP UserModel::can怎么用?PHP UserModel::can使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserModel
的用法示例。
在下文中一共展示了UserModel::can方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _onAfterActivateUser
/**
* Takes over after a user has been activated.
*
* @param UserModel $user
*/
private function _onAfterActivateUser(UserModel $user)
{
// Should we log them in?
$loggedIn = false;
if (craft()->config->get('autoLoginAfterAccountActivation')) {
$loggedIn = craft()->userSession->loginByUserId($user->id, false, true);
}
// Can they access the CP?
if ($user->can('accessCp')) {
$postCpLoginRedirect = craft()->config->get('postCpLoginRedirect');
$url = UrlHelper::getCpUrl($postCpLoginRedirect);
} else {
$activateAccountSuccessPath = craft()->config->getLocalized('activateAccountSuccessPath');
$url = UrlHelper::getSiteUrl($activateAccountSuccessPath);
}
$this->redirect($url);
}
示例2: getPasswordResetUrl
/**
* Sets a new verification code on a user, and returns their new Password Reset URL.
*
* @param UserModel $user The user that should get the new Password Reset URL
*
* @return string The new Password Reset URL.
*/
public function getPasswordResetUrl(UserModel $user)
{
$userRecord = $this->_getUserRecordById($user->id);
$unhashedVerificationCode = $this->_setVerificationCodeOnUserRecord($userRecord);
$userRecord->save();
if ($user->can('accessCp')) {
$url = UrlHelper::getActionUrl('users/setpassword', array('code' => $unhashedVerificationCode, 'id' => $userRecord->uid), craft()->request->isSecureConnection() ? 'https' : 'http');
} else {
// We want to hide the CP trigger if they don't have access to the CP.
$path = craft()->config->get('actionTrigger') . '/users/setpassword';
$url = UrlHelper::getSiteUrl($path, array('code' => $unhashedVerificationCode, 'id' => $userRecord->uid), craft()->request->isSecureConnection() ? 'https' : 'http');
}
return $url;
}
示例3: getPasswordResetUrl
/**
* Sets a new verification code on a user, and returns their new Password Reset URL.
*
* @param UserModel $user The user that should get the new Password Reset URL
*
* @return string The new Password Reset URL.
*/
public function getPasswordResetUrl(UserModel $user)
{
$userRecord = $this->_getUserRecordById($user->id);
$unhashedVerificationCode = $this->_setVerificationCodeOnUserRecord($userRecord);
$userRecord->save();
$path = craft()->config->get('actionTrigger') . '/users/setpassword';
$params = array('code' => $unhashedVerificationCode, 'id' => $userRecord->uid);
$scheme = UrlHelper::getProtocolForTokenizedUrl();
if ($user->can('accessCp')) {
return UrlHelper::getCpUrl($path, $params, $scheme);
} else {
$locale = $user->preferredLocale ?: craft()->i18n->getPrimarySiteLocaleId();
return UrlHelper::getSiteUrl($path, $params, $scheme, $locale);
}
}
示例4: getSetPasswordPath
/**
* Returns a user’s Set Password path with a given activation code and user’s UID.
*
* @param string $code The activation code.
* @param string $uid The user’s UID.
* @param UserModel $user The user.
* @param bool $full Whether a full URL should be returned. Defaults to `false`.
*
* @return string The Set Password path.
*
* @internal This is a little awkward in that the method is called getActivateAccount**Path**, but it's also capable
* of returning a full **URL**. And it requires you pass in both a user’s UID *and* the UserModel - presumably we
* could get away with just the UserModel and get the UID from that.
*
* @todo Create a new getSetPasswordUrl() method (probably elsewhere, such as UrlHelper) which handles
* everything that setting $full to `true` currently does here. The function should not accetp a UID since that's
* already covered by the UserModel. Let this function continue working as a wrapper for getSetPasswordUrl() for the
* time being, with deprecation logs.
*/
public function getSetPasswordPath($code, $uid, $user, $full = false)
{
if ($user->can('accessCp')) {
$url = $this->getCpSetPasswordPath();
if ($full) {
if (craft()->request->isSecureConnection()) {
$url = UrlHelper::getCpUrl($url, array('code' => $code, 'id' => $uid), 'https');
} else {
$url = UrlHelper::getCpUrl($url, array('code' => $code, 'id' => $uid));
}
}
} else {
$url = $this->getLocalized('setPasswordPath');
if ($full) {
if (craft()->request->isSecureConnection()) {
$url = UrlHelper::getUrl($url, array('code' => $code, 'id' => $uid), 'https');
} else {
$url = UrlHelper::getUrl($url, array('code' => $code, 'id' => $uid));
}
}
}
return $url;
}
示例5: getPasswordResetUrl
/**
* Sets a new verification code on a user, and returns their new Password Reset URL.
*
* @param UserModel $user The user that should get the new Password Reset URL
*
* @return string The new Password Reset URL.
*/
public function getPasswordResetUrl(UserModel $user)
{
$userRecord = $this->_getUserRecordById($user->id);
$unhashedVerificationCode = $this->_setVerificationCodeOnUserRecord($userRecord);
$userRecord->save();
$path = craft()->config->get('actionTrigger') . '/users/setpassword';
$params = array('code' => $unhashedVerificationCode, 'id' => $userRecord->uid);
$scheme = craft()->request->isSecureConnection() ? 'https' : 'http';
if ($user->can('accessCp')) {
return UrlHelper::getCpUrl($path, $params, $scheme);
} else {
return UrlHelper::getSiteUrl($path, $params, $scheme);
}
}
示例6: _redirectUserAfterAccountActivation
/**
* Redirect the browser after a user’s account has been activated.
*
* @param UserModel $user The user that was just activated
*
* @return void
*/
private function _redirectUserAfterAccountActivation(UserModel $user)
{
// Can they access the CP?
if ($user->can('accessCp')) {
$postCpLoginRedirect = craft()->config->get('postCpLoginRedirect');
$url = UrlHelper::getCpUrl($postCpLoginRedirect);
} else {
$activateAccountSuccessPath = craft()->config->getLocalized('activateAccountSuccessPath');
$url = UrlHelper::getSiteUrl($activateAccountSuccessPath);
}
$this->redirect($url);
}
示例7: saveBackup
/**
* @codeCoverageIgnore
*
* @param array $settings
* @param string $backup
* @param UserModel $currentUser
*
* @return string Backup filename
*/
protected function saveBackup($settings, $backup, $currentUser)
{
if ($currentUser->can('backup') && $settings['backup'] && IOHelper::fileExists($backup)) {
$destZip = craft()->path->getTempPath() . IOHelper::getFileName($backup, false) . '.zip';
if (IOHelper::fileExists($destZip)) {
IOHelper::deleteFile($destZip, true);
}
IOHelper::createFile($destZip);
if (Zip::add($destZip, $backup, craft()->path->getDbBackupPath())) {
$backup = $destZip;
}
}
return $backup;
}