| 1 | # Use-case 0001 Implementation — Register
|
|---|
| 2 |
|
|---|
| 3 | **Initiating actor:** Visitor. **Source file:** `server/auth.go`, function `Register`.
|
|---|
| 4 |
|
|---|
| 5 | ## Scenario (implemented)
|
|---|
| 6 |
|
|---|
| 7 | 1. **User** chooses option `[1] Register` from the anonymous menu.
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 | 2. **System** prompts for username, email, full name and password (`server/auth.go:20-23`).
|
|---|
| 11 |
|
|---|
| 12 | 3. **User** enters the values.
|
|---|
| 13 |
|
|---|
| 14 | 4. **System** validates (empty checks, `@` in email, ≥ 6 chars in password) and then asks the database:
|
|---|
| 15 |
|
|---|
| 16 | ```sql
|
|---|
| 17 | SELECT EXISTS(
|
|---|
| 18 | SELECT 1 FROM users WHERE username = $1 OR email = $2
|
|---|
| 19 | );
|
|---|
| 20 | ```
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | 5. **System** inserts the new row (password hashed in Go, not in SQL, to keep hashing identical between register and login):
|
|---|
| 24 |
|
|---|
| 25 | ```sql
|
|---|
| 26 | INSERT INTO users (username, email, full_name, password_hash, available_balance)
|
|---|
| 27 | VALUES ($1, $2, $3, $4, 0);
|
|---|
| 28 | ```
|
|---|
| 29 |
|
|---|
| 30 | 6. **System** confirms: `Account created. You can now log in.`
|
|---|
| 31 |
|
|---|
| 32 | 
|
|---|
| 33 |
|
|---|
| 34 | ## How to reproduce
|
|---|
| 35 |
|
|---|
| 36 | ```sh
|
|---|
| 37 | ./eduberza -init # optional: reset to a known state
|
|---|
| 38 | ./eduberza
|
|---|
| 39 | # choose [1] Register, then enter username / email / full name / password
|
|---|
| 40 | ```
|
|---|
| 41 |
|
|---|
| 42 | The screenshot above is from an actual run: registering `marko` /
|
|---|
| 43 | `marko@example.com`, followed by the confirmation line.
|
|---|