Permalink
Browse files

Added logout function to switch user menu.

  • Loading branch information...
RickDB committed Jan 2, 2017
1 parent 7f243b2 commit 9437ab57c64ea94f8492763821396e9c0548b2fa
Showing with 48 additions and 12 deletions.
  1. +1 −0 MyAnimePlugin3/Translation.cs
  2. +33 −3 MyAnimePlugin3/ViewModel/JMMServerVM.cs
  3. +14 −9 MyAnimePlugin3/Windows/MainWindow.cs
@@ -357,6 +357,7 @@ public static string ParseString(string input)
public static string LoadingData = "Loading Data";
public static string LocalFiles = "Local Files";
public static string LocalMapping= "Local Mapping";
public static string LogOut = "Log out";
public static string Low = "Low";

public static string Main = "Main";
@@ -462,7 +462,8 @@ public bool PromptUserLogin()
string msgCurUser = string.Format(Translation.CurrentUser, CurrentUser.Username);

dlg.Add(msgCurUser);
dlg.Add("--------");
dlg.Add("--------");
dlg.Add(">> " + Translation.LogOut);
}

List<JMMUserVM> allUsers = JMMServerHelper.GetAllUsers();
@@ -473,10 +474,16 @@ public bool PromptUserLogin()
selectedLabel = dlg.SelectedLabel;

if (selectedLabel < 0) return false;
if (CurrentUser != null) selectedLabel = selectedLabel - 2;
if (CurrentUser != null) selectedLabel = selectedLabel - 3;

if (dlg.SelectedLabelText == ">> " + Translation.LogOut)
{
LogOut(true);
return false;
}
JMMUserVM selUser = allUsers[selectedLabel];;

BaseConfig.MyAnimeLog.Write("selected user label: " + selectedLabel.ToString());
BaseConfig.MyAnimeLog.Write("Selected user label: " + selectedLabel);

// try and auth user with a blank password

@@ -502,6 +509,29 @@ public bool PromptUserLogin()

}

public void LogOut(bool returnToHome)
{
CurrentUser = null;
Username = "";
IsAdminUser = false;
UserAuthenticated = false;

MainWindow.isFirstInitDone = false;

if (returnToHome)
{
// Set home window message for use later
var msgHome = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0,
(int) GUIWindow.Window.WINDOW_HOME, 00432100, null);

if (BaseConfig.Settings.BasicHome)
msgHome = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0,
(int) GUIWindow.Window.WINDOW_SECOND_HOME, 00432100, null);

GUIWindowManager.SendThreadMessage(msgHome);
}
}

public void SetCurrentUser(JMMUserVM user)
{
CurrentUser = user;
@@ -2311,16 +2311,21 @@ protected override void OnClicked(int controlId, GUIControl control, MediaPortal
});
menu.Add(btnSwitchUser, () =>
{
if (JMMServerVM.Instance.PromptUserLogin())
{
Breadcrumbs = new List<History>() { new History() };
if (JMMServerVM.Instance.PromptUserLogin())
{
Breadcrumbs = new List<History>() {new History()};

// user has logged in, so save to settings so we will log in as the same user next time
settings.CurrentJMMUserID = JMMServerVM.Instance.CurrentUser.JMMUserID.ToString(CultureInfo.InvariantCulture);
settings.Save();
// user has logged in, so save to settings so we will log in as the same user next time
settings.CurrentJMMUserID =
JMMServerVM.Instance.CurrentUser.JMMUserID.ToString(CultureInfo.InvariantCulture);
settings.Save();

LoadFacade();
}
LoadFacade();
}
else
{
LoadFacade();
}
});
menu.Add(btnSettings, () =>
{
@@ -3106,7 +3111,7 @@ void g_Player_PlayBackEnded(g_Player.MediaType type, string filename)
// Not used at this time
}

static bool isFirstInitDone = false;
public static bool isFirstInitDone = false;
private void OnFirstStart()
{
if (isFirstInitDone)

0 comments on commit 9437ab5

Please sign in to comment.