YAFLogo

McHine
  • McHine
  • 52.6% (Neutral)
  • YAF Forumling Topic Starter YAF Version: 4.0.8 beta
a month ago
Looking to expose the roles in order to do some authorisation control.

Seems using boardcontext I can get most of the existing ones .membershipuser .isforumadmin etc (please correct if i'm wrong).

I have added two (Crew and Owner if you want to know), and want to access those to change website behaviours.

How to?

Thanks a millon!

Sponsor
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
a month ago
If you want to check if the Current user is part of a role use ...

​await BoardContext.Current.Get<IAspNetUsersHelper>().IsUserInRoleAsync(BoardContext.Current.MembershipUser, "Crew");
McHine
  • McHine
  • 52.6% (Neutral)
  • YAF Forumling Topic Starter YAF Version: 4.0.8 beta
21 days ago
ok that is working pretty well, for example currently using this in pages needing to have user logged in:

bool RegUser = await BoardContext.Current.Get().IsUserInRoleAsync(BoardContext.Current.MembershipUser, "Registered Users");

if (!RegUser)

{ Nav.NavigateTo("/Forums/Account/Login", true); }

but.....

what about banned and suspended users, are they considered Registered Users? probably a noob question or easily found (happy to be shown where to look for this kind of thing, struggling with trawling so asking early!)

thanks again getting closer and closer to first looks :)

tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
21 days ago
if you want to check if the user is registered just check for guest

​if (BoardContext.Current.IsGuest)
{
    Nav.NavigateTo("/Forums/Account/Login", true);
}

Banned Users are deleted users and are treated as guest, and as suspended users they only see a blank page.

Users browsing this topic