mirror of
https://github.com/discourse/discourse.git
synced 2026-08-27 05:37:29 -05:00
basic api support
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
Discourse.AdminApiController = Ember.Controller.extend({
|
||||
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
Discourse.AdminApi = Discourse.Model.extend({
|
||||
VALID_KEY_LENGTH: 64,
|
||||
|
||||
keyExists: function(){
|
||||
var key = this.get('key') || '';
|
||||
return key && key.length === this.VALID_KEY_LENGTH;
|
||||
}.property('key'),
|
||||
|
||||
generateKey: function(){
|
||||
var _this = this;
|
||||
|
||||
$.ajax(Discourse.getURL('/admin/api/generate_key'),{
|
||||
type: 'POST'
|
||||
}).success(function(result){
|
||||
_this.set('key', result.key);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Discourse.AdminApi.reopenClass({
|
||||
find: function(){
|
||||
return this.getAjax('/admin/api');
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
Handles routes related to api
|
||||
|
||||
@class AdminApiRoute
|
||||
@extends Discourse.Route
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.AdminApiRoute = Discourse.Route.extend({
|
||||
renderTemplate: function() {
|
||||
this.render({into: 'admin/templates/admin'});
|
||||
},
|
||||
|
||||
model: function(params) {
|
||||
return Discourse.AdminApi.find();
|
||||
}
|
||||
});
|
||||
@@ -10,6 +10,7 @@ Discourse.Route.buildRoutes(function() {
|
||||
this.route('site_settings', { path: '/site_settings' });
|
||||
this.route('email_logs', { path: '/email_logs' });
|
||||
this.route('customize', { path: '/customize' });
|
||||
this.route('api', {path: '/api'});
|
||||
|
||||
this.resource('adminReports', { path: '/reports/:type' });
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<li>{{#linkTo 'admin.email_logs'}}{{i18n admin.email_logs.title}}{{/linkTo}}</li>
|
||||
<li>{{#linkTo 'adminFlags.active'}}{{i18n admin.flags.title}}{{/linkTo}}</li>
|
||||
<li>{{#linkTo 'admin.customize'}}{{i18n admin.customize.title}}{{/linkTo}}</li>
|
||||
<li>{{#linkTo 'admin.api'}}{{i18n admin.api.title}}{{/linkTo}}</li>
|
||||
</ul>
|
||||
|
||||
<div class='boxed white admin-content'>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<!-- Hold off on localizing for a few days while I finalize this page -->
|
||||
<h3>API Information</h3>
|
||||
{{#if content.keyExists}}
|
||||
<strong>Key:</strong> {{content.key}} <button {{action regenerateKey}}>Regenerate API Key</button>
|
||||
<p>Keep this key <strong>secret</strong>, all users that have it may create arbirary posts on the forum as any user.</p>
|
||||
{{else}}
|
||||
<p>Your API key will allow you to create and update topics using JSON calls.</p>
|
||||
<button {{action generateKey target="content"}}>Generate API Key</button>
|
||||
{{/if}}
|
||||
</p>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Discourse.AdminApiView = Discourse.View.extend({
|
||||
templateName: 'admin/templates/api'
|
||||
});
|
||||
Reference in New Issue
Block a user