Skip to content

Commit 4f59578

Browse files
committed
About launching Hyperion and creating your own admin user
1 parent 30b3714 commit 4f59578

File tree

1 file changed

+61
-26
lines changed

1 file changed

+61
-26
lines changed

README.md

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -255,53 +255,85 @@ The `config.yaml` contains environment variables that are internal to the Python
255255

256256
## Launch the API
257257

258+
> [!WARNING]
259+
> Beforehand, check that your venv is activated.
260+
261+
### Using VS Code
262+
263+
1. In the activity bar (the leftmost part), click the _Run and Debug_ icon (the play button).
264+
2. Click the green play button.
265+
266+
Check that your Hyperion instance is up and running by navigating to http://localhost:8000/information.
267+
268+
### Using the command-line interface
269+
258270
```bash
259271
fastapi dev app/main.py
260272
```
261273

262-
## Use Alembic migrations
274+
Check that your Hyperion instance is up and running by navigating to http://localhost:8000/information.
263275

264-
See [migrations README](./migrations/README)
276+
## Create your own user
265277

266-
Warning : on SQLite databases, you have to drop the database and recreate it to apply the new DDL.
278+
There are many ways to do so, ranked here from easiest (GUI only) to hardest (CLI only).
279+
Note that registration and activation are distinct steps, so for fun you may register one way and activate your account another way.
267280

268-
## OpenAPI specification
281+
### With CalypSSO
269282

270-
API endpoints are parsed following the OpenAPI specifications at `http://127.0.0.1:8000/openapi.json`.
283+
#### Registering your account
271284

272-
A Swagger UI is available at `http://127.0.0.1:8000/docs`. For authentication to work, a valid `AUTH_CLIENT` must be defined in the `.env`, with `http://127.0.0.1:8000/docs/oauth2-redirect` as the redirect URI, and `scope=API` must be added to the authentication request.
285+
Go to http://localhost:8000/calypsso/register and type a valid email address to register (start the creation of) your account.
273286

274-
## Create the first user
287+
#### Activating your account
275288

276-
You can create the first user either using Titan or calling the API directly.
289+
Go back to the shell running your Hyperion instance, in the logs look for a link looking like http://localhost:3000/calypsso/activate?activation_token=12345.
290+
Open it and activate (end the creation of) your account.
277291

278-
> You need to use an email with the format `[email protected]` or `[email protected]`
292+
### With Titan
279293

280-
To activate your account you will need an activation token which will be printed in the console.
294+
1. Click "_Se connecter_" on the login page: you land CalypSSO's login page.
295+
2. Click "_Créer un compte_" and create your account using CalypSSO as above.
281296

282-
### With Titan
297+
### Using the API through the swagger
283298

284-
Press "Créer un compte" on the first page and follow the process.
299+
#### Registering your account
285300

286-
### Using the API directly
301+
1. Go to http://localhost:8000/docs: this is called the _swagger_, a web interface to interact with the API, it is a layer on top of the "automatic documentation" (the _OpenAPI specification_) generated by FastAPI at http://localhost:8000/openapi.json.
302+
2. Search `/users/create`.
303+
3. Open it, click "Try it out".
304+
4. Fill in your email address, and click "Execute".
287305

288-
Create the account:
306+
#### Activating your account
307+
308+
1. Go back to the shell running your Hyperion instance, in the logs look for a link looking like http://localhost:3000/calypsso/activate?activation_token=12345.
309+
2. Copy this activation token.
310+
3. Go again on the swagger and search `/users/activate`.
311+
4. Open it, click "Try it out".
312+
5. Fill in your information, using the `activation_token` you copied (click "Schema" next to "Edit Value" so see what fields are optional), and click "Execute".
313+
314+
### Using the API in command line
315+
316+
> [!TIP]
317+
> On Windows, `curl` is different.
318+
> To get the same results as on Linux and MacOS:
319+
>
320+
> - either replace `curl` with `curl.exe`
321+
> - or run the `curl` commands below in a bash (using WSL or using Git Bash)
322+
323+
#### Registering your account
289324

290325
```bash
291-
curl --location 'http://127.0.0.1:8000/users/create' \
292-
--header 'Content-Type: application/json' \
293-
--data-raw '{
294-
"email": "<...>@etu.ec-lyon.fr",
295-
"account_type": "39691052-2ae5-4e12-99d0-7a9f5f2b0136"
296-
}'
326+
curl --json '{"email": "[email protected]"}' http://localhost:8000/users/create
297327
```
298328

299-
Activate the account:
329+
#### Activating your account
330+
331+
1. Go back to the shell running your Hyperion instance, in the logs look for a link looking like http://localhost:3000/calypsso/activate?activation_token=12345.
332+
2. Copy this activation token.
333+
3. Use this `activation_token` in:
300334

301335
```bash
302-
curl --location 'http://127.0.0.1:8000/users/activate' \
303-
--header 'Content-Type: application/json' \
304-
--data '{
336+
curl --json '{
305337
"name": "<Name>",
306338
"firstname": "<Firstname>",
307339
"nickname": "<Nickname>",
@@ -311,15 +343,18 @@ curl --location 'http://127.0.0.1:8000/users/activate' \
311343
"phone": "<Phone>",
312344
"promo": 0,
313345
"floor": ""
314-
}'
346+
}' http://localhost:8000/users/activate
315347
```
316348

317349
## Make the first user admin
318350

351+
> [!WARNING]
352+
> This may not work if you ran the factories
353+
319354
If there is exactly one user in the database, you can make it admin using the following command:
320355

321356
```bash
322-
curl --location --request POST 'http://127.0.0.1:8000/users/make-admin'
357+
curl -X POST http://localhost:8000/users/make-admin
323358
```
324359

325360
## Install docker or an equivalent

0 commit comments

Comments
 (0)