Create a new token by User id.

@param  mixed  $id

@return string|null
339632
public function tokenById($id)
    {
        if ($user = $this->provider->retrieveById($id)) {
            return $this->jwT->fromUser($user);
        }
    }
1147264
public function actionCreateUser($id)
    {
        $model = $this->findModel($id);
        if (empty($model->user)) {
            $user = new User([
                'status'     => User::STATUS_ACTIVE,
                'username'   => date('Ymdhis'),
                'full_name'  => $model->first_name . ' ' . $model->last_name,
                'company'    => $model->company,
                'tax_number' => $model->vat_number,
                'address'    => $model->address,
                'avatar'     => $model->avatar,
            ]);
            $user->setPassword($model->email);
            $user->generateAuthKey();
            if ($user->save()) {
                $model->user_id = $user->getPrimaryKey();
                $model->save();
            }
        }

        return $this->goBack(request()->referrer);
    }
69167
public function getByRememberToken(int $id, string $token) : ?Authenticatable
    {
        $model = $this->getModel();

        $user = $model->newQuery()
                      ->where($model->getAuthIdentifierName(), $id)
                      ->first();

        if ($user === null) {
            return null;
        }

        $rememberToken = $user->getRememberToken();

        return !empty($rememberToken) && hash_equals($rememberToken, $token) ? $user : null;
    }
1231962
public function actionIndexPost($id=NULL)
	{
		if ($id === NULL)
			return $this->createNewPost();
		else
			return $this->updatePost($id);
	}
783469
function signature($id = null) {
		if ( ! $this->unsigned) {
			if ($this->get('id', null) === null) {
				$formsignature = 'freiaform'.$this->formindex;
			}
			else { # custom signature
				$formsignature = $this->get('id');
			}

			if ($id !== null) {
				return "{$formsignature}_field$id";
			}
			else { # form signature
				return $formsignature;
			}
		}
		else { # unsigned
			return null;
		}
	}
1113806
public function getById($id)
    {
        return isset($this->_data[$id]) ? $this->_data[$id] : null;
    }
1109281
private function validateToken(string $id)
    {
        $token = (new Parser())->parse((string)$id);
        //Verifica se o token expirou
        if ($token->isExpired()) {
            return NULL;
        }
        //Verifica a assinatura
        $signer = new Sha256();
        $key = new Key('file://' . config('openid.key'));
        if (!$token->verify($signer, $key)) {
            return NULL;
        }
        //Verifica os dados
        $validation = new ValidationData();
        $validation->setIssuer(config('openid.server'));
        $validation->setAudience(config('openid.client.id'));
        if (!$token->validate($validation)) {
            return NULL;
        }

        return $token;
    }
858558
public function getSignatureRequest($id)
    {
        $response = $this->rest->get(
            static::SIGNATURE_REQUEST_PATH . '/' . $id
        );

        $this->checkResponse($response);

        return new SignatureRequest($response);
    }
1274926
public function getDMByUserId($id)
    {
        return $this->apiCall('im.open', [
            'user' => $id,
        ])->then(function (Payload $response) {
            return $this->getDMById($response['channel']['id']);
        });
    }
149265
public static function create($id = null)
    {
        $obj = new self();

        $obj->id = ($id) ? (string) $id : Uuid::uuid4()->toString();

        return $obj;
    }
17529
public function postAdminEdit($id = null)
    {
        // Get the user information
        $user = Sentinel::findById($id);

        if ($user == null)
        {
            // Prepare the error message
            $error = Lang::get('base.auth.not_found');

            // Redirect to the user management page
            return Redirect::route('admin.users.show')->with('error', $error);
        }

        $this->validationRulesAdmin['email'] = "required|email|unique:User,email,{$user->email},email,status,3|max:255";
        $this->validationRulesAdmin['username'] = "required|min:3|unique:User,username,{$user->username},username|max:25";

        // Do we want to update the user password?
        if (!$password = Input::get('password')) {
            unset($this->validationRulesAdmin['password']);
            unset($this->validationRulesAdmin['password_confirm']);
        }

        // Create a new validator instance from our validation rules
        $validator = Validator::make(Input::all(), $this->validationRulesAdmin);

        // If validation fails, we'll exit the operation now.
        if ($validator->fails()) {
            // Ooops.. something went wrong
            return Redirect::back()->withInput()->withErrors($validator);
        }

        try {
            // Update the user
            $user->gender   = Input::get('gender');
            $user->first_name  = Input::get('first_name');
            $user->last_name   = Input::get('last_name');
            $user->username    = Input::get('username');
            $user->email       = Input::get('email');
            $user->description = Input::get('description');

            if (Input::get('force_new_password'))
                $user->force_new_password = 1;
            else
                $user->force_new_password = 0;

            if (Input::get('birthday') != null)
                $user->birthday = \Carbon\Carbon::createFromFormat('d/m/Y', Input::get('birthday'));

            $password_changed = false;

            // Do we want to update the user password?
            if ($password)
            {
                $user->password = Hash::make($password);
                $password_changed = true;
            }

            // is new image uploaded?
            if ($file = Input::file('pic'))
            {
                $fileName        = $file->getClientOriginalName();
                $extension       = $file->getClientOriginalExtension() ?: 'png';

                if ($extension == 'png' || $extension == 'PNG' || $extension == 'JGP' || $extension == 'jpg' || $extension == 'gif')
                {
                    $folderName      = '/uploads/users/';
                    $destinationPath = public_path() . $folderName;
                    $safeName        = str_random(10).'.'.$extension;
                    $file->move($destinationPath, $safeName);

                    //delete old pic if exists
                    if(File::exists(public_path() . $folderName . $user->pic))
                        File::delete(public_path() . $folderName . $user->pic);

                    //save new file path into db
                    $user->pic   = $safeName;
                }
            }

            /*
            // Get the current user groups
            $userRoles = $user->roles()->lists('id')->all();

            // Get the selected groups
            $selectedRoles = Input::get('groups', array());

            // Groups comparison between the groups the user currently
            // have and the groups the user wish to have.
            $rolesToAdd    = array_diff($selectedRoles, $userRoles);
            $rolesToRemove = array_diff($userRoles, $selectedRoles);

            // Assign the user to groups
            foreach ($rolesToAdd as $roleId) {
                $role = Sentinel::findRoleById($roleId);

                $role->users()->attach($user);
            }

            // Remove the user from groups
            foreach ($rolesToRemove as $roleId) {
                $role = Sentinel::findRoleById($roleId);

                $role->users()->detach($user);
            }
            */

            // Activate / De-activate user
            $status = $activation = Activation::completed($user);
            $currentStatus = Input::get('status');

            if($currentStatus != $status)
            {
                if ($currentStatus == 0)
                    // Remove existing activation record
                    Activation::remove($user);
                else
                {
                    $activation = Activation::exists($user);

                    if (!$activation)
                    {
                        Activation::create($user);

                        $activation = Activation::exists($user);
                    }

                    if($activation)
                        Activation::complete($user, $activation->code);
                }

                $user->status = $currentStatus;
            }
            else
                $user->status = $currentStatus;

            // Was the user updated?
            if ($user->save())
            {
                if ($password_changed && Input::get('send_new_password_email'))
                {
                    Mail::queue('emails.account.password-changed-by-admin', [ 'user' => $user, 'new_password' => $password ], function ($m) use ($user) {
                        $m->to($user->email, $user->first_name . ' ' . $user->last_name);
                        $m->subject(Lang::get('base.mails.password_changed'));
                    });
                }

                if ($password_changed)
                    Base::TargettedLog($user->username . ' (' . $user->first_name . ' ' . $user->last_name . ') password was changed by an admin. ', $user->id);

                Base::TargettedLog($user->username . ' (' . $user->first_name . ' ' . $user->last_name . ') profile was changed by an admin. ', $user->id);

                // Prepare the success message
                $success = Lang::get('base.auth.user_changed');

                // Redirect to the user page
                return Redirect::route('users.update', $id)->with('success', $success);
            }

        } catch (Exception $e) {
        }
        $error = Lang::get('base.base.error');

        // Redirect to the user page
        return Redirect::route('users.update', $id)->withInput()->with('error', $error);
    }
989040
public function createAutoLoginTokenAndCookie(int $id)
    {
        $authtok = new AuthToken($this->db);
        $authtok->setId($id);
        $authtok->setExpires($this->expires_after);

        setcookie($this->cookie_name, $authtok->generate(), $authtok->getExpiresTimestamp(), '/');
    }
301650
public static function create($user_id) {
	$text  = bootstrap::get_library('text');
	$mysql = bootstrap::get_library('mysql');
	
	$new_token  = $text::generate_token(self::TOKEN_LENGTH);
	$expiration = (time() + self::EXPIRATION);
	
	$sql   = "INSERT INTO `login_tokens` SET `code` = '%s', `user_id` = %d, `expire_at` = %d;";
	$binds = [$new_token, $user_id, $expiration];
	$mysql::query($sql, $binds);
	
	return new static($mysql::$insert_id);
}
210870
public static function create($id = null)
    {
        if ( empty($id) )
        {
            $id = md5(__METHOD__) . count(self::$instances); 
        }
        if ( empty(self::$instances[$id]) )
        {
            self::$instances[$id] = new self();  
        }
        return self::$instances[$id];
    }
887453
public function show($id)
    {
        $webhook = $this->client->get(
            sprintf('buckets/%d/webhooks/%d.json', $this->bucket, $id)
        );
        $webhook = new Webhook($this->response($webhook));
        $webhook->inContext($this->bucket);

        return $webhook;
    }
592646
public function activate($id = null, $token = null)
    {
        $user = $this->_getUser($id, $token);

        if ($user === null) {
            $this->Flash->error(__d('community', 'User was not found'));
            return $this->redirect(['action' => 'login']);
        }

        if ($user->status) {
            $this->Flash->error(__d(
                'community',
                '«{0}», you have already activated your profile before.',
                sprintf('<strong>%s</strong>', $user->name)
            ));
        } else {
            $user
                ->set('token', null)
                ->set('status', true);

            $result = $this->Users->save($user);
            if ($result) {
                EventManager::trigger('Controller.Users.successActivate', $this, ['user' => $result]);
                $this->Flash->success(__d(
                    'community',
                    '«{0}», you profile has been activate successfully.',
                    sprintf('<strong>%s</strong>', $user->name)
                ));
            } else {
                $this->Flash->error(__d(
                    'community',
                    'An error has occurred. Please, try again.',
                    sprintf('<strong>%s</strong>', $user->name)
                ));
            }
        }

        return $this->redirect(['action' => 'login']);
    }
1299057
public function setId($id = null)
    {
        $this->id = ($id !== null) ? $id : SecureKey::generate();

        return $this;
    }