mirror of
https://github.com/flarum/core.git
synced 2025-10-19 10:46:06 +02:00
Add external authenticator (social login) API
Allows registrations to be completed with a pre-confirmed email address and no password.
This commit is contained in:
@@ -12,6 +12,7 @@ namespace Flarum\Api;
|
||||
|
||||
use Flarum\Core\Model;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @todo document database columns with @property
|
||||
@@ -55,14 +56,13 @@ class AccessToken extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the given token only if it is valid.
|
||||
* Check that the token has not expired.
|
||||
*
|
||||
* @param string $token
|
||||
* @return static|null
|
||||
* @return bool
|
||||
*/
|
||||
public static function valid($token)
|
||||
public function isValid()
|
||||
{
|
||||
return static::where('id', $token)->where('expires_at', '>', new DateTime)->first();
|
||||
return $this->expires_at > new DateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -73,8 +73,12 @@ class CreateAction extends BaseCreateAction
|
||||
*/
|
||||
protected function create(JsonApiRequest $request)
|
||||
{
|
||||
return $this->bus->dispatch(
|
||||
$user = $this->bus->dispatch(
|
||||
new RegisterUser($request->actor, $request->get('data'))
|
||||
);
|
||||
|
||||
$request->actor = $user;
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
@@ -50,7 +50,7 @@ class LoginWithHeader implements MiddlewareInterface
|
||||
if (isset($parts[0]) && starts_with($parts[0], $this->prefix)) {
|
||||
$token = substr($parts[0], strlen($this->prefix));
|
||||
|
||||
if ($accessToken = AccessToken::valid($token)) {
|
||||
if (($accessToken = AccessToken::find($token)) && $accessToken->isValid()) {
|
||||
$this->app->instance('flarum.actor', $user = $accessToken->user);
|
||||
|
||||
$user->updateLastSeen()->save();
|
||||
|
Reference in New Issue
Block a user