Skip to content

Commit efa8f05

Browse files
committed
About launching Hyperion and creating your own admin user
1 parent 9004c45 commit efa8f05

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
@@ -253,53 +253,85 @@ The `config.yaml` contains environment variables that are internal to the Python
253253

254254
## Launch the API
255255

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

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

262-
See [migrations README](./migrations/README)
274+
## Create your own user
263275

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

266-
## OpenAPI specification
279+
### With CalypSSO
267280

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

270-
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.
283+
Go to http://localhost:8000/calypsso/register and type a valid email address to register (start the creation of) your account.
271284

272-
## Create the first user
285+
#### Activating your account
273286

274-
You can create the first user either using Titan or calling the API directly.
287+
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.
288+
Open it and activate (end the creation of) your account.
275289

276-
> You need to use an email with the format `[email protected]` or `[email protected]`
290+
### With Titan
277291

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

280-
### With Titan
295+
### Using the API through the swagger
281296

282-
Press "Créer un compte" on the first page and follow the process.
297+
#### Registering your account
283298

284-
### Using the API directly
299+
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.
300+
2. Search `/users/create`.
301+
3. Open it, click "Try it out".
302+
4. Fill in your email address, and click "Execute".
285303

286-
Create the account:
304+
#### Activating your account
305+
306+
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.
307+
2. Copy this activation token.
308+
3. Go again on the swagger and search `/users/activate`.
309+
4. Open it, click "Try it out".
310+
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".
311+
312+
### Using the API in command line
313+
314+
> [!TIP]
315+
> On Windows, `curl` is different.
316+
> To get the same results as on Linux and MacOS:
317+
>
318+
> - either replace `curl` with `curl.exe`
319+
> - or run the `curl` commands below in a bash (using WSL or using Git Bash)
320+
321+
#### Registering your account
287322

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

297-
Activate the account:
327+
#### Activating your account
328+
329+
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.
330+
2. Copy this activation token.
331+
3. Use this `activation_token` in:
298332

299333
```bash
300-
curl --location 'http://127.0.0.1:8000/users/activate' \
301-
--header 'Content-Type: application/json' \
302-
--data '{
334+
curl --json '{
303335
"name": "<Name>",
304336
"firstname": "<Firstname>",
305337
"nickname": "<Nickname>",
@@ -309,15 +341,18 @@ curl --location 'http://127.0.0.1:8000/users/activate' \
309341
"phone": "<Phone>",
310342
"promo": 0,
311343
"floor": ""
312-
}'
344+
}' http://localhost:8000/users/activate
313345
```
314346

315347
## Make the first user admin
316348

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

319354
```bash
320-
curl --location --request POST 'http://127.0.0.1:8000/users/make-admin'
355+
curl -X POST http://localhost:8000/users/make-admin
321356
```
322357

323358
## Install docker or an equivalent

0 commit comments

Comments
 (0)