Logout button for forms Auth and fix UrlBase redirects

pull/2/head
Mark McDowall 10 years ago
parent aa9df49ea2
commit 754c1ea331

@ -4,17 +4,21 @@ using Nancy.Authentication.Forms;
using Nancy.Extensions;
using Nancy.ModelBinding;
using NzbDrone.Core.Authentication;
using NzbDrone.Core.Configuration;
namespace NzbDrone.Api.Authentication
{
public class LoginModule : NancyModule
public class AuthenticationModule : NancyModule
{
private readonly IUserService _userService;
private readonly IConfigFileProvider _configFileProvider;
public LoginModule(IUserService userService)
public AuthenticationModule(IUserService userService, IConfigFileProvider configFileProvider)
{
_userService = userService;
_configFileProvider = configFileProvider;
Post["/login"] = x => Login(this.Bind<LoginResource>());
Get["/logout"] = x => Logout();
}
private Response Login(LoginResource resource)
@ -35,5 +39,10 @@ namespace NzbDrone.Api.Authentication
return this.LoginAndRedirect(user.Identifier, expiry);
}
private Response Logout()
{
return this.LogoutAndRedirect(_configFileProvider.UrlBase + "/");
}
}
}

@ -64,7 +64,7 @@ namespace NzbDrone.Api.Authentication
FormsAuthentication.Enable(pipelines, new FormsAuthenticationConfiguration
{
RedirectUrl = "~/login",
RedirectUrl = _configFileProvider.UrlBase + "/login",
UserMapper = _authenticationService,
CryptographyConfiguration = cryptographyConfiguration
});

@ -83,7 +83,7 @@
</Compile>
<Compile Include="Authentication\AuthenticationService.cs" />
<Compile Include="Authentication\EnableAuthInNancy.cs" />
<Compile Include="Authentication\LoginModule.cs" />
<Compile Include="Authentication\AuthenticationModule.cs" />
<Compile Include="Authentication\LoginResource.cs" />
<Compile Include="Authentication\NzbDroneUser.cs" />
<Compile Include="Blacklist\BlacklistModule.cs" />

@ -1,4 +1,4 @@
var $ = require('jquery');
var $ = require('jquery');
var Backbone = require('backbone');
var Marionette = require('marionette');
var SystemInfoLayout = require('./Info/SystemInfoLayout');
@ -7,6 +7,7 @@ var UpdateLayout = require('./Update/UpdateLayout');
var BackupLayout = require('./Backup/BackupLayout');
var TaskLayout = require('./Task/TaskLayout');
var Messenger = require('../Shared/Messenger');
var StatusModel = require('./StatusModel');
module.exports = Marionette.Layout.extend({
template : 'System/SystemLayoutTemplate',
@ -25,18 +26,22 @@ module.exports = Marionette.Layout.extend({
tasksTab : '.x-tasks-tab'
},
events : {
"click .x-info-tab" : '_showInfo',
"click .x-logs-tab" : '_showLogs',
"click .x-updates-tab" : '_showUpdates',
"click .x-backup-tab" : '_showBackup',
"click .x-tasks-tab" : '_showTasks',
"click .x-shutdown" : '_shutdown',
"click .x-restart" : '_restart'
'click .x-info-tab' : '_showInfo',
'click .x-logs-tab' : '_showLogs',
'click .x-updates-tab' : '_showUpdates',
'click .x-backup-tab' : '_showBackup',
'click .x-tasks-tab' : '_showTasks',
'click .x-shutdown' : '_shutdown',
'click .x-restart' : '_restart'
},
initialize : function(options){
if(options.action) {
this.action = options.action.toLowerCase();
}
this.templateHelpers = {
authentication : StatusModel.get('authentication')
};
},
onShow : function(){
switch (this.action) {

@ -1,4 +1,4 @@
<ul class="nav nav-tabs">
<ul class="nav nav-tabs">
<li><a href="#info" class="x-info-tab no-router">Info</a></li>
<li><a href="#logs" class="x-logs-tab no-router">Logs</a></li>
<li><a href="#updates" class="x-updates-tab no-router">Updates</a></li>
@ -12,6 +12,12 @@
<button class="btn btn-default btn-icon-only x-restart" title="Restart" data-container="body">
<i class="icon-nd-restart"></i>
</button>
{{#if_eq authentication compare="forms"}}
<a href="{{UrlBase}}/logout" class="btn btn-default btn-icon-only" title="Logout" data-container="body">
<i class="icon-lock"></i>
</a>
{{/if_eq}}
</div>
</li>
</ul>

Loading…
Cancel
Save