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

View File

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

View File

@ -128,19 +128,9 @@ namespace NzbDrone.Common.Test
[Test]
public void GetAuthenticationType_No_Existing_Value()
{
var result = Subject.AuthenticationType;
var result = Subject.AuthenticationEnabled;
result.Should().Be(AuthenticationType.Anonymous);
}
[Test]
public void GetAuthenticationType_Basic()
{
Subject.SetValue("AuthenticationType", AuthenticationType.Basic);
var result = Subject.AuthenticationType;
result.Should().Be(AuthenticationType.Basic);
result.Should().Be(false);
}
[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="Contract\ReportBase.cs" />
<Compile Include="Contract\ParseErrorReport.cs" />
<Compile Include="Model\AuthenticationType.cs" />
<Compile Include="PathExtensions.cs" />
<Compile Include="DiskProvider.cs" />
<Compile Include="EnvironmentInfo\AppFolderInfo.cs" />

View File

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

View File

@ -15,14 +15,16 @@
}
.btn {
min-width : 80px;
&.btn-mini{
min-width: 0px;
text-transform : capitalize;
min-width : 80px;
&.btn-mini {
min-width : 0px;
}
&.btn-icon-only{
min-width: 15px;
&.btn-icon-only {
min-width : 15px;
}
}

View File

@ -6,7 +6,7 @@
<label class="control-label">Port Number</label>
<div class="controls">
<input type="text" placeholder="8989" name="port"/>
<input type="number" placeholder="8989" name="port"/>
<span>
<i class="icon-form-danger" title="Requires restart to take effect"/>
</span>
@ -38,33 +38,36 @@
<fieldset>
<legend>Security</legend>
<div class="control-group">
<label class="control-label">Authentication</label>
<div class="controls">
<select class="inputClass" name="authenticationType">
<option value="anonymous">Anonymous</option>
<option value="basic">Basic</option>
</select>
<label class="checkbox toggle well">
<input type="checkbox" class='x-auth' name="authenticationEnabled"/>
<p>
<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 class="control-group">
<label class="control-label">Username</label>
<div class="controls">
<input type="text" placeholder="Username" name="basicAuthUsername"/>
<div class='x-auth-options'>
<div class="control-group">
<label class="control-label">Username</label>
<div class="controls">
<input type="text" placeholder="Username" name="username"/>
</div>
</div>
<div class="control-group">
<label class="control-label">Password</label>
<div class="controls">
<input type="password" name="password"/>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">Password</label>
<div class="controls">
<input type="password" name="basicAuthPassword"/>
</div>
</div>
</fieldset>
</div>

View File

@ -1,10 +1,43 @@
'use strict';
define(['marionette', 'Mixins/AsModelBoundView'], function (Marionette, AsModelBoundView) {
var view = Marionette.ItemView.extend({
template: 'Settings/General/GeneralTemplate'
}
);
define(
[
'marionette',
'Mixins/AsModelBoundView'
], function (Marionette, AsModelBoundView) {
var view = Marionette.ItemView.extend({
template: 'Settings/General/GeneralTemplate',
return AsModelBoundView.call(view);
});
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);
});

View File

@ -1,4 +1,4 @@
'use strict';
'use strict';
define(
[
'marionette',
@ -9,32 +9,28 @@ define(
template: 'Settings/MediaManagement/Naming/ViewTemplate',
ui: {
namingOptions : '.x-naming-options',
renameEpisodesCheckbox : '.x-rename-episodes'
namingOptions : '.x-naming-options',
renameEpisodesCheckbox: '.x-rename-episodes'
},
events: {
'change .x-rename-episodes': '_toggleNamingOptions'
'change .x-rename-episodes': '_setNamingOptionsVisibility'
},
onShow: function () {
var renameEpisodes = this.model.get('renameEpisodes');
this._setNamingOptionsVisibility(renameEpisodes);
onRender: function(){
if(!this.model.get('renameEpisodes')){
this.ui.namingOptions.hide();
}
},
_toggleNamingOptions: function() {
_setNamingOptionsVisibility: function () {
var checked = this.ui.renameEpisodesCheckbox.prop('checked');
this._setNamingOptionsVisibility(checked);
},
_setNamingOptionsVisibility: function (showNamingOptions) {
if (showNamingOptions) {
this.ui.namingOptions.show();
if (checked) {
this.ui.namingOptions.slideDown();
}
else {
this.ui.namingOptions.hide();
this.ui.namingOptions.slideUp();
}
}
});

View File

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