init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
|
@ -0,0 +1,69 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Web;
|
||||
using Kreta.Naplo.Domain.V3.Common;
|
||||
using Kreta.Naplo.Domain.V3.Enum;
|
||||
|
||||
namespace Kreta.Naplo.WebApi.V3.Common.Logic
|
||||
{
|
||||
internal static class FelhasznaloLogic
|
||||
{
|
||||
public static MobileUser GetFelhasznalo()
|
||||
{
|
||||
return HttpContext.Current.Items.Contains("MobileUser")
|
||||
? (MobileUser)HttpContext.Current.Items["MobileUser"]
|
||||
: new MobileUser(GetInstituteCode(), GetInstituteUserId(), GetUserName(), GetRoles(), GetSchoolYearId(), GetUserIdpUniqueId(), GetInstituteUniqueId());
|
||||
}
|
||||
|
||||
public static string GetInstituteCode()
|
||||
{
|
||||
return GetClaims("kreta:institute_code").Single();
|
||||
}
|
||||
|
||||
private static Guid GetInstituteUniqueId()
|
||||
{
|
||||
return new Guid(GetClaims("kreta:institute_unique_id").Single());
|
||||
}
|
||||
|
||||
public static int GetInstituteUserId()
|
||||
{
|
||||
var claim = GetClaims("kreta:institute_user_id").Single();
|
||||
return int.Parse(claim);
|
||||
}
|
||||
|
||||
public static int GetSchoolYearId()
|
||||
{
|
||||
var claim = GetClaims("kreta:school_year_id").Single();
|
||||
return int.Parse(claim);
|
||||
}
|
||||
|
||||
private static Guid GetUserIdpUniqueId()
|
||||
{
|
||||
return new Guid(GetClaims("kreta:institute_user_idp_unique_id").Single());
|
||||
}
|
||||
|
||||
private static string GetUserName()
|
||||
{
|
||||
return GetClaims("kreta:user_name").Single();
|
||||
}
|
||||
|
||||
public static IEnumerable<FelhasznaloSzerepkor> GetRoles()
|
||||
{
|
||||
var roles = GetClaims(ClaimTypes.Role);
|
||||
foreach (var role in roles)
|
||||
{
|
||||
if (Enum.TryParse(role, out FelhasznaloSzerepkor enumValue))
|
||||
{
|
||||
yield return enumValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetClaims(string type)
|
||||
{
|
||||
return ClaimsPrincipal.Current.Claims.Where(x => x.Type == type).Select(x => x.Value);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue