Initial ...
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Models;
|
||||
|
||||
namespace xIdentityHelper.Extensions
|
||||
{
|
||||
public static class XIdentityHelperExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Check User Claims ia Admin Role or not ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsAdmin(this XUserClaimsInfoDto source)
|
||||
{
|
||||
//
|
||||
var result = false;
|
||||
|
||||
//
|
||||
if (source.IsNull() ||
|
||||
source.Roles.IsNull() ||
|
||||
!source.Roles.HasChild())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = source.Roles.Contains(XUserRoles.ADMIN);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Actor is Valid for UserSelectByParam or not ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="userSelectByParam"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsValidActor(this XUserClaimsInfoDto source, string userSelectByParam)
|
||||
{
|
||||
//
|
||||
var result = false;
|
||||
|
||||
//
|
||||
if (source.IsNull() ||
|
||||
userSelectByParam.IsNullOrEmpty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isAdmin = source.IsAdmin();
|
||||
result = isAdmin ||
|
||||
userSelectByParam == source.Email ||
|
||||
userSelectByParam == source.UserId ||
|
||||
userSelectByParam == source.UserName ||
|
||||
userSelectByParam == source.PhoneNumber;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user