Create token

@param $user
@return string
764685
protected function createToken($user)
    {
        $token = $this->getToken();

        DB::table($this->table)->insert([
            'user_id'    => $user->id,
            'token'      => $token,
            'created_at' => Carbon::now()->toDateTimeString(),
        ]);

        return $token;
    }
421773
private function createUser(SamlSpResponseToken $token)
    {
        if (null === $this->userCreator) {
            return null;
        }

        $user = $this->userCreator->createUser($token->getResponse());

        if ($user && false === $user instanceof UserInterface) {
            throw new \LogicException('User creator must return instance of UserInterface or null');
        }

        return $user;
    }
925501
protected function _createToken($username)
    {
        if (isset($this->_person)) {
            return;
        }

        $api = $this->_getApi();

        //if there's no api or the token are invalid then don't create
        //session
        if (!$api || !$api->getUser()->id) {
            return;
        }

        if ($token = $api->getToken()) {
            $person = AnService::get('repos:people.person')->find(array('username' => $username));
            $user = $api->getUser();
            $session = AnService::get('repos:connect.session')
            ->findOrAddNew(array(
                'profileId' => $user->id, 
                'api' => $api->getName()
            ));

            $session->setData(array(
                'component' => 'com_connect',
                'owner' => $person,
            ))->setToken($token);

            $session->save();

            $this->_person = $person;
            $this->_api = $api;
        }
    }
1102101
public function createToken(CanVerifyEmailContract $user, $expiration): string
    {
        $payload = $this->buildPayload($user, $user->getEmailForVerification(), $expiration);

        return hash_hmac('sha256', $payload, $this->getKey());
    }
803275
public function create(CanResetPassword $user)
    {
        $email = $user->getEmailForPasswordReset();

        $this->deleteExisting($user);

        // We will create a new, random token for the user so that we can e-mail them
        // a safe link to the password reset form. Then we will insert a record in
        // the database so that we can verify the token within the actual reset.
        $token = $this->createNewToken();

        $this->getTable()
             ->insert($this->table)
             ->values([
                 'email'      => ':email',
                 'token'      => ':token',
                 'created_at' => ':date'
             ])
             ->setParameters([
                 'email' => $email,
                 'token' => $token,
                 'date'  => new Carbon('now')
             ])
             ->execute();

        return $token;
    }
239660
public function make($user)
    {
        $RagnarokUser = new SecUser();
        $this->userRagnarok = $RagnarokUser->populate($user);
        Session::put($this->getName(), $this->userRagnarok);
        return $this->userRagnarok;
    }
1225155
public function create(CanResetPassword $user)
    {
        $email = $user->getEmailForPasswordReset();

        $this->deleteExisting($user);

        // We will create a new, random token for the user so that we can e-mail them
        // a safe link to the password reset form. Then we will insert a record in
        // the database so that we can verify the token within the actual reset.
        $token = $this->createNewToken($user);

        $reminder = new PasswordReminder(
            $email,
            $token
        );

        $this->entities->persist($reminder);
        $this->entities->flush($reminder);

        return $token;
    }
1171087
public function actionCreate()
    {
        $user = new User();
        $this->readValue($user, 'username');
        $this->readValue($user, 'email');
        $user->setPassword($this->prompt('Password:', [
            'required' => true,
            'pattern'  => '#^.{6,255}$#i',
            'error'    => 'More than 6 symbols',
        ]));
        $user->generateAuthKey();
        $user->status = User::STATUS_ACTIVE;
        $this->log($this->repository->save($user));
    }
197601
public static function create(AbstractUser $user, bool $remember = false): UserAccessTokenInterface
    {
        $token = self::find()->where(['user_id' => $user->id, 'is_active' => 1])->orderBy(['created_at' => SORT_DESC])->one();
        if ($token instanceof UserAccessTokenInterface && $token->expired_at > time()) {
            return $token;
        }
        $user->deactivateTokens();
        $new_token = new static([
            'user_id' => $user->id,
            'access_token' => self::generateToken($user->email),
            'expired_at' => self::generateExpired($remember),
            'is_active' => 1,
        ]);
        (new UserAccessTokenHandler($new_token))->create();
        $new_token->refresh();
        $user->updateLastEntering();
        return $new_token;
    }
360023
public function create(ApiClientInterface $client, UserInterface $user = null)
    {
        $tokenClass = $this->tokenClass;

        return $tokenClass::create($client, $user);
    }
470705
public static function login($user)
  {
    $token = $user->{config('auth.provider.' . Auth::$provider . '.with')} = Hash::random(70);
    $user->save();

    return Remember::login($token);
  }
824851
def generate_user_token(self, user, salt=None):
        
        return self.token_serializer.dumps(str(user.id), salt=salt)
563682
private function generateTokenForUser(UserInterface $user)
    {
        // if a token was already requested within the request interval time frame
        if (null !== $user->getPasswordResetToken()
            && $this->dateIsInRequestFrame($user->getPasswordResetTokenExpiresAt())) {
            throw new TokenAlreadyRequestedException(self::getRequestInterval());
        }
        $em = $this->getDoctrine()->getManager();

        $user->setPasswordResetToken($this->getToken());
        $expireDateTime = (new \DateTime())->add(self::getResetInterval());
        $user->setPasswordResetTokenExpiresAt($expireDateTime);
        $user->setPasswordResetTokenEmailsSent(0);

        $em->persist($user);
        $em->flush();
    }
863178
public function encryptUserData(AbstractUser $user)
    {
        // data (we use short syntax to reduce the size of the cookie or session)
        $data = [
            // username
            'u'  => $user->getUsername(),
            // valid until
            'vu' => time() + $this->getTokenTtl(),
            // auth provider driver
            'ap' => $user->getAuthProviderName(),
            // user provider driver
            'up' => $user->getUserProviderName()
        ];

        // build and add token to $data
        $token = $this->getCrypt()->encrypt($this->jsonEncode($data), $this->getEncryptionKey());
        $token = urlencode(rtrim($token, '='));

        return $token;
    }
371607
public function sendActivationMail($user)
    {
        if( ! $this->shouldSend($user) ) {
            return trans('HCACL::users.activation.check_email');
        }

        \DB::beginTransaction();

        try {
            $token = $this->createActivation($user);

            $user->sendActivationLinkNotification($token);
        } catch ( \Exception $e ) {
            \DB::rollback();

            throw new \Exception('Activation code or mail sending failed');
        }

        \DB::commit();

        return trans('HCACL::users.activation.resent_activation');
    }
1186197
public function forUser($user)
    {
        $callback = function () use ($user)
        {
            return $user;
        };

        return new static(
            $this->container, $callback, $this->abilities,
            $this->policies, $this->beforeCallbacks, $this->afterCallbacks
        );
    }
27351
protected function FormUrl(User $user = null)
    {
        $args = array();
        if ($user)
        {
            $args['user'] = $user->GetID();
        }
        return BackendRouter::ModuleUrl(new UserForm(), $args); 
    }