本文整理汇总了PHP中BackendUser::hasSuperUser方法的典型用法代码示例。如果您正苦于以下问题:PHP BackendUser::hasSuperUser方法的具体用法?PHP BackendUser::hasSuperUser怎么用?PHP BackendUser::hasSuperUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BackendUser
的用法示例。
在下文中一共展示了BackendUser::hasSuperUser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
function validate($data, $action, $options = array())
{
$data = parent::validate($data, $action, $options);
if (!$data) {
return $data;
}
switch ($action) {
case 'create':
$data['active'] = array_key_exists('active', $data) ? $data['active'] : true;
//We need either an email, mobile number or username to register a user
//Lower ASCII only
if (!empty($data['username'])) {
$data['username'] = filter_var(trim($data['username']), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
//TODO Make the banned usernames configurable
$banned_usernames = array('root', 'admin', 'superadmin', 'superuser', 'webadmin', 'postmaster', 'webdeveloper', 'webmaster', 'administrator', 'sysadmin');
if (in_array($data['username'], $banned_usernames) && BackendUser::hasSuperUser()) {
Backend::addError('Please choose a valid username');
return false;
}
}
if (empty($data['username']) && empty($data['email']) && empty($data['mobile'])) {
Backend::addError('Please provide a username');
}
//If the username is an email address, make it the email address
if (!empty($data['username']) && filter_var($data['username'], FILTER_VALIDATE_EMAIL)) {
if (!empty($data['email'])) {
list($data['username'], $data['email']) = array($data['email'], $data['username']);
} else {
$data['email'] = $data['username'];
unset($data['username']);
}
}
$data['salt'] = get_random('numeric');
$data['password'] = md5($data['salt'] . $data['password'] . Controller::$salt);
if (ConfigValue::get('application.confirmUser')) {
$data['confirmed'] = false;
} else {
$data['confirmed'] = array_key_exists('confirmed', $data) ? $data['confirmed'] : true;
}
break;
case 'update':
if (!empty($data['password'])) {
$data['password'] = md5($this->array['salt'] . $data['password'] . Controller::$salt);
}
break;
}
return $data;
}