Skip to content

Commit

Permalink
Added logout function to switch user menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
RickDB authored and RickDB committed Jan 2, 2017
1 parent 7f243b2 commit 9437ab5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
1 change: 1 addition & 0 deletions MyAnimePlugin3/Translation.cs
Expand Up @@ -357,6 +357,7 @@ public static string ParseString(string input)
public static string LoadingData = "Loading Data"; public static string LoadingData = "Loading Data";
public static string LocalFiles = "Local Files"; public static string LocalFiles = "Local Files";
public static string LocalMapping= "Local Mapping"; public static string LocalMapping= "Local Mapping";
public static string LogOut = "Log out";
public static string Low = "Low"; public static string Low = "Low";


public static string Main = "Main"; public static string Main = "Main";
Expand Down
36 changes: 33 additions & 3 deletions MyAnimePlugin3/ViewModel/JMMServerVM.cs
Expand Up @@ -462,7 +462,8 @@ public bool PromptUserLogin()
string msgCurUser = string.Format(Translation.CurrentUser, CurrentUser.Username); string msgCurUser = string.Format(Translation.CurrentUser, CurrentUser.Username);


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


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


if (selectedLabel < 0) return false; 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];; 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 // try and auth user with a blank password


Expand All @@ -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) public void SetCurrentUser(JMMUserVM user)
{ {
CurrentUser = user; CurrentUser = user;
Expand Down
23 changes: 14 additions & 9 deletions MyAnimePlugin3/Windows/MainWindow.cs
Expand Up @@ -2311,16 +2311,21 @@ protected override void OnClicked(int controlId, GUIControl control, MediaPortal
}); });
menu.Add(btnSwitchUser, () => menu.Add(btnSwitchUser, () =>
{ {
if (JMMServerVM.Instance.PromptUserLogin()) if (JMMServerVM.Instance.PromptUserLogin())
{ {
Breadcrumbs = new List<History>() { new History() }; 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 // 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.CurrentJMMUserID =
settings.Save(); JMMServerVM.Instance.CurrentUser.JMMUserID.ToString(CultureInfo.InvariantCulture);
settings.Save();
LoadFacade(); LoadFacade();
} }
else
{
LoadFacade();
}
}); });
menu.Add(btnSettings, () => menu.Add(btnSettings, () =>
{ {
Expand Down Expand Up @@ -3106,7 +3111,7 @@ void g_Player_PlayBackEnded(g_Player.MediaType type, string filename)
// Not used at this time // Not used at this time
} }


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

0 comments on commit 9437ab5

Please sign in to comment.