mirror of
https://github.com/flarum/core.git
synced 2025-07-30 21:20:24 +02:00
Implement token-based auth API
This commit is contained in:
@@ -1,10 +1,35 @@
|
||||
<?php
|
||||
namespace Codeception\Module;
|
||||
|
||||
// here you can define custom actions
|
||||
// all public methods declared in helper class will be available in $I
|
||||
use Laracasts\TestDummy\Factory;
|
||||
use Auth;
|
||||
use DB;
|
||||
|
||||
class ApiHelper extends \Codeception\Module
|
||||
{
|
||||
public function haveAnAccount($data = [])
|
||||
{
|
||||
return Factory::create('Flarum\Core\Users\User', $data);
|
||||
}
|
||||
|
||||
public function login($identifier, $password)
|
||||
{
|
||||
$this->getModule('REST')->sendPOST('/api/auth/login', ['identifier' => $identifier, 'password' => $password]);
|
||||
|
||||
$response = json_decode($this->getModule('REST')->grabResponse(), true);
|
||||
if ($response && is_array($response) && isset($response['token'])) {
|
||||
return $response['token'];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function amAuthenticated()
|
||||
{
|
||||
$user = $this->haveAnAccount();
|
||||
$user->groups()->attach(3); // Add member group
|
||||
Auth::onceUsingId($user->id);
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user