diff --git a/flexiapi/app/Http/Controllers/Api/Admin/AccountController.php b/flexiapi/app/Http/Controllers/Api/Admin/AccountController.php index 83a0918..616d50d 100644 --- a/flexiapi/app/Http/Controllers/Api/Admin/AccountController.php +++ b/flexiapi/app/Http/Controllers/Api/Admin/AccountController.php @@ -21,11 +21,13 @@ namespace App\Http\Controllers\Api\Admin; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use Illuminate\Support\Str; use Carbon\Carbon; use App\Account; use App\Password; use App\Helpers\Utils; +use App\Http\Controllers\Account\AuthenticateController as WebAuthenticateController; class AccountController extends Controller { @@ -87,6 +89,11 @@ class AccountController extends Controller $account->ip_address = $request->ip(); $account->creation_time = Carbon::now(); $account->user_agent = config('app.name'); + + if (!$request->has('activated') || !(bool)$request->has('activated')) { + $account->confirmation_key = Str::random(WebAuthenticateController::$emailCodeSize); + } + $account->save(); $password = new Password; diff --git a/flexiapi/app/Http/Middleware/AuthenticateDigestOrKey.php b/flexiapi/app/Http/Middleware/AuthenticateDigestOrKey.php index 8799651..fee442a 100644 --- a/flexiapi/app/Http/Middleware/AuthenticateDigestOrKey.php +++ b/flexiapi/app/Http/Middleware/AuthenticateDigestOrKey.php @@ -56,6 +56,11 @@ class AuthenticateDigestOrKey ->where('domain', $domain) ->firstOrFail(); + // Check if activated + if (!$account->activated) { + return $this->generateUnauthorizedResponse($account); + } + // Key authentication if ($request->header('x-api-key')) { if ($account->apiKey diff --git a/flexiapi/database/factories/AccountFactory.php b/flexiapi/database/factories/AccountFactory.php index 5b75dd2..86b6459 100644 --- a/flexiapi/database/factories/AccountFactory.php +++ b/flexiapi/database/factories/AccountFactory.php @@ -36,6 +36,7 @@ class AccountFactory extends Factory 'user_agent' => $this->faker->userAgent, 'ip_address' => $this->faker->ipv4, 'creation_time' => $this->faker->dateTime, + 'activated' => true ]; } } diff --git a/flexiapi/resources/views/documentation.blade.php b/flexiapi/resources/views/documentation.blade.php index 2e2adb4..e26f527 100644 --- a/flexiapi/resources/views/documentation.blade.php +++ b/flexiapi/resources/views/documentation.blade.php @@ -48,11 +48,13 @@ For the moment only DIGEST-MD5 and DIGEST-SHA-256 are supported through the auth

Endpoints

-

Ping

+

Public endpoints

GET /ping

Returns pong

+

Accounts

+

GET /accounts/{sip}/info

Retrieve public information about the account.

Return 404 if the account doesn't exists.

@@ -73,19 +75,23 @@ For the moment only DIGEST-MD5 and DIGEST-SHA-256 are supported through the auth
  • code the PIN code
  • -

    Accounts (User)

    +

    User authenticated endpoints

    +

    Those endpoints are authenticated and requires an activated account.

    GET /accounts/me

    Retrieve the account information.

    -

    POST /accounts/email/request

    +

    DELETE /accounts/me

    +

    Delete the account.

    + +

    POST /accounts/me/email/request

    Change the account email. An email will be sent to the new email address to confirm the operation.

    JSON parameters:

    -

    POST /accounts/password

    +

    POST /accounts/me/password

    Change the account password.

    JSON parameters:

    -

    Devices

    +

    Devices

    -

    GET /devices

    +

    GET /accounts/me/devices

    Return the user registered devices.

    -

    DELETE /devices/{uuid}

    +

    DELETE /accounts/me/devices/{uuid}

    Remove one of the user registered devices.

    -

    Accounts (Administrator)

    +

    Admin endpoints

    +

    Those endpoints are authenticated and requires an admin account.

    POST /accounts

    To create an account directly from the API.

    +

    If activated is set to false a random generated confirmation_key will be returned to allow further activation using the public endpoints.

    +

    JSON parameters: