Cleaned up auth settings

This commit is contained in:
kay.one 2013-07-14 00:00:50 -07:00
parent e046d2c680
commit 0c5827fb41
11 changed files with 112 additions and 105 deletions

View File

@ -1,14 +1,12 @@
using Nancy.Authentication.Basic; using Nancy.Authentication.Basic;
using Nancy.Security; using Nancy.Security;
using NzbDrone.Common;
using NzbDrone.Common.Model;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
namespace NzbDrone.Api.Authentication namespace NzbDrone.Api.Authentication
{ {
public interface IAuthenticationService : IUserValidator public interface IAuthenticationService : IUserValidator
{ {
AuthenticationType AuthenticationType { get; } bool Enabled { get; }
} }
public class AuthenticationService : IAuthenticationService public class AuthenticationService : IAuthenticationService
@ -22,25 +20,29 @@ namespace NzbDrone.Api.Authentication
_configFileProvider = configFileProvider; _configFileProvider = configFileProvider;
} }
public AuthenticationType AuthenticationType
{
get { return _configFileProvider.AuthenticationType; }
}
public IUserIdentity Validate(string username, string password) public IUserIdentity Validate(string username, string password)
{ {
if (AuthenticationType == AuthenticationType.Anonymous) if (!Enabled)
{ {
return AnonymousUser; return AnonymousUser;
} }
if (_configFileProvider.BasicAuthUsername.Equals(username) && if (_configFileProvider.Username.Equals(username) &&
_configFileProvider.BasicAuthPassword.Equals(password)) _configFileProvider.Password.Equals(password))
{ {
return new NzbDroneUser { UserName = username }; return new NzbDroneUser { UserName = username };
} }
return null; return null;
} }
public bool Enabled
{
get
{
return _configFileProvider.AuthenticationEnabled;
}
}
} }
} }

View File

@ -1,7 +1,6 @@
using Nancy; using Nancy;
using Nancy.Authentication.Basic; using Nancy.Authentication.Basic;
using Nancy.Bootstrapper; using Nancy.Bootstrapper;
using NzbDrone.Common.Model;
namespace NzbDrone.Api.Authentication namespace NzbDrone.Api.Authentication
{ {
@ -28,7 +27,7 @@ namespace NzbDrone.Api.Authentication
private Response RequiresAuthentication(NancyContext context) private Response RequiresAuthentication(NancyContext context)
{ {
Response response = null; Response response = null;
if (context.CurrentUser == null && _authenticationService.AuthenticationType != AuthenticationType.Anonymous) if (context.CurrentUser == null && _authenticationService.Enabled)
{ {
response = new Response { StatusCode = HttpStatusCode.Unauthorized }; response = new Response { StatusCode = HttpStatusCode.Unauthorized };
} }

View File

@ -128,19 +128,9 @@ namespace NzbDrone.Common.Test
[Test] [Test]
public void GetAuthenticationType_No_Existing_Value() public void GetAuthenticationType_No_Existing_Value()
{ {
var result = Subject.AuthenticationType; var result = Subject.AuthenticationEnabled;
result.Should().Be(AuthenticationType.Anonymous); result.Should().Be(false);
}
[Test]
public void GetAuthenticationType_Basic()
{
Subject.SetValue("AuthenticationType", AuthenticationType.Basic);
var result = Subject.AuthenticationType;
result.Should().Be(AuthenticationType.Basic);
} }
[Test] [Test]

View File

@ -1,10 +0,0 @@
using System.Linq;
namespace NzbDrone.Common.Model
{
public enum AuthenticationType
{
Anonymous,
Basic
}
}

View File

@ -149,7 +149,6 @@
<Compile Include="ConsoleService.cs" /> <Compile Include="ConsoleService.cs" />
<Compile Include="Contract\ReportBase.cs" /> <Compile Include="Contract\ReportBase.cs" />
<Compile Include="Contract\ParseErrorReport.cs" /> <Compile Include="Contract\ParseErrorReport.cs" />
<Compile Include="Model\AuthenticationType.cs" />
<Compile Include="PathExtensions.cs" /> <Compile Include="PathExtensions.cs" />
<Compile Include="DiskProvider.cs" /> <Compile Include="DiskProvider.cs" />
<Compile Include="EnvironmentInfo\AppFolderInfo.cs" /> <Compile Include="EnvironmentInfo\AppFolderInfo.cs" />

View File

@ -1,13 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.Cache; using NzbDrone.Common.Cache;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Model;
namespace NzbDrone.Core.Configuration namespace NzbDrone.Core.Configuration
{ {
@ -16,11 +14,11 @@ namespace NzbDrone.Core.Configuration
Dictionary<string, object> GetConfigDictionary(); Dictionary<string, object> GetConfigDictionary();
void SaveConfigDictionary(Dictionary<string, object> configValues); void SaveConfigDictionary(Dictionary<string, object> configValues);
int Port { get; set; } int Port { get; }
bool LaunchBrowser { get; set; } bool LaunchBrowser { get; }
AuthenticationType AuthenticationType { get; set; } bool AuthenticationEnabled { get; }
string BasicAuthUsername { get; set; } string Username { get; }
string BasicAuthPassword { get; set; } string Password { get; }
} }
public class ConfigFileProvider : IConfigFileProvider public class ConfigFileProvider : IConfigFileProvider
@ -80,31 +78,26 @@ namespace NzbDrone.Core.Configuration
public int Port public int Port
{ {
get { return GetValueInt("Port", 8989); } get { return GetValueInt("Port", 8989); }
set { SetValue("Port", value); }
} }
public bool LaunchBrowser public bool LaunchBrowser
{ {
get { return GetValueBoolean("LaunchBrowser", true); } get { return GetValueBoolean("LaunchBrowser", true); }
set { SetValue("LaunchBrowser", value); }
} }
public AuthenticationType AuthenticationType public bool AuthenticationEnabled
{ {
get { return GetValueEnum("AuthenticationType", AuthenticationType.Anonymous); } get { return GetValueBoolean("AuthenticationEnabled", false); }
set { SetValue("AuthenticationType", value); }
} }
public string BasicAuthUsername public string Username
{ {
get { return GetValue("BasicAuthUsername", ""); } get { return GetValue("Username", ""); }
set { SetValue("BasicAuthUsername", value); }
} }
public string BasicAuthPassword public string Password
{ {
get { return GetValue("BasicAuthPassword", ""); } get { return GetValue("Password", ""); }
set { SetValue("BasicAuthPassword", value); }
} }
public int GetValueInt(string key, int defaultValue) public int GetValueInt(string key, int defaultValue)

View File

@ -15,6 +15,8 @@
} }
.btn { .btn {
text-transform : capitalize;
min-width : 80px; min-width : 80px;
&.btn-mini { &.btn-mini {

View File

@ -6,7 +6,7 @@
<label class="control-label">Port Number</label> <label class="control-label">Port Number</label>
<div class="controls"> <div class="controls">
<input type="text" placeholder="8989" name="port"/> <input type="number" placeholder="8989" name="port"/>
<span> <span>
<i class="icon-form-danger" title="Requires restart to take effect"/> <i class="icon-form-danger" title="Requires restart to take effect"/>
</span> </span>
@ -38,33 +38,36 @@
<fieldset> <fieldset>
<legend>Security</legend> <legend>Security</legend>
<div class="control-group"> <div class="control-group">
<label class="control-label">Authentication</label> <label class="control-label">Authentication</label>
<div class="controls"> <div class="controls">
<select class="inputClass" name="authenticationType"> <label class="checkbox toggle well">
<option value="anonymous">Anonymous</option> <input type="checkbox" class='x-auth' name="authenticationEnabled"/>
<option value="basic">Basic</option> <p>
</select> <span>On</span>
<span>Off</span>
</p>
<div class="btn btn-primary slide-button"/>
</label>
<span class="help-inline-checkbox">
<i class="icon-question-sign" title="Require Username and Password to access Nzbdrone"/>
</span>
</div> </div>
</div> </div>
<div class='x-auth-options'>
<div class="control-group"> <div class="control-group">
<label class="control-label">Username</label> <label class="control-label">Username</label>
<div class="controls"> <div class="controls">
<input type="text" placeholder="Username" name="basicAuthUsername"/> <input type="text" placeholder="Username" name="username"/>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label">Password</label> <label class="control-label">Password</label>
<div class="controls"> <div class="controls">
<input type="password" name="basicAuthPassword"/> <input type="password" name="password"/>
</div>
</div> </div>
</div> </div>
</fieldset> </fieldset>
</div> </div>

View File

@ -1,9 +1,42 @@
'use strict'; 'use strict';
define(['marionette', 'Mixins/AsModelBoundView'], function (Marionette, AsModelBoundView) { define(
[
'marionette',
'Mixins/AsModelBoundView'
], function (Marionette, AsModelBoundView) {
var view = Marionette.ItemView.extend({ var view = Marionette.ItemView.extend({
template: 'Settings/General/GeneralTemplate' template: 'Settings/General/GeneralTemplate',
events: {
'change .x-auth': '_setAuthOptionsVisibility'
},
ui: {
authToggle : '.x-auth',
authOptions: '.x-auth-options'
},
onRender: function(){
if(!this.ui.authToggle.prop('checked')){
this.ui.authOptions.hide();
} }
); },
_setAuthOptionsVisibility: function () {
var showAuthOptions = this.ui.authToggle.prop('checked');
if (showAuthOptions) {
this.ui.authOptions.slideDown();
}
else {
this.ui.authOptions.slideUp();
}
}
});
return AsModelBoundView.call(view); return AsModelBoundView.call(view);
}); });

View File

@ -1,4 +1,4 @@
'use strict'; 'use strict';
define( define(
[ [
'marionette', 'marionette',
@ -14,27 +14,23 @@ define(
}, },
events: { events: {
'change .x-rename-episodes': '_toggleNamingOptions' 'change .x-rename-episodes': '_setNamingOptionsVisibility'
}, },
onShow: function () { onRender: function(){
var renameEpisodes = this.model.get('renameEpisodes'); if(!this.model.get('renameEpisodes')){
this._setNamingOptionsVisibility(renameEpisodes); this.ui.namingOptions.hide();
}
}, },
_toggleNamingOptions: function() { _setNamingOptionsVisibility: function () {
var checked = this.ui.renameEpisodesCheckbox.prop('checked'); var checked = this.ui.renameEpisodesCheckbox.prop('checked');
this._setNamingOptionsVisibility(checked); if (checked) {
}, this.ui.namingOptions.slideDown();
_setNamingOptionsVisibility: function (showNamingOptions) {
if (showNamingOptions) {
this.ui.namingOptions.show();
} }
else { else {
this.ui.namingOptions.hide(); this.ui.namingOptions.slideUp();
} }
} }
}); });

View File

@ -1,6 +1,6 @@
<div class="row"> <div class="row">
<div class="span12" id="quality-profile"/> <div class="span12" id="quality-profile"/>
</div> </div>
<div class="row"> <!--<div class="row">
<div class="span12" id="quality-size"/> <div class="span12" id="quality-size"/>
</div> </div>-->