Regular register method now also returns a token upon registration
token expiration is set for 1 week

@return \Cake\Network\Response
327789
public function add()
    {
        $this->Crud->on('afterSave', function (Event $event) {
            if ($event->subject->created) {
                $token = [
                    'id' => $event->subject->entity->id,
                    'exp' => time() + 60 * 60 * 24 * 7,
                ];
                $this->set('data', [
                    'id' => $event->subject->entity->id,
                    'token' => JWT::encode($token, Security::salt())
                ]);
                $this->Crud->action()->config('serialize.data', 'data');
            }
            $signupEvent = new Event('Users.afterSignup', $event->subject());
            $this->eventManager()->dispatch($signupEvent);
        });
        return $this->Crud->execute();
    }
554600
public function userRegisterCallback() {
    $sdk = $this->getSdk('register');

    if ($sdk instanceof RedirectResponse) {
      return $sdk;
    }

    $this->authManager->setSdk($sdk);
    $profile = $this->getProfile('register');

    if ($profile instanceof RedirectResponse) {
      return $profile;
    }

    // Check whether user account exists. If account already exists,
    // authorize the user and redirect him to the account page.
    $account = $this->entityTypeManager()
      ->getStorage('user')
      ->loadByProperties([
        'facebook_id' => $profile->getField('id'),
      ]);

    if ($account) {
      $account = current($account);

      if (!$account->get('status')->value) {
        drupal_set_message($this->t('You already have account on this site, but your account is blocked. Contact the site administrator.'), 'error');
        return $this->redirect('user.register');
      }

      user_login_finalize($account);
      return $this->redirect('entity.user.canonical', [
        'user' => $account->id(),
      ]);
    }

    // Save email and name to storage to use for auto fill the registration
    // form.
    $data_handler = $this->networkManager->createInstance('social_auth_facebook')->getDataHandler();
    $data_handler->set('access_token', $this->accessToken);
    $data_handler->set('mail', $profile->getField('email'));
    $data_handler->set('name', $profile->getField('name'));

    drupal_set_message($this->t('You are now connected with @network, please continue registration', [
      '@network' => $this->t('Facebook'),
    ]));

    return $this->redirect('user.register', [
      'provider' => 'facebook',
    ]);
  }
281956
public function register()
    {
        Request::macro('isXml', function () {
            return strtolower($this->getContentType()) === 'xml';
        });

        Request::macro('xml', function ($assoc = true) {
            if (!$this->isXml() || !$content = $this->getContent()) {
                return $assoc ? [] : new \stdClass;
            }
            // Returns the xml input from a request
            $xml = simplexml_load_string($content, null, LIBXML_NOCDATA);
            $json = json_encode($xml);

            return json_decode($json, $assoc);
        });
    }
197046
public function postRegister()
    {
        if (!Config::get('credentials.regallowed')) {
            return Redirect::route('account.register');
        }

        $input = Binput::only(['first_name', 'last_name', 'email', 'password', 'password_confirmation']);

        $val = UserRepository::validate($input, array_keys($input));
        if ($val->fails()) {
            return Redirect::route('account.register')->withInput()->withErrors($val->errors());
        }

        $this->throttler->hit();

        try {
            unset($input['password_confirmation']);

            $user = Credentials::register($input);

            if (!Config::get('credentials.activation')) {
                $mail = [
                    'url'     => URL::to(Config::get('credentials.home', '/')),
                    'email'   => $user->getLogin(),
                    'subject' => Config::get('app.name').' - Welcome',
                ];

                Mail::queue('credentials::emails.welcome', $mail, function ($message) use ($mail) {
                    $message->to($mail['email'])->subject($mail['subject']);
                });

                $user->attemptActivation($user->getActivationCode());
                $user->addGroup(Credentials::getGroupProvider()->findByName('Users'));

                return Redirect::to(Config::get('credentials.home', '/'))
                    ->with('success', 'Your account has been created successfully. You may now login.');
            }

            $code = $user->getActivationCode();

            $mail = [
                'url'     => URL::to(Config::get('credentials.home', '/')),
                'link'    => URL::route('account.activate', ['id' => $user->id, 'code' => $code]),
                'email'   => $user->getLogin(),
                'subject' => Config::get('app.name').' - Welcome',
            ];

            Mail::queue('credentials::emails.welcome', $mail, function ($message) use ($mail) {
                $message->to($mail['email'])->subject($mail['subject']);
            });

            return Redirect::to(Config::get('credentials.home', '/'))
                ->with('success', 'Your account has been created. Check your email for the confirmation link.');
        } catch (UserExistsException $e) {
            return Redirect::route('account.register')->withInput()->withErrors($val->errors())
                ->with('error', 'That email address is taken.');
        }
    }
1253721
protected function getCookieExpirationDate()
	{
		return Config::get( $this->configPrefix . '.expire_on_close' ) ? 0 : Carbon::now()->addMinutes( Config::get( $this->configPrefix . '.lifetime' ) );
	}
1192359
public function getTokenExpire()
    {
        return $this->_state->token->obtained
            + $this->_state->token->data->expires_in - time();
    }
104556
public function register()
    {
        if (! $this->isRegistered) {
            spl_autoload_register([$this, 'load'], true, true);
            $this->isRegistered = true;
        }

        return $this;
    }
907115
public function register()
    {
        $this->allowedModifiers           = Tokens::$scopeModifiers;
        $this->allowedModifiers[\T_FINAL] = \T_FINAL;

        $tokens = $this->targetedTokens;

        if (\defined('T_ANON_CLASS')) {
            $tokens[] = \T_ANON_CLASS;
        }

        return $tokens;
    }
1300426
public function ipnAction()
    {
        $payboxResponse = $this->container->get('lexik_paybox.response_handler');
        $result = $payboxResponse->verifySignature();

        return new Response($result ? 'OK' : 'KO');
    }
1274234
public function registerAction()
    {
        $userIdentityField = $this->container->getParameter('rch_jwt_user.user_identity_field');
        $userManager = $this->container->get('fos_user.user_manager');
        $userClass = $userManager->getClass();

        $rules = [
            $userIdentityField => [
                'requirements' => ['email' == $userIdentityField ? new Email() : '[^/]+'],
            ],
            'password' => ['requirements' => '[^/]+'],
        ];

        $params = $this->get('rch_jwt_user.credential_fetcher')
            ->create($rules)
            ->all();

        $user = $this->createUser($params, $userManager);

        return $this->renderToken($user, 201);
    }
238400
public function postRegister()
    {
        if( $this->userForm->register(Input::all(),false) )
        {
            return Redirect::route('cpanel.login')
                ->with('success', Lang::get('cpanel::users.register_success'));
        }

        return Redirect::back()
            ->withInput()
            ->withErrors($this->userForm->getErrors());

    }
342085
public function getTokens()
    {
        $response = $this->client->post($this->uri());

        return $this->handleResponse($response);
    }
72608
protected function getTokenFromCookie()
    {
        $cookies = $this->getCookies();
        if (!empty($cookies['token']) && $cookies['token']['expiration'] > time()) {
            return $cookies['token']['value'];
        }

        return null;
    }
681205
protected function refreshToken()
    {
        $token = $this->authorization->getApi()
                                     ->getAuthorizerToken(
                                         $this->authorization->getAuthorizerCorpId(),
                                         $this->authorization->getAuthorizerPermanentCode()
                                     );

        $this->authorization->setAuthorizerAccessToken($token['access_token'], $token['expires_in'] - 1500);

        return $token['access_token'];
    }
1235211
public function register()
    {
        Paginator::viewFactoryResolver(function () {
            return $this->app['view'];
        });

        Paginator::currentPathResolver(function () {
            return $this->app['request']->url();
        });

        Paginator::currentPageResolver(function ($pageName = 'page') {
            $page = $this->app['request']->input($pageName);

            if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
                return (int) $page;
            }

            return 1;
        });
    }
541308
public function token()
    {
        $payload = [
            'auth'        => [$this->config['client_id'], $this->config['client_secret']],
            'form_params' => ['grant_type' => 'client_credentials'],
        ];

        $request = array_merge($this->requestTemplate, $payload);
        $rawResponse = $this->getHttpClient()->post($this->buildUrlFromString('oauth2/token'), $request);
        $rawResponse = $this->responseToArray($rawResponse);

        return [
            'token'  => Arr::get($rawResponse, 'access_token'),
            'type'   => Arr::get($rawResponse, 'token_type'),
            'scope'  => Arr::get($rawResponse, 'scope'),
            'expiry' => isset($rawResponse['expires_in'])
                ? time() + Arr::get($rawResponse, 'expires_in')
                : null,
        ];
    }
1125391
public function register() {
        if (!$this->registered) {
            spl_autoload_register([$this, 'autoLoad'], $throw=true, $prepend=false);
            $this->registered = true;
        }
        return $this;
    }