-
Notifications
You must be signed in to change notification settings - Fork 0
BE-18 Email confirmation #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1987ed4
Complete the email verification loop again
elffjs 249d89d
More error responses, validate emails
elffjs 7532cc9
README
elffjs 890da6f
Basic instructions
elffjs 9f01deb
More error cleanup
elffjs db9e394
Tidy
elffjs 97f79e9
Some cleanup
elffjs 988dc38
Keyset URL configuration
elffjs 25f3726
Merge branch 'main' into BE-18-email-confirmation
elffjs f7403be
Linting
elffjs c59ee55
Id -> ID
elffjs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
### Running the app | ||
|
||
Make a copy of the settings file and edit as you see fit: | ||
```sh | ||
cp settings.sample.yaml settings.yaml | ||
``` | ||
If you kept the default database and SMTP server settings then you'll want to start up the respective containers: | ||
```sh | ||
docker-compose up -d | ||
``` | ||
This runs Postgres on port 5432; and [Mailhog](https://github.com/mailhog/MailHog) on port 1025 with a [web interface](http://localhost:8025) on port 8025. | ||
|
||
With a fresh database you'll want to run the migrations: | ||
```sh | ||
go run ./cmd/users-api migrate | ||
``` | ||
Finally, running the app is simple: | ||
```sh | ||
go run ./cmd/users-api | ||
``` | ||
|
||
### Endpoints | ||
|
||
`GET /user` | ||
|
||
`200` | ||
|
||
Response | ||
```json | ||
{ | ||
"id": "de5817c0-57a6-11ec-bf63-0242ac130002", | ||
"email": "[email protected]", | ||
"email_verified": true | ||
} | ||
``` | ||
|
||
`PUT /user` | ||
|
||
JSON body | ||
```json | ||
{ | ||
"email": "[email protected]" | ||
} | ||
``` | ||
|
||
`200` | ||
|
||
Response | ||
```json | ||
{ | ||
"id": "de5817c0-57a6-11ec-bf63-0242ac130002", | ||
"email": "[email protected]", | ||
"email_verified": false | ||
} | ||
``` | ||
|
||
`POST /send-confirmation-email` | ||
|
||
`POST /confirm-email` | ||
|
||
JSON body | ||
|
||
```json | ||
{ | ||
"key": "60412984" | ||
} | ||
``` | ||
|
||
`200` | ||
|
||
`400` | ||
|
||
This can fail for a few reasons: | ||
|
||
- We already confirmed the email | ||
- We never sent a confirmation email for the current candidate email address | ||
- The confirmation key expired; the default timeout for this is 15 minutes | ||
- The submitted key does not match the one we've stored |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/golang-jwt/jwt/v4" | ||
) | ||
|
||
func errorResponseHandler(c *fiber.Ctx, err error, status int) error { | ||
msg := "" | ||
if err != nil { | ||
msg = err.Error() | ||
} | ||
return c.Status(status).JSON(fiber.Map{ | ||
"error_message": msg, | ||
}) | ||
} | ||
|
||
func getUserID(c *fiber.Ctx) string { | ||
token := c.Locals("user").(*jwt.Token) | ||
claims := token.Claims.(jwt.MapClaims) | ||
userID := claims["sub"].(string) | ||
return userID | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for readme