1
0
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:
Toby Zerner
2015-01-22 14:44:33 +10:30
parent 74c9b48870
commit ad269fdb5a
11 changed files with 194 additions and 44 deletions

View File

@@ -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;
}
}