Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

Commit

Permalink
add back api keys
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Jan 20, 2016
1 parent 15c973d commit 097d94e
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 9 deletions.
3 changes: 2 additions & 1 deletion MediaBrowser.Api/Session/SessionsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ public object Get(GetApiKeys request)
{
var result = _authRepo.Get(new AuthenticationInfoQuery
{
IsActive = true
IsActive = true,
HasUser = false
});

return ToOptimizedResult(result);
Expand Down
6 changes: 6 additions & 0 deletions MediaBrowser.Controller/Security/AuthenticationInfoQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public class AuthenticationInfoQuery
/// <value><c>null</c> if [is active] contains no value, <c>true</c> if [is active]; otherwise, <c>false</c>.</value>
public bool? IsActive { get; set; }

/// <summary>
/// Gets or sets a value indicating whether this instance has user.
/// </summary>
/// <value><c>null</c> if [has user] contains no value, <c>true</c> if [has user]; otherwise, <c>false</c>.</value>
public bool? HasUser { get; set; }

/// <summary>
/// Gets or sets the start index.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ public QueryResult<AuthenticationInfo> Get(AuthenticationInfoQuery query)
cmd.Parameters.Add(cmd, "@IsActive", DbType.Boolean).Value = query.IsActive.Value;
}

if (query.HasUser.HasValue)
{
if (query.HasUser.Value)
{
whereClauses.Add("UserId not null");
}
else
{
whereClauses.Add("UserId is null");
}
}

var whereTextWithoutPaging = whereClauses.Count == 0 ?
string.Empty :
" where " + string.Join(" AND ", whereClauses.ToArray());
Expand Down
6 changes: 6 additions & 0 deletions MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@
<Content Include="dashboard-ui\scripts\secondaryitems.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\serversecurity.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\shared.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -323,6 +326,9 @@
<Content Include="dashboard-ui\secondaryitems.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\serversecurity.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\shared.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
1 change: 1 addition & 0 deletions MediaBrowser.WebDashboard/dashboard-ui/advanced.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<div data-role="controlgroup" data-type="horizontal" class="localnav" data-mini="true">
<a href="#" data-role="button" class="ui-btn-active">${TabGeneral}</a>
<a href="dashboardhosting.html" data-role="button">${TabHosting}</a>
<a href="serversecurity.html" data-role="button">${TabSecurity}</a>
</div>
<form class="advancedConfigurationForm">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<div data-role="controlgroup" data-type="horizontal" class="localnav" data-mini="true">
<a href="advanced.html" data-role="button">${TabGeneral}</a>
<a href="#" data-role="button" class="ui-btn-active">${TabHosting}</a>
<a href="serversecurity.html" data-role="button">${TabSecurity}</a>
</div>

<form class="dashboardHostingForm">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function ($, document, LibraryBrowser) {
(function ($, document) {

function renderItems(page, item) {

Expand Down Expand Up @@ -337,4 +337,4 @@
renderItems: renderItems
};

})(jQuery, document, LibraryBrowser);
})(jQuery, document);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function ($, document, LibraryBrowser, window) {
(function ($, document, window) {

var currentItem;

Expand Down Expand Up @@ -2092,4 +2092,4 @@

window.ItemDetailPage = new itemDetailPage();

})(jQuery, document, LibraryBrowser, window);
})(jQuery, document, window);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function ($, document, Dashboard, LibraryBrowser) {
(function ($, document, Dashboard) {

function notifications() {

Expand Down Expand Up @@ -205,4 +205,4 @@

});

})(jQuery, document, Dashboard, LibraryBrowser);
})(jQuery, document, Dashboard);
144 changes: 144 additions & 0 deletions MediaBrowser.WebDashboard/dashboard-ui/scripts/serversecurity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
(function ($, document) {

function revoke(page, key) {

Dashboard.confirm(Globalize.translate('MessageConfirmRevokeApiKey'), Globalize.translate('HeaderConfirmRevokeApiKey'), function (result) {

if (result) {

Dashboard.showLoadingMsg();

ApiClient.ajax({
type: "DELETE",
url: ApiClient.getUrl('Auth/Keys/' + key)

}).then(function () {

loadData(page);
});
}

});
}

function renderKeys(page, keys, users) {

var rows = keys.map(function (item) {

var html = '';

html += '<tr>';

html += '<td>';
html += '<button data-token="' + item.AccessToken + '" class="btnRevoke" data-mini="true" title="' + Globalize.translate('ButtonRevoke') + '" style="margin:0;">' + Globalize.translate('ButtonRevoke') + '</button>';
html += '</td>';

html += '<td style="vertical-align:middle;">';
html += (item.AccessToken);
html += '</td>';

html += '<td style="vertical-align:middle;">';
html += (item.AppName || '');
html += '</td>';

html += '<td style="vertical-align:middle;">';
html += (item.DeviceName || '');
html += '</td>';

html += '<td style="vertical-align:middle;">';

var user = users.filter(function (u) {

return u.Id == item.UserId;
})[0];

if (user) {
html += user.Name;
}

html += '</td>';

html += '<td style="vertical-align:middle;">';

var date = parseISO8601Date(item.DateCreated, { toLocal: true });

html += date.toLocaleDateString() + ' ' + LibraryBrowser.getDisplayTime(date);

html += '</td>';

html += '</tr>';

return html;

}).join('');

var elem = $('.resultBody', page).html(rows).parents('.tblApiKeys').table("refresh").trigger('create');

$('.btnRevoke', elem).on('click', function () {

revoke(page, this.getAttribute('data-token'));
});

Dashboard.hideLoadingMsg();
}

function loadData(page) {

Dashboard.showLoadingMsg();

ApiClient.getUsers().then(function (users) {

ApiClient.getJSON(ApiClient.getUrl('Auth/Keys')).then(function (result) {

renderKeys(page, result.Items, users);
});
});
}

function onSubmit() {
var form = this;
var page = $(form).parents('.page');

Dashboard.showLoadingMsg();

ApiClient.ajax({
type: "POST",
url: ApiClient.getUrl('Auth/Keys', {

App: $('#txtAppName', form).val()

})

}).then(function () {

$('.newKeyPanel', page).panel('close');

loadData(page);
});

return false;
}

pageIdOn('pageinit', "serverSecurityPage", function () {

var page = this;

$('.btnNewKey', page).on('click', function () {

$('.newKeyPanel', page).panel('toggle');

$('#txtAppName', page).val('').focus();

});

$('.newKeyForm').off('submit', onSubmit).on('submit', onSubmit);

});
pageIdOn('pagebeforeshow', "serverSecurityPage", function () {

var page = this;

loadData(page);
});

})(jQuery, document);
4 changes: 2 additions & 2 deletions MediaBrowser.WebDashboard/dashboard-ui/scripts/shared.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function ($, document, LibraryBrowser, window) {
(function ($, document, window) {

var currentItem;

Expand Down Expand Up @@ -87,4 +87,4 @@

});

})(jQuery, document, LibraryBrowser, window);
})(jQuery, document, window);
58 changes: 58 additions & 0 deletions MediaBrowser.WebDashboard/dashboard-ui/serversecurity.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html>
<head>
<title>${TitleAdvanced}</title>
</head>
<body>
<div id="serverSecurityPage" data-role="page" class="page type-interior advancedConfigurationPage" data-require="jqmpanel,jqmtable,scripts/serversecurity,detailtablecss">
<div data-role="content">
<div class="content-primary">
<div data-role="controlgroup" data-type="horizontal" class="localnav" data-mini="true">
<a href="advanced.html" data-role="button">${TabGeneral}</a>
<a href="dashboardhosting.html" data-role="button">${TabHosting}</a>
<a href="#" data-role="button" class="ui-btn-active">${TabSecurity}</a>
</div>
<div class="detailSectionHeader" style="margin-top:2.5em;">
<h3 style="margin:.6em 0;vertical-align:middle;display:inline-block;">
${HeaderApiKeys}
</h3>
<paper-button raised class="btnNewKey submit mini" style="margin-left:1em;" title="${ButtonNew}">
<iron-icon icon="add"></iron-icon>
<span>${ButtonAdd}</span>
</paper-button>
</div>
<p>${HeaderApiKeysHelp}</p>
<br />
<table data-role="table" data-mode="reflow" class="tblApiKeys stripedTable ui-responsive table-stroke" style="display: table;">
<thead>
<tr>
<th></th>
<th>${HeaderApiKey}</th>
<th>${HeaderApp}</th>
<th>${HeaderDevice}</th>
<th>${HeaderUser}</th>
<th>${HeaderDateIssued}</th>
</tr>
</thead>
<tbody class="resultBody"></tbody>
</table>
</div>
</div>
<div data-role="panel" class="newKeyPanel" data-position="right" data-display="overlay" data-position-fixed="true">
<form class="newKeyForm">
<h3>${HeaderNewApiKey}</h3>
<p>${HeaderNewApiKeyHelp}</p>
<div>
<label for="txtAppName">${LabelAppName}</label>
<input type="text" id="txtAppName" required="required" />
<div class="fieldDescription">${LabelAppNameExample}</div>
</div>
<br />
<p>
<button type="submit" data-icon="plus" data-mini="true" data-theme="b">${ButtonCreate}</button>
</p>
</form>
</div>
</div>
</body>
</html>

0 comments on commit 097d94e

Please sign in to comment.