当前位置: 首页>>代码示例>>PHP>>正文


PHP AuthUser::Create方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:eavesmonkey,项目名称:respond,代码行数:75,代码来源:user.php


注:本文中的AuthUser::Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。