registerAndActivate() public méthode

Registers and activates the user.
public registerAndActivate ( array $credentials ) : Cartalyst\Sentinel\Users\UserInteface | boolean
$credentials array
Résultat Cartalyst\Sentinel\Users\UserInteface | boolean
 public function postRegister(CredentialsRequest $request)
 {
     if ($user = $this->sentinel->registerAndActivate($this->getRequestData($request))) {
         $this->sentinel->loginAndRemember($user);
         $this->setResponseData($user->toArray());
     } else {
         $this->setErrorData("Can't create user");
     }
     return $this->responseJson();
 }
 /**
  * @return mixed
  */
 public function postLogin()
 {
     /*
      * Login Facebook
      * Người dùng login bằng javascriptSDK sau đó sẽ gửi short token-key lên server.
      * Server sẽ dùng short token-key này để lấy long-lived token-key
      * Tiếp tục dùng long-lived token key để lấy thông tin của người dùng: id-facebook + email + name....
      * Kiểm tra người dùng trên hệ thống. Lưu ý đây là người dùng facebook. Sẽ link sang user-sentinel bằng user_id.
      * Nếu người dùng chưa tồn tại trên hệ thống thì sẽ tạo 1 user mới để đăng nhập. User này do sentinel quản lý. Email/pass word do mình tự generate ra.
      * Nếu người dùng tồn tại trên hệ thống rồi => lấy user-sentinel => login-sentinel
      */
     try {
         $token = $this->laravelFacebookSdk->getJavaScriptHelper()->getAccessToken();
         if (!$token) {
             // User hasn't logged in using the JS SDK yet
             $this->setErrorData('not_authorized');
         } else {
             // Get long-lived access token
             $longLiveAccessToken = $this->facebookHelper->extendToken($token);
             // Use long-lived access token above to get UserData
             $facebookUser = $this->facebookHelper->getSocialUserByLongLivedAccessToken($longLiveAccessToken);
             // Check current facebook user existed in user database
             $userSentinel = $this->facebookUser->isFacebookUserExisted($facebookUser);
             if (!$userSentinel) {
                 $credentials = $facebookUser->toArray();
                 $credentials['password'] = md5(microtime());
                 /** @var \Modules\IzCustomer\Entities\User $userSentinel */
                 $userSentinel = $this->sentinel->registerAndActivate($credentials);
                 // update relationship
                 $userSentinel->facebook()->save($facebookUser);
             }
             // Login and remember to sentinel
             $this->sentinel->loginAndRemember($userSentinel);
             // set output
             $this->setResponseData($userSentinel->toArray());
         }
     } catch (FacebookSDKException $e) {
         $this->setResponseCode(400);
         $this->setErrorData($e->getMessage());
     }
     return $this->responseJson();
 }
 /**
  * {@inheritDoc}
  */
 public function registerAndActivate(array $data, $validate = true)
 {
     $this->rules = ['email' => 'required|unique:users', 'password' => 'required|confirmed', 'password_confirmation' => 'required'];
     if ($validate) {
         $this->validate($data);
     }
     try {
         $user = $this->sentinel->registerAndActivate($data);
     } catch (QueryException $e) {
         throw new AuthenticationException(trans('dashboard::dashboard.errors.auth.create'));
     }
     if (!isset($data['role'])) {
         $data['role'] = config('laraflock.dashboard.defaultRole');
     }
     if (!($role = $this->sentinel->findRoleBySlug($data['role']))) {
         throw new RolesException(trans('dashboard::dashboard.errors.role.found'));
     }
     $role->users()->attach($user);
     return;
 }
Exemple #4
0
 /**
  * Retrieves a link and associates a user (will lazily
  * create one) for the given slug, provider and token.
  *
  * @param  string  $slug
  * @param  mixed  $provider
  * @param  mixed  $token
  * @return \Cartalyst\Sentinel\Addons\Social\Models\LinkInterface
  */
 protected function linkLoggedOut($slug, $provider, $token)
 {
     $uid = $provider->getUserUid($token);
     $link = $this->retrieveLink($slug, $uid, $token);
     if (!($user = $link->getUser())) {
         $login = $provider->getUserEmail($token) ?: $uid . '@' . $slug;
         $user = $this->sentinel->findByCredentials(compact('login'));
         if ($user) {
             $link->setUser($user);
             $this->fireEvent('sentinel.social.existing', [$link, $provider, $token, $slug]);
         } else {
             $user = $this->sentinel->getUserRepository()->createModel();
             // Create a dummy password for the user
             $password = [$slug, $login, time(), mt_rand()];
             shuffle($password);
             $password = implode('', $password);
             $credentials = ['login' => $login, 'password' => $password];
             // Some providers give a first / last name, some don't.
             // If we only have one name, we'll just put it in the
             // "first_name" attribute.
             if (is_array($name = $provider->getUserScreenName($token))) {
                 $credentials['first_name'] = $name[0];
                 $credentials['last_name'] = $name[1];
             } elseif (is_string($name)) {
                 $credentials['first_name'] = $name;
             }
             $this->fireEvent('sentinel.social.registering', [$link, $provider, $token, $slug]);
             $user = $this->sentinel->registerAndActivate($credentials);
             $link->setUser($user);
             $this->fireEvent('sentinel.social.registered', [$link, $provider, $token, $slug]);
         }
     } else {
         $this->fireEvent('sentinel.social.existing', [$link, $provider, $token, $slug]);
     }
     $this->fireEvent('sentinel.social.linking', [$link, $provider, $token, $slug]);
     return $link;
 }
Exemple #5
0
 /**
  * Registers and activates the user.
  *
  * @param  array $credentials
  *
  * @return User|bool
  */
 public function registerAndActivate(array $credentials)
 {
     return $this->sentinel->registerAndActivate($credentials);
 }
 /**
  * Registers and activates the user.
  *
  * @param array $credentials
  * @return \Cartalyst\Sentinel\Users\UserInteface|bool 
  * @static 
  */
 public static function registerAndActivate($credentials)
 {
     return \Cartalyst\Sentinel\Sentinel::registerAndActivate($credentials);
 }