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


PHP Profile::findFirst方法代码示例

本文整理汇总了PHP中app\models\Profile::findFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP Profile::findFirst方法的具体用法?PHP Profile::findFirst怎么用?PHP Profile::findFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Profile的用法示例。


在下文中一共展示了Profile::findFirst方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: facebookCallback

 public function facebookCallback()
 {
     try {
         $state = $this->security->getToken();
         $code = $this->request->getQuery('code');
         $error = $this->request->getQuery('error');
         $callback = $this->request->getQuery('callback');
         if (!empty($error)) {
             if ($error === 'access_denied') {
                 throw new FbCallbackException('FB authorization error: ' . $error);
             } else {
                 throw new FbCallbackException('FB authorization error: ' . $error);
             }
         }
         if (empty($code)) {
             throw new FbCallbackException('Ups, something went wrong during authorization');
         }
         $facebook_response = $this->facebook->getAccessToken($code, $state, $callback);
         $access_token = $facebook_response->access_token;
         $uid = $this->facebook->getUid($access_token);
         $profile = Profile::findFirst(['uid = ?0', 'bind' => [$uid]]);
         if (empty($profile)) {
             // No user, let's register it
             // TODO: encrypt access_token
             // TODO: Change default facebook avatar by ours
             // TODO: if user doesn't provide us with email we can't register it
             // TODO: facebook date format can vary
             $me = $this->facebook->me($access_token);
             // Create user
             $user = new User();
             $user = $user->assignFromFacebook($me);
             if ($user->save()) {
                 // Create profile and assign to the user
                 $profile = new Profile();
                 $profile->createFromFacebook($me->id, $access_token, $user->id);
                 return new Response(json_encode($user));
             } else {
                 throw new InvalidFbUser($user);
             }
         } else {
             // User already registered, update access_token
             $profile->save(['access_token' => $access_token]);
             $user = $profile->getUser();
             return new Response(json_encode($user->toArray()));
         }
     } catch (FbCallbackException $e) {
         return $e->returnResponse();
     } catch (InvalidFbUser $e) {
         return $e->returnResponse();
     } catch (\Exception $e) {
         return new Response($e->getMessage(), 409);
     }
 }
开发者ID:soutoner,项目名称:api-desconecta,代码行数:53,代码来源:RegisterController.php

示例2: userIdProviderIdMustBeUnique

 public function userIdProviderIdMustBeUnique(FunctionalTester $I)
 {
     $this->model->user_id = Profile::findFirst()->user_id;
     $this->model->provider_id = Profile::findFirst()->provider_id;
     $I->assertFalse($this->model->save());
 }
开发者ID:soutoner,项目名称:api-desconecta,代码行数:6,代码来源:ProfileCest.php


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