Commit Graph

23 Commits

Author SHA1 Message Date
bvisness 0210a0784b Add Discord login (#106)
This leverages our existing Discord OAuth implementation. Any users with a linked Discord account will be able to log in immediately. When logging in, we request the `email` scope in addition to `identity`, so existing users will be prompted one time to accept the new permissions. On subsequent logins, Discord will skip the prompt.

When linking your Discord account to an existing HMN account, we continue to only request the `identity` scope, so we do not receive the user's Discord email.

Both login and linking go through the same Discord OAuth callback. All flows through the callback try to achieve the same end goal: a logged-in HMN user with a linked Discord account.

Linking works the same as it ever has. Login, however, is different because we do not have a session ID to use as the OAuth state. To account for this, I have added a `pending_login` table that stores a secure unique ID and the eventual destination URL. These pending logins expire after 10 minutes. When we receive the OAuth callback, we look up the pending login by the OAuth `state` and immediately delete it. The destination URL will be used to redirect the user to the right place.

If we have a `discord_user` entry for the OAuth'd Discord user, we immediately log the user into the associated HMN account. This is the typical login case. If we do not have a `discord_user`, but there is exactly one HMN user with the same email address as the Discord user, we will link the two accounts and log into the HMN account.

(It is possible for multiple HMN accounts to have the same email, because we don't have a uniqueness constraint there. We fail the login in this case rather than link to the wrong account.)

Finally, if no associated HMN user exists, a new one will be created. It will use the Discord user's username, email, and avatar. This user will have no password, but they can set or reset a password through the usual flows.

Co-authored-by: Ben Visness <bvisness@gmail.com>
Reviewed-on: #106
2023-05-06 19:38:50 +00:00
Asaf Gartner 2af28d9f3f Update pgx v4 to pgx v5 2023-01-29 08:53:57 +02:00
Asaf Gartner b165bf7c23 Added panic recovery to all of our background jobs
Fixes issue #32
2022-06-16 00:33:57 +03:00
Ben Visness c1fa6cae13 Integrate Nick's local S3 server
Works like a charm!

Small tweak for clarity
2022-05-14 00:48:19 -05:00
Ben Visness 3a93aa93e9 Seed users (and rework a lot of user access to use new helpers) 2022-05-07 13:58:00 -05:00
Ben Visness 0e56f56372 Rename all the db tables 2022-05-07 08:11:05 -05:00
Ben Visness a147cfa325 Rework DB API
This takes advantage of generics, and generally clears up a lot of
inconsistencies and quality-of-life issues.

Start of db rework: clean up, start generics, improve tests

Write some nice aspirational package docs

Rework and document the db API

Tests still pass, at least...now for everything else

Update all callsites of db functions

Finish converting all callsites

Not too bad actually! Centralizing access into the helpers makes a big
difference.

wtf it works
2022-05-06 16:56:13 -05:00
Asaf Gartner f8985e6ee3 User approval admin page and RSS 2021-09-24 03:13:40 +03:00
Ben Visness 986a42c1ac Switch to centralized helpers for fetching threads/posts
This includes the ability to "shadowban" new users who have not yet been
approved. We do not have UI for approving these users.

Migrate deserving users to new Approved status

Add post fetching helpers as well

The logic in the thread/post stuff is definitely getting redundant, but
I'm not sure I'm yet ready to try to abstract any of it away.

The next thing to do is probably to update blogs and other places that
fetch threads/posts, and delete the old helpers.

Move forums and blogs fully to new helpers

Use the helpers on the landing page too

that was easy!

Fix up some spots I missed

Check user status and use helpers on the profile page
2021-09-22 23:48:31 -05:00
Ben Visness 67b86720a9 Add user edit form
Add most of the user settings backend

still need to do discord lol

Add the Discord settings

Add avatar uploads
2021-08-27 17:18:02 -05:00
Asaf Gartner a32f71f862 Password reset and Notices 2021-08-17 08:18:51 +03:00
Asaf Gartner 4a8d84b303 Only run user cleanup once an hour. Not every 10 seconds. 2021-08-09 11:06:39 +03:00
Asaf Gartner 660f65ba95 Registration flow and email 2021-08-08 23:05:52 +03:00
Ben Visness d11094481f Add CSRF verification 2021-07-04 15:32:07 -05:00
Ben Visness 00b0383030 Start forum editing experience, including bbcode parser 2021-07-04 15:31:37 -05:00
Ben Visness 314ae26e18 Fix feed pagination
And tweak perf log output
2021-04-28 22:34:22 -05:00
Ben Visness 8929a5d749 Start porting landing page; rework db layer a bit 2021-03-30 22:55:19 -05:00
Ben Visness f7ac023c44 Re-hash user's passwords if necessary when they log in 2021-03-28 10:32:30 -05:00
Ben Visness 8f2958594a Add a cron to delete expired sessions 2021-03-27 23:22:29 -05:00
Ben Visness 608d1af195 Add logout 2021-03-27 16:27:40 -05:00
Ben Visness cdfe02726c Get login working 2021-03-27 16:12:22 -05:00
Ben Visness 56cd737203 Add initial auth token / login stuff 2021-03-25 22:33:00 -05:00
Ben Visness acca4fe232 Initial implementation of password-checking 2021-03-21 22:07:18 -05:00