public IUser GetLoggedInUser(IContext context) { string[] header; if (!context.Request.Headers.TryGetValue("Authorization", out header)) return null; if (header == null || header.Length != 1) return null; var user = HttpRuntime.Cache.Get(header[0]) as IgorUser; if (user != null) return user; var dict = ConnectionStringParser.ParseConnectionString(header[0]); if (!(dict.ContainsKey("User") && dict.ContainsKey("Password"))) return null; user = new IgorUser(dict["User"], Uri.UnescapeDataString(dict["Password"])); var site = _settingsHelper.GetSites().First(); var client = _clientHelper.GetWebSiteExtensionsClient(site, user.Name, user.Password); try { var task = client.Settings.ListAsync(CancellationToken.None); task.Wait(); if (task.IsFaulted || task.IsCanceled) return null; HttpRuntime.Cache[header[0]] = user; return user; } catch (Exception) { return null; } }
public IUser GetLoggedInUser(IContext context) { string[] header; if (!context.Request.Headers.TryGetValue("Authorization", out header)) { return(null); } if (header == null || header.Length != 1) { return(null); } var user = HttpRuntime.Cache.Get(header[0]) as IgorUser; if (user != null) { return(user); } var dict = ConnectionStringParser.ParseConnectionString(header[0]); if (!(dict.ContainsKey("User") && dict.ContainsKey("Password"))) { return(null); } user = new IgorUser(dict["User"], Uri.UnescapeDataString(dict["Password"])); var site = _settingsHelper.GetSites().First(); var client = _clientHelper.GetWebSiteExtensionsClient(site, user.Name, user.Password); try { var task = client.Settings.ListAsync(CancellationToken.None); task.Wait(); if (task.IsFaulted || task.IsCanceled) { return(null); } HttpRuntime.Cache[header[0]] = user; return(user); } catch (Exception) { return(null); } }