Commit Graph

39 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
Ben Visness 045a2c2379 Add education toggle to user admin settings 2022-09-10 16:52:02 -05:00
Ben Visness 81d8d4559f Fix bug where Discord settings were cleared while disabled 2022-08-13 14:29:40 -05:00
Ben Visness a0cc2f5c66 Update auth flows 2022-08-13 14:15:00 -05:00
Asaf Gartner efc7d76cb7 Snippet creation and editing 2022-08-06 00:41:37 +03:00
bvisness e9d4300100 Rework requests and middleware (#57)
o boy

Resolves #10 (hopefully!)

Co-authored-by: Ben Visness <bvisness@gmail.com>
Reviewed-on: #57
2022-06-24 21:38:11 +00: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 11dd75ad03 Twitch monitoring 2022-03-22 20:07:43 +02:00
Asaf Gartner f4f439489d Assets for user avatars 2021-12-29 16:38:23 +02:00
Asaf Gartner eb32b04437 Added project links to project edit page 2021-12-26 12:03:25 +02:00
Asaf Gartner 12eb172f98 Log out user after setting status to 'banned' 2021-12-21 06:07:55 +02:00
Asaf Gartner b5eb718615 Query automatically does ToSlice. Use QueryIterator if you need an
iterator.
2021-12-15 03:36:37 +02:00
Asaf Gartner c84b6842e2 Admin actions on user profile 2021-12-15 03:17:42 +02:00
Ben Visness 415ce8db43 Rework project visibility 2021-12-11 13:08:10 -06:00
Ben Visness b88776af0c Cap the number of personal projects per user 2021-12-08 22:02:11 -06:00
Ben Visness 37fcbb205c Move data-fetching helpers to a separate package 2021-12-08 20:04:15 -06:00
Ben Visness 73824a027b Add tag management to projects
Also rearrange that ProjectAndLogos stuff because agh it was so weird
2021-12-07 21:37:52 -06:00
Asaf Gartner 950e84d53a Personal project creation 2021-12-02 12:53:36 +02:00
Asaf Gartner 03c82c9d1a New project form 2021-11-25 05:59:51 +02:00
Ben Visness 0cc879df21 Add tags to snippets on timelines 2021-11-11 11:00:46 -08:00
Ben Visness dfbcfbeacc Use new UrlContext for project URLs
Wow that was a lot to change
2021-11-09 20:11:39 -08:00
Ben Visness a4ad2c5f04 Update data model for personal projects
Also:
- Added a helper for fetching posts with appropriate visibility
- Added personal projects to the project index
2021-11-06 15:25:31 -05:00
Ben Visness f8d5f9fce5 Rework the home page 2021-10-27 21:55:40 -05:00
Ben Visness 09e6a15085 Rejigger timelines to avoid explicit types 2021-10-27 21:55:39 -05: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 36bb2ce2d5 Put timestamp in avatar filenames to avoid cache problems 2021-09-07 19:55:52 -05:00
Asaf Gartner d78a2e8e82 Breadcrumbs 2021-09-01 21:25:09 +03:00
Ben Visness bc39b4c0b7 Clean up TODOs 2021-08-28 12:07:45 -05:00
Asaf Gartner cb5c3c403d Internal server error page 2021-08-28 15:21:40 +03: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
Ben Visness 4f01e1fdcf Add a title to the user profile page 2021-08-17 21:09:42 -05:00
Ben Visness 038ee7e90e Add permission check to the New Post button 2021-08-02 22:27:59 -05:00
Ben Visness 8ecb4a7173 Rework the category/thread data model
Threads can stand alone now. Threads can be attached to resources
directly without requiring a category. In addition, a lot of wiki stuff
and library discussion stuff was deleted because we're not gonna port
it.
2021-07-29 22:49:24 -05:00
Ben Visness e9ba9b3dde Add permission check on post editing 2021-07-21 21:16:10 -05:00
Ben Visness 17e9e0b735 Add MustWriteTemplate func for the common case of panicking 2021-07-17 10:19:17 -05:00
Asaf Gartner a4671c5fb5 Profile page and timeline items 2021-06-22 12:50:40 +03:00