public function createShadowOAuthUser(OAuthUserContract $OAuthUser)
    {
        $fullName = $OAuthUser->getName();
        @list($firstName, $lastName) = explode(' ', $fullName);

        $email = $OAuthUser->getEmail();
        $serviceName = $this->getName();
        $providerName = $this->getProviderName();

        if (empty($email)) {
            $email = $OAuthUser->getId() . '+' . $serviceName . '@' . $serviceName . '.com';
        } else {
            list($emailId, $domain) = explode('@', $email);
            $email = $emailId . '+' . $serviceName . '@' . $domain;
        }

        $user = User::whereEmail($email)->first();

        if (empty($user)) {
            $data = [
                'username'       => $email,
                'name'           => $fullName,
                'first_name'     => $firstName,
                'last_name'      => $lastName,
                'email'          => $email,
                'is_active'      => true,
                'oauth_provider' => $providerName,
            ];

            $user = User::create($data);
        }

        // todo Should this be done only if the user was not already there?
        if (!empty($defaultRole = $this->getDefaultRole())) {
            User::applyDefaultUserAppRole($user, $defaultRole);
        }
        if (!empty($serviceId = $this->getServiceId())) {
            User::applyAppRoleMapByService($user, $serviceId);
        }

        return $user;
    }
public function createShadowOAuthUser(OAuthUserContract $OAuthUser)
    {
        $fullName = $OAuthUser->getName();
        @list($firstName, $lastName) = explode(' ', $fullName);

        $email = $OAuthUser->getEmail();
        $serviceName = $this->getName();
        $providerName = $this->getProviderName();

        if (empty($email)) {
            $email = $OAuthUser->getId() . '+' . $serviceName . '@' . $serviceName . '.com';
        } else {
            list($emailId, $domain) = explode('@', $email);
            $email = $emailId . '+' . $serviceName . '@' . $domain;
        }

        $user = User::whereEmail($email)->first();

        if (empty($user)) {
            $data = [
                'username'       => $email,
                'name'           => $fullName,
                'first_name'     => $firstName,
                'last_name'      => $lastName,
                'email'          => $email,
                'is_active'      => true,
                'oauth_provider' => $providerName,
            ];

            $user = User::create($data);
        }

        // todo Should this be done only if the user was not already there?
        if (!empty($defaultRole = $this->getDefaultRole())) {
            User::applyDefaultUserAppRole($user, $defaultRole);
        }
        if (!empty($serviceId = $this->getServiceId())) {
            User::applyAppRoleMapByService($user, $serviceId);
        }

        return $user;
    }
public function createShadowOAuthUser ( OAuthUserContract $ OAuthUser ) { $ fullName = $ OAuthUser -> getName ( ) ; @ list ( $ firstName , $ lastName ) = explode ( ' ' , $ fullName ) ; $ email = $ OAuthUser -> getEmail ( ) ; $ serviceName = $ this -> getName ( ) ; $ providerName = $ this -> getProviderName ( ) ; if ( empty ( $ email ) ) { $ email = $ OAuthUser -> getId ( ) . '+' . $ serviceName . '@' . $ serviceName . '.com' ; } else { list ( $ emailId , $ domain ) = explode ( '@' , $ email ) ; $ email = $ emailId . '+' . $ serviceName . '@' . $ domain ; } $ user = User :: whereEmail ( $ email ) -> first ( ) ; if ( empty ( $ user ) ) { $ data = [ 'username' => $ email , 'name' => $ fullName , 'first_name' => $ firstName , 'last_name' => $ lastName , 'email' => $ email , 'is_active' => true , 'oauth_provider' => $ providerName , ] ; $ user = User :: create ( $ data ) ; } // todo Should this be done only if the user was not already there? if ( ! empty ( $ defaultRole = $ this -> getDefaultRole ( ) ) ) { User :: applyDefaultUserAppRole ( $ user , $ defaultRole ) ; } if ( ! empty ( $ serviceId = $ this -> getServiceId ( ) ) ) { User :: applyAppRoleMapByService ( $ user , $ serviceId ) ; } return $ user ; }
If does not exists, creates a shadow OAuth user using user info provided
by the OAuth service provider and assigns default role to this user
for all apps in the system. If user already exists then updates user's
role for all apps and returns it.

@param OAuthUserContract $OAuthUser

@return User
@throws \Exception
If does not exists creates a shadow OAuth user using user info provided by the OAuth service provider and assigns default role to this user for all apps in the system . If user already exists then updates user s role for all apps and returns it .