Added user logout method and unit tests to cover it

This commit is contained in:
tidusjar 2016-03-09 12:59:07 +00:00
parent 55560611e8
commit 759540c837
4 changed files with 51 additions and 6 deletions

View file

@ -27,6 +27,7 @@
using System.Linq;
using Nancy;
using Nancy.Extensions;
using Nancy.Responses.Negotiation;
using PlexRequests.Api.Interfaces;
@ -46,6 +47,7 @@ namespace PlexRequests.UI.Modules
Api = api;
Get["/"] = _ => Index();
Post["/"] = x => LoginUser();
Get["/logout"] = x => Logout();
}
private ISettingsService<AuthenticationSettings> AuthService { get; }
@ -104,6 +106,15 @@ namespace PlexRequests.UI.Modules
: new JsonResponseModel { Result = false, Message = "Incorrect User or Password"});
}
private Response Logout()
{
if (Session[SessionKeys.UsernameKey] != null)
{
Session.Delete(SessionKeys.UsernameKey);
}
return Context.GetRedirect("~/userlogin");
}
private bool CheckIfUserIsInPlexFriends(string username, string authToken)
{
var users = Api.GetUsers(authToken);