本文整理汇总了PHP中AuthUser::Create方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthUser::Create方法的具体用法?PHP AuthUser::Create怎么用?PHP AuthUser::Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AuthUser
的用法示例。
在下文中一共展示了AuthUser::Create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
// 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;
}
}