YAFLogo

McHine
  • McHine
  • 64.6% (Friendly)
  • YAF Forumling Topic Starter YAF Version: 4.0.0 RC4
a month ago
Hi,

i'd like to know the code to ban a user in c# and directly from an ms sql stored procedure, please.

would be a permaban, but not a deleting, would allow them to appeal, but that's admin you don't need/want to know.

thanks a mil

Sponsor
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.1 BETA
a month ago
Technically there is no feature to directly ban a user. There is a kill user feature which deletes the user and bans the email, ip and user name. 

But since you dont wont to delete the user you can use the suspend user feature. Where you can suspend the user for an x amount of time. You can do this via code (there are no stored procedures in yaf)

​ BoardContext.Current.GetRepository<User>().Suspend(
     userId,
     suspendDateTime,
     "SuspendedReason",
     userIDoftheuserthatdidthesuspension);

McHine
  • McHine
  • 64.6% (Friendly)
  • YAF Forumling Topic Starter YAF Version: 4.0.0 RC4
a month ago
of course this particular part is being done through the db!

I'll make a plan pulling a user id to ban out of the stored procs on my side. 

suspendDateTime: this is the time until which they are suspended?

cheers bruv, greatly apprecaited!

tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.1 BETA
a month ago

suspendDateTime: this is the time until which they are suspended?

Originally Posted by: McHine 

Correct 

McHine
  • McHine
  • 64.6% (Friendly)
  • YAF Forumling Topic Starter YAF Version: 4.0.0 RC4
14 days ago
ok that's workign fairly well, although have hardly tested under load or extensiely yet, one this is i don't want mods admin or crew to be banned automatically, 

currently using this to check if the page user is within those roles

// Check if user is admin/crew


bool isAdminOrCrew =


    await BoardContext.Current.Get().IsUserInRoleAsync(BoardContext.Current.MembershipUser, "Crew") ||


    await BoardContext.Current.Get().IsUserInRoleAsync(BoardContext.Current.MembershipUser, "Administrators") ||


    await BoardContext.Current.Get().IsUserInRoleAsync(BoardContext.Current.MembershipUser, "Moderator");

i'd like to run something like this 

bool isSuspAdminOrCrew =


    await BoardContext.Current.Get().IsUserInRoleAsync(  userId, "Crew") ||


    await BoardContext.Current.Get().IsUserInRoleAsync(  userId, "Administrators") ||


    await BoardContext.Current.Get().IsUserInRoleAsync(  userId, "Moderator");





if (!isSuspAdminOrCrew)


{BoardContext.Current.GetRepository().Suspend(


    userId,


    suspendDateTime,


    "SuspendedReason",


    userIDoftheuserthatdidthesuspension);}

but 

await BoardContext.Current.Get().IsUserInRoleAsync(  userId, "Crew")

that doesn't work, and forgive but my brain is too tired to spend another half an hour looking to ask you in the end anyways. 

the time is greatly apprecaited! I think you can tell this is getting close to a first launch, which means after i'm going to ask you even funkier integrations :)

tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.1 BETA
14 days ago
Just one thing dont check for each role separate. Just get all roles and then check if the role exist...

​  var roles = await this.Get<IAspNetUsersHelper>().GetUserRolesAsync(user);

  var isSuspAdminOrCrew = roles.Any(x => x is "Crew" or "Administrators" or "Moderator");