protected bool LoadUser(User user, string pw, bool authenticate = true) { ShowSplash = true; Kernel.ApiClient.CurrentUserId = user.Id; if (authenticate) { try { if (!string.IsNullOrEmpty(pw)) { //Logger.ReportVerbose("Authenticating with pw: {0} ({1})",CustomPINEntry, pw); Kernel.ApiClient.AuthenticateUserWithHash(user.Id, pw); //If we get here the pw was correct - save it so we can use it if automatically logging in user.PwHash = pw; } else { Kernel.ApiClient.AuthenticateUser(user.ApiId, pw); } } catch (HttpException e) { if (((WebException)e.InnerException).Status == WebExceptionStatus.ProtocolError) { if (!UsingDirectEntry) { Application.MediaCenterEnvironment.Dialog("Incorrect Password.", "Access Denied", DialogButtons.Ok, 100, true); } UsingDirectEntry = false; ShowSplash = false; return false; } throw; } } LoggedIn = true; // load server config try { Kernel.ServerConfig = Kernel.ApiClient.GetServerConfiguration(); } catch (Exception e) { Logger.ReportException("Error getting server configuration", e); } // re-load server info now that we have authorization for the whole thing Kernel.ServerInfo = Kernel.ApiClient.GetSystemInfo(); Kernel.Instance.CommonConfigData.LastServerMacAddress = Kernel.ServerInfo.MacAddress; Kernel.Instance.CommonConfigData.Save(); // load user config Kernel.Instance.LoadUserConfig(); // and server-based user prefs ServerUserConfig = new UserConfig(Kernel.CurrentUser.Dto.Configuration); // init activity timer ActivityTimerInterval = Config.InputActivityTimeout * 1000; _inputActivityTimer.Elapsed += _activityTimerElapsed; // setup styles and fonts with user options try { CustomResourceManager.SetupStylesMcml(null, Config.Instance); CustomResourceManager.SetupFontsMcml(null, Config.Instance); } catch (Exception ex) { Application.MediaCenterEnvironment.Dialog(ex.Message, "Error", DialogButtons.Ok, 100, true); Application.ApplicationContext.CloseApplication(); return false; } // load root Kernel.Instance.ReLoadRoot(); // get server plug-ins var plugins = Kernel.ApiClient.GetServerPlugins(); Kernel.ServerPlugins = plugins != null ? plugins.ToList() : new List<PluginInfo>(); LoadPluginsAndModels(); // build switch user menu BuildUserMenu(); if (Kernel.Instance.RootFolder == null) { Async.Queue(Async.ThreadPoolName.LaunchError, () => { MessageBox("Unable to retrieve root folder. Application will exit."); Close(); }); } else { Logger.ReportInfo("*** Theme in use is: " + Config.ViewTheme); //Launch into our entrypoint Application.UIDeferredInvokeIfRequired(() => LaunchEntryPoint(EntryPointResolver.EntryPointPath)); } //load plug-in catalog info if (user.Dto.Policy.IsAdministrator) { Async.Queue(Async.ThreadPoolName.PackageLoad,() => { LoadPackages(); RefreshPluginCollections(); }); } //supporter nag if (Kernel.Instance.CommonConfigData.LastNagDate == DateTime.MinValue || Kernel.Instance.CommonConfigData.LastNagDate > DateTime.Now || DateTime.Now > Kernel.Instance.CommonConfigData.LastNagDate.AddDays(2)) { Async.Queue(Async.ThreadPoolName.SupporterCheck, () => { var supporter = MBRegistration.GetRegistrationStatus("mbsupporter", Kernel.Instance.Version); while (!supporter.RegChecked) { Thread.Sleep(500);} if (!supporter.IsRegistered) { PopoutMessage("Please Support Media Browser", "Please become a Media Browser Supporter. Go to your server dashboard Help/Become a Supporter. Thanks!"); Kernel.Instance.CommonConfigData.LastNagDate = DateTime.Now; Kernel.Instance.CommonConfigData.Save(); } },10000); } return true; }
protected bool LoadUser(User user, string pw) { ShowSplash = true; Kernel.ApiClient.CurrentUserId = user.Id; try { if (!string.IsNullOrEmpty(pw)) { //Logger.ReportVerbose("Authenticating with pw: {0} ({1})",CustomPINEntry, pw); Kernel.ApiClient.AuthenticateUserWithHash(user.Id, pw); //If we get here the pw was correct - save it so we can use it if automatically logging in user.PwHash = pw; } else { Kernel.ApiClient.AuthenticateUser(user.ApiId, pw); } } catch (Model.Net.HttpException e) { if (((System.Net.WebException)e.InnerException).Status == System.Net.WebExceptionStatus.ProtocolError) { if (!UsingDirectEntry) { AddInHost.Current.MediaCenterEnvironment.Dialog("Incorrect Password.", "Access Denied", DialogButtons.Ok, 100, true); } UsingDirectEntry = false; ShowSplash = false; return false; } throw; } LoggedIn = true; // load user config Kernel.Instance.LoadUserConfig(); // setup styles and fonts with user options try { CustomResourceManager.SetupStylesMcml(AddInHost.Current, Config.Instance); CustomResourceManager.SetupFontsMcml(AddInHost.Current, Config.Instance); } catch (Exception ex) { AddInHost.Current.MediaCenterEnvironment.Dialog(ex.Message, "Error", DialogButtons.Ok, 100, true); AddInHost.Current.ApplicationContext.CloseApplication(); return false; } // load root Kernel.Instance.ReLoadRoot(); LoadPluginsAndModels(); // build switch user menu BuildUserMenu(); if (Kernel.Instance.RootFolder == null) { Async.Queue("Launch Error", () => { MessageBox("Unable to retrieve root folder. Application will exit."); Close(); }); } else { Logger.ReportInfo("*** Theme in use is: " + Config.ViewTheme); //Launch into our entrypoint if (Microsoft.MediaCenter.UI.Application.ApplicationThread != Thread.CurrentThread) { Microsoft.MediaCenter.UI.Application.DeferredInvoke(_ => LaunchEntryPoint(EntryPointResolver.EntryPointPath)); } else { LaunchEntryPoint(EntryPointResolver.EntryPointPath); } } //load plug-in catalog info if (user.Dto.Configuration.IsAdministrator) { Async.Queue("PackageLoad",() => { LoadPackages(); RefreshPluginCollections(); }); } return true; }