本文整理汇总了PHP中Role::GetByName方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::GetByName方法的具体用法?PHP Role::GetByName怎么用?PHP Role::GetByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Role
的用法示例。
在下文中一共展示了Role::GetByName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
/**
* @method POST
*/
function login()
{
// parse request
parse_str($this->request->data, $request);
$email = $request['email'];
$password = $request['password'];
// get the user from the credentials
$user = User::GetByEmailPassword($email, $password);
if ($user != null) {
try {
// if $site is null, login to the app, else login to the site
$site = Site::GetBySiteUniqId(SITE_UNIQ_ID);
// default canView
$canView = '';
// try to get a role by its name
$role = Role::GetByName($user['Role'], $user['SiteId']);
// set canView permission
if ($role != null) {
$canView = trim($role['CanView']);
}
if ($site['SiteId'] == $user['SiteId']) {
SiteAuthUser::Create(SITE_FRIENDLY_ID, $user, $canView);
$params = array();
} else {
// invalid login
$response = new Tonic\Response(Tonic\Response::BADREQUEST);
$response->body = 'Site mismatch';
return $response;
}
// return a json response
$response = new Tonic\Response(Tonic\Response::OK);
$response->contentType = 'text/html';
$response->body = 'success!';
} catch (Exception $e) {
$response = new Tonic\Response(Tonic\Response::BADREQUEST);
$response->body = $e->getMessage();
return $response;
}
return $response;
} else {
// return an unauthorized exception (401)
$response = new Tonic\Response(Tonic\Response::UNAUTHORIZED);
$response->body = 'Access denied';
return $response;
}
}
示例2: SetAccess
public static function SetAccess($user)
{
if ($user['Role'] == 'Admin') {
$is_auth = true;
$canEdit = 'All';
$canPublish = 'All';
$canRemove = 'All';
$canCreate = 'All';
} else {
if ($user['Role'] == 'Contributor') {
$is_auth = true;
$canEdit = 'All';
$canPublish = '';
$canRemove = '';
$canCreate = '';
} else {
if ($user['Role'] == 'Member') {
$is_auth = false;
} else {
// try to get a role by its name
$role = Role::GetByName($user['Role'], $user['SiteId']);
if ($role != null) {
$canEdit = trim($role['CanEdit']);
$canPublish = trim($role['CanPublish']);
$canRemove = trim($role['CanRemove']);
$canCreate = trim($role['CanCreate']);
if ($canEdit != '' && $canPublish != '' && $canRemove != '') {
$is_auth = true;
}
} else {
$is_auth = false;
}
}
}
}
// set can access
if ($canEdit == 'All' || $canPublish == 'All' || $canRemove == 'All' || $canCreate == 'All') {
$canAccess = 'All';
} else {
$canAccess = $canEdit . ',' . $canPublish . ',' . $canRemove . ',' . $canCreate;
}
return array('CanEdit' => $canEdit, 'CanPublish' => $canPublish, 'CanRemove' => $canRemove, 'CanCreate' => $canCreate, 'CanAccess' => $canAccess);
}
示例3: login
/**
* @method POST
*/
function login()
{
// parse request
parse_str($this->request->data, $request);
$email = $request['email'];
$password = $request['password'];
// get site
$site = null;
$first_login = false;
if (isset($request['friendlyId'])) {
$friendlyId = $request['friendlyId'];
// get site by its friendly id
$site = Site::GetByFriendlyId($friendlyId);
} else {
if (isset($request['siteId'])) {
$siteId = $request['siteId'];
// get site by its friendly id
$site = Site::GetBySiteId($siteId);
} else {
// return an unauthorized exception (401)
$response = new Tonic\Response(Tonic\Response::UNAUTHORIZED);
$response->body = 'Access denied';
return $response;
}
}
// set first_login if the last login is null
if ($site['LastLogin'] == NULL) {
$first_login = true;
}
// get the user from the credentials
$user = User::GetByEmailPassword($email, $site['SiteId'], $password);
// determine if the user is authorized
$is_auth = false;
// permissions
$canEdit = '';
$canPublish = '';
$canRemove = '';
$canCreate = '';
$canView = '';
if ($user != null) {
if ($user['Role'] == 'Admin') {
$is_auth = true;
$canEdit = 'All';
$canPublish = 'All';
$canRemove = 'All';
$canCreate = 'All';
$canView = 'All';
} else {
if ($user['Role'] == 'Contributor') {
$is_auth = true;
$canEdit = 'All';
$canPublish = '';
$canRemove = '';
$canCreate = '';
$canView = 'All';
} else {
if ($user['Role'] == 'Member') {
$is_auth = true;
$canEdit = '';
$canPublish = '';
$canRemove = '';
$canCreate = '';
$canView = 'All';
} else {
// try to get a role by its name
$role = Role::GetByName($user['Role'], $user['SiteId']);
if ($role != null) {
$canEdit = trim($role['CanEdit']);
$canPublish = trim($role['CanPublish']);
$canRemove = trim($role['CanRemove']);
$canCreate = trim($role['CanCreate']);
$canView = trim($role['CanView']);
} else {
$is_auth = false;
}
}
}
}
} else {
// return an unauthorized exception (401)
$response = new Tonic\Response(Tonic\Response::UNAUTHORIZED);
$response->body = 'Access denied';
return $response;
}
// login if authorized
if ($is_auth = true) {
try {
$fullPhotoUrl = '';
// set photo url
if ($user['PhotoUrl'] != '' && $user['PhotoUrl'] != NULL) {
// build the full URL for the photo
$site = Site::GetBySiteId($user['SiteId']);
// set images URL
if (FILES_ON_S3 == true) {
$bucket = $site['Bucket'];
$imagesURL = str_replace('{{bucket}}', $bucket, S3_URL);
$imagesURL = str_replace('{{site}}', $site['FriendlyId'], $imagesURL);
//.........这里部分代码省略.........
示例4: login
/**
* @method POST
*/
function login()
{
// parse request
parse_str($this->request->data, $request);
$email = $request['email'];
$password = $request['password'];
// get the user from the credentials
$user = User::GetByEmailPassword($email, $password);
// determine if the user is authorized
$is_auth = false;
// permissions
$canEdit = '';
$canPublish = '';
$canRemove = '';
$canCreate = '';
if ($user != null) {
if ($user['Role'] == 'Admin') {
$is_auth = true;
$canEdit = 'All';
$canPublish = 'All';
$canRemove = 'All';
$canCreate = 'All';
} else {
if ($user['Role'] == 'Contributor') {
$is_auth = true;
$canEdit = 'All';
$canPublish = '';
$canRemove = '';
$canCreate = '';
} else {
if ($user['Role'] == 'Member') {
$is_auth = false;
} else {
// try to get a role by its name
$role = Role::GetByName($user['Role'], $user['SiteId']);
if ($role != null) {
$canEdit = trim($role['CanEdit']);
$canPublish = trim($role['CanPublish']);
$canRemove = trim($role['CanRemove']);
$canCreate = trim($role['CanCreate']);
if ($canEdit != '' && $canPublish != '' && $canRemove != '') {
$is_auth = true;
}
} else {
$is_auth = false;
}
}
}
}
}
// login if authorized
if ($is_auth = true) {
try {
AuthUser::Create($user, $canEdit, $canPublish, $canRemove, $canCreate);
$params = array('start' => START_PAGE);
// return a json response
$response = new Tonic\Response(Tonic\Response::OK);
$response->contentType = 'application/json';
$response->body = json_encode($params);
} catch (Exception $e) {
$response = new Tonic\Response(Tonic\Response::BADREQUEST);
$response->body = $e->getMessage();
return $response;
}
return $response;
} else {
// return an unauthorized exception (401)
$response = new Tonic\Response(Tonic\Response::UNAUTHORIZED);
$response->body = 'Access denied';
return $response;
}
}