Here's the idea:
1) My Grav site only accepts Github OAuth2 usernames and logins.
2) I want to restrict access to my Grav site based on whether the user has sponsored my project and made a donation.
How would I accomplish this?
Here's the idea:
1) My Grav site only accepts Github OAuth2 usernames and logins.
2) I want to restrict access to my Grav site based on whether the user has sponsored my project and made a donation.
How would I accomplish this?
@Spindizzy,
A few options come to mind:
As mentioned in the README of the Login plugin, there are several events that can be subscribed to in a custom plugin.
onUserLoginAuthorizeAllows plugins to block user from being logged in.
This sounds like a good candidate to add your own logic, to either read the list of sponsors online, or read an offline copy of the list.
Im thinking of doing a combination of #2 and #3. i have a Flarum forum running under Grav that has a REST api to synchronize accounts between Grav and Flarum, as well as get the Group the user is in on the Flarum side of things.
So what I want to do is, when the user logs into Grav, OnUserLogin in a custom plugin can get the group the user is in from Flarum, and synchronize it. So how would I change the user's group in a Grav plugin?
@Spindizzy, There are some docs chapters you might want to read:
I understand how to do it from the Admin panel and manually but how would i do it inside a plugin?
@Spindizzy,
So how would I change the user’s group in a Grav plugin?
Assuming the relevant Flarum group(s) has/have already been created in Grav, you might try something like:
public function onUserLoginAuthorize(Event $event)
{
/** @var User */
$user = $event['user'];
$groups = $user->groups;
// Get flarum group of user
$flarum_group = ...
if (!$groups) {
$user->groups = [$flarum_group];
} else if (!in_array($flarum_group, $groups)) {
array_push($groups, $flarum_group);
$user->groups = $groups;
}
$user->save();
}
exactly what i needed - thanks!
Log in to reply.
| Topic | Participants | Replies | Views | Activity |
|---|---|---|---|---|
| 2 | 133 | 1 day ago | ||
| 1 | 93 | 1 day ago | ||
| 0 | 77 | 2 days ago | ||
| 6 | 387 | 5 days ago | ||
| 3 | 72 | 6 days ago |