41 lines
823 B
C#
41 lines
823 B
C#
namespace Library;
|
|
public static class ContextExtensions
|
|
{
|
|
public static void SetUserID( this HttpContext context , int id )
|
|
{
|
|
context.Items.Add( "CONTEXT_USER_ID" , id );
|
|
}
|
|
|
|
public static int GetUserID( this HttpContext context )
|
|
{
|
|
if ( !context.Items.TryGetValue( "CONTEXT_USER_ID" , out object? value ) )
|
|
return 0;
|
|
|
|
if ( value == null )
|
|
return 0;
|
|
|
|
if ( value is int v )
|
|
return v;
|
|
|
|
return 0;
|
|
}
|
|
|
|
public static void SetSystemAdmin( this HttpContext context , bool is_admin )
|
|
{
|
|
context.Items.Add( "CONTEXT_IS_ADMIN" , is_admin );
|
|
}
|
|
|
|
public static bool IsSystemAdmin( this HttpContext context )
|
|
{
|
|
if ( !context.Items.TryGetValue( "CONTEXT_IS_ADMIN" , out object? value ) )
|
|
return false;
|
|
|
|
if ( value == null )
|
|
return false;
|
|
|
|
if ( value is bool v )
|
|
return v;
|
|
|
|
return false;
|
|
}
|
|
} |