public static bool isAccountCorrect(string username, string password) { FanxiAuthenticationBase _authenticationService = IoC.Resolve <FanxiAuthenticationBase>(); UserIdentity tempId = _authenticationService.Authenticate(username, password); if (tempId == null) { return(false); } FanxiPrincipal _principal = new FanxiPrincipal(tempId); HttpContext.Current.User = _principal; return(true); }
private bool isAccountCorrect(string username, string password) { FanxiAuthenticationBase _authenticationService = IoC.Resolve <FanxiAuthenticationBase>(); UserIdentity tempId = _authenticationService.Authenticate(username, password); if (tempId == null) { return(false); } FanxiPrincipal _principal = new FanxiPrincipal(tempId); HttpContext.Current.User = _principal; if (_Roles != null && _Roles.Length > 0) { IEnumerable <string> TempRoles = (from r in tempId.Roles where _Roles.Contains(r) select r); if (TempRoles == null || TempRoles.Count() == 0) { return(false); } } if (_Permissions != null && _Permissions.Length > 0) { List <string> HasPermission = new List <string>(); IList <IdentityManagement.Domain.role> roles = FX.Core.IoC.Resolve <IroleService>().Query.Where(p => tempId.Roles.Contains(p.name)).ToList(); foreach (var r in roles) { foreach (var per in r.Permissions) { if (HasPermission.Contains(per.name)) { continue; } HasPermission.Add(per.name); } } string[] TempPer = (from per in _Permissions where (!HasPermission.Contains(per)) select per).ToArray(); if (TempPer != null && TempPer.Length > 0) { return(false); } } return(true); }