public IUser ValidateHash(string Hash, string ApiKey) { try { var logins = from login in _loginsRepository.Table where login.Hash == Hash select login; if (logins == null) { return(null); } var loginrecord = logins.FirstOrDefault(); if (loginrecord == null) { return(null); } var data = _encryptionService.Decode(Convert.FromBase64String(loginrecord.Hash)); var xml = Encoding.UTF8.GetString(data); var element = XElement.Parse(xml); DateTime validateByUtc; string appid = element.Attribute("ai").Value; string userid = element.Attribute("ui").Value; validateByUtc = DateTime.Parse(element.Attribute("utc").Value, CultureInfo.InvariantCulture); if (_clock.UtcNow <= validateByUtc) { int aid; ApplicationRecord app = null; if (Int32.TryParse(appid, out aid)) { app = _applicationsService.GetApplication(aid); } if (app != null && app.AppKey == ApiKey) { int uid; if (Int32.TryParse(userid, out uid)) { return(GetUser(uid)); } } } else { _loginsRepository.Delete(loginrecord); return(null); } } catch { return(null); } return(null); }
public IQueryable <UserRole> GetRoles(string username = null, string Hash = null) { IUser user = null; ApplicationRecord app = null; if (string.IsNullOrWhiteSpace(username)) { if (_orchardServices.WorkContext.CurrentUser == null) { return(null); } else { username = _orchardServices.WorkContext.CurrentUser.UserName; } Hash = null; } // if hash is null then we can only return data for current user if (Hash == null) { try { string appid = _orchardServices.WorkContext.HttpContext.Session["doticca_aid"].ToString(); if (string.IsNullOrWhiteSpace(appid)) { return(null); } int aid; if (!Int32.TryParse(appid, out aid)) { return(null); } user = _orchardServices.WorkContext.CurrentUser; if (user.UserName.ToLower() != username.ToLower()) { return(null); } app = _applicationsService.GetApplication(aid); if (app == null) { return(null); } } catch { return(null); } } //else //{ // user = _membershipService.GetUser(username); // if(user == null) return null; // app = _applicationsService.GetApplicationByKey(appID); // if(app == null) return null; //} // get roles from service IEnumerable <UserRoleRecord> roles = _profileService.GetUserRoles(user.As <UserProfilePart>(), app); // create a new list List <UserRole> Roles = new List <UserRole>(); foreach (UserRoleRecord role in roles) { Roles.Add(new UserRole(user, role, Request)); } return(Roles.AsQueryable()); }