From a7458425133ed839e20fdfd48be1ec89823f26a7 Mon Sep 17 00:00:00 2001 From: Mathew Henson Date: Wed, 13 Apr 2016 17:23:25 +0100 Subject: [PATCH] Updated modepress URI's to match users v0.2.0. Closes issue #8 --- admin/gulpfile.js | 32 ++- admin/lib/application.ts | 2 - .../definitions/required/webinate-users.d.ts | 183 ++++++++++-------- admin/lib/index.jade | 1 - admin/lib/references.d.ts | 4 +- admin/lib/states/media/media-ctrl.ts | 22 +-- .../states/password-reset/password-ctrl.ts | 6 +- admin/lib/states/posts/posts-ctrl.ts | 6 +- admin/lib/states/register/register-ctrl.ts | 10 +- admin/lib/states/users/users-ctrl.ts | 2 +- admin/package.json | 4 +- admin/tsconfig.json | 10 +- server/dist/definitions/definitions.d.ts | 8 +- server/dist/src/path-handler.js | 5 +- server/dist/src/users-service.js | 11 +- .../definitions/required/webinate-users.d.ts | 10 +- server/src/path-handler.ts | 5 +- server/src/users-service.ts | 22 +-- test/tests.js | 2 +- 19 files changed, 183 insertions(+), 162 deletions(-) diff --git a/admin/gulpfile.js b/admin/gulpfile.js index 7db619e2..a148c693 100644 --- a/admin/gulpfile.js +++ b/admin/gulpfile.js @@ -17,6 +17,8 @@ var sprity = require('sprity'); var sass = require('gulp-sass'); var spritySass = require('sprity-sass'); var rimraf = require('rimraf'); +var download = require('gulp-download'); +var rename = require("gulp-rename"); // CONFIG @@ -69,7 +71,7 @@ gulp.task('sprites', function () { /** * Builds each of the ts files into JS files in the output folder */ -gulp.task('ts-code', function() { +gulp.task('ts-code', ['check-files'], function() { return gulp.src(tsFiles, { base: "." }) .pipe(ts({ @@ -117,6 +119,34 @@ function deleteFolderRecursive(path) { } }; +/** + * This function downloads a definition file from github and writes it to a destination + * @param {string} url The url of the file to download + * @param {string} dest The destination folder to move the file to + */ +function getDefinition(url, dest, name) { + return new Promise(function(resolve, reject) { + download(url) + .pipe(rename(name)) + .pipe(gulp.dest(dest)) + .on('error', function(err) { + throw(err) + }) + .on('end', function() { + resolve(true); + }) + }); +} + +/** + * Downloads the definition files used in the development of the application and moves them into the definitions folder + */ +gulp.task('install-definitions', function () { + return Promise.all([ + getDefinition("https://raw.githubusercontent.com/MKHenson/users/dev/dist/definitions/definitions.d.ts", "lib/definitions/required/", "webinate-users.d.ts") + ]); +}); + /** * Downloads a tarbal from a given url and unzips it into a specified folder * @param {string} url The URL of the tarball to download diff --git a/admin/lib/application.ts b/admin/lib/application.ts index 72b5fe9c..f07b3be3 100644 --- a/admin/lib/application.ts +++ b/admin/lib/application.ts @@ -1,5 +1,4 @@ declare var _users: string; -declare var _media: string; declare var _cache: string; declare var _plugins: Array; @@ -12,7 +11,6 @@ module clientAdmin var appModule = angular.module("admin", ["ui.router", "ngAnimate", "ngSanitize", 'angular-loading-bar', 'ngFileUpload', 'admin-templates']) .constant("usersURL", _users ) - .constant("mediaURL", _media ) .constant("apiURL", "./api") .constant("cacheURL", _cache) .constant("capthaPublicKey", "6LdiW-USAAAAAGxGfZnQEPP2gDW2NLZ3kSMu3EtT") diff --git a/admin/lib/definitions/required/webinate-users.d.ts b/admin/lib/definitions/required/webinate-users.d.ts index 580acc86..68b7951a 100644 --- a/admin/lib/definitions/required/webinate-users.d.ts +++ b/admin/lib/definitions/required/webinate-users.d.ts @@ -1,5 +1,3 @@ -/// - declare module UsersInterface { export class User @@ -40,7 +38,7 @@ declare module UsersInterface */ export interface IFilesRemovedEvent extends IEvent { - files: Array; + files: Array; } /* @@ -84,12 +82,13 @@ declare module UsersInterface */ export interface IBucketEntry { - _id?: any; + _id?:any; name?: string; identifier?: string; user?: string; created?: number; memoryUsed?: number; + meta?: any; } /** @@ -121,6 +120,8 @@ declare module UsersInterface mimeType?: string; isPublic?: boolean; numDownloads?: number; + parentFile?: string; + meta?: any; } /** @@ -168,7 +169,7 @@ declare module UsersInterface */ port: number; - + /** * An array of expected clients * [ @@ -181,7 +182,7 @@ declare module UsersInterface /* * Users stores data on an external cloud bucket with Google */ - export interface IGoogleStorage + export interface IGoogleProperties { /* * Path to the key file @@ -189,33 +190,56 @@ declare module UsersInterface keyFile: string; /* - * Project ID + * Mail settings */ - projectId: string; + mail: { - /** - * The name of the mongodb collection for storing bucket details - * eg: "buckets" - */ - bucketsCollection: string; + /* + * The email account to use the gmail API through. This account must be authorized to + * use this application. See: https://admin.google.com/AdminHome?fral=1#SecuritySettings: + */ + apiEmail: string; - /** - * The name of the mongodb collection for storing file details - * eg: "files" - */ - filesCollection: string; + /* + * The email to use as the from field when sending mail. This can be different from the apiEmail. + */ + from: string; + }; - /** - * The name of the mongodb collection for storing user stats - * eg: "storageAPI" - */ - statsCollection: string; - - /** - * The length of time the assets should be cached on a user's browser. - * eg: 2592000000 or 30 days - */ - cacheLifetime: number; + /* + * Describes the bucket details + */ + bucket : { + + /* + * Project ID + */ + projectId: string; + + /** + * The name of the mongodb collection for storing bucket details + * eg: "buckets" + */ + bucketsCollection: string; + + /** + * The name of the mongodb collection for storing file details + * eg: "files" + */ + filesCollection: string; + + /** + * The name of the mongodb collection for storing user stats + * eg: "storageAPI" + */ + statsCollection: string; + + /** + * The length of time the assets should be cached on a user's browser. + * eg: 2592000000 or 30 days + */ + cacheLifetime: number; + } } /* @@ -246,6 +270,23 @@ declare module UsersInterface filename: string; error: boolean; errorMsg: string; + url: string; + } + + /* + * A POST request that returns the details of a text upload + */ + export interface IUploadTextResponse extends IResponse + { + token: IUploadToken; + } + + /* + * A POST request that returns the details of a binary upload + */ + export interface IUploadBinaryResponse extends IResponse + { + token: IUploadToken; } /* @@ -313,32 +354,26 @@ declare module UsersInterface export interface IConfig { /** - * The domain or host of the site. + * The domain or host of the site. * eg: "127.0.0.1" or "webinate.net" */ host: string; /** - * The RESTful path of this service. - * eg: If "/api", then the API url would be 127.0.0.1:80/api (or rather host:port/restURL) - */ - restURL: string; - - /** - * The RESTful path of the media API - * eg: If "/media", then the API url would be 127.0.0.1:80/media (or rather host:port/restURL) + * The RESTful path of this service. + * eg: If "/api", then the API url would be 127.0.0.1:80/api (or rather host:port/api) */ - mediaURL: string; + apiPrefix: string; /** * A secret string to identify authenticated servers */ secret: string; - + /** - * The URL to redirect to after the user attempts to activate their account. + * The URL to redirect to after the user attempts to activate their account. * User's can activate their account via the "/activate-account" URL, and after its validation the server will redirect to this URL - * adding a query ?message=You%20have%20activated%20your%20account&status=success. + * adding a query ?message=You%20have%20activated%20your%20account&status=success. * The status can be either 'success' or 'error' * * eg: "http://localhost/notify-user" @@ -352,9 +387,9 @@ declare module UsersInterface * eg: "http://localhost/reset-password" */ passwordResetURL: string; - + /** - * An array of approved domains that can access this API. + * An array of approved domains that can access this API. * e.g. ["webinate\\.net", "127.0.0.1:80", "http:\/\/127.0.0.1"] etc... */ approvedDomains: Array; @@ -375,7 +410,7 @@ declare module UsersInterface * Information regarding the websocket communication. Used for events and IPC */ websocket: IWebsocket; - + /** * The name of the mongo database name */ @@ -392,7 +427,7 @@ declare module UsersInterface * eg: "sessions" */ sessionCollection: string; - + /** * The host the DB is listening on * e.g. "127.0.0.1" @@ -412,7 +447,7 @@ declare module UsersInterface ssl: boolean; /** - * The path to the SSL private key + * The path to the SSL private key */ sslKey: string; @@ -443,7 +478,7 @@ declare module UsersInterface */ sessionPath?: string; - /** + /** * If present, the cookie (and hence the session) will apply to the given domain, including any subdomains. * For example, on a request from foo.example.org, if the domain is set to '.example.org', then this session will persist across any subdomain of example.org. * By default, the domain is not set, and the session will only be visible to other requests that exactly match the domain. @@ -457,7 +492,7 @@ declare module UsersInterface * e.g: true/false. Default is true */ sessionPersistent?: boolean; - + /** * The default length of user sessions in seconds * e.g 1800 @@ -465,46 +500,22 @@ declare module UsersInterface sessionLifetime?: number; /** - * The private key to use for Google captcha + * The private key to use for Google captcha * Get your key from the captcha admin: https://www.google.com/recaptcha/intro/index.html */ captchaPrivateKey: string; /** - * The public key to use for Google captcha + * The public key to use for Google captcha * Get your key from the captcha admin: https://www.google.com/recaptcha/intro/index.html */ captchaPublicKey: string; - - /** - * The 'from' email when they receive an email for the server - * eg: support@host.com - */ - emailFrom: string; - - /** - * Email service we are using to send mail. For example 'Gmail' - * eg: "Gmail" - */ - emailService: string; - - /** - * The email address / username of the service - * e.g: "provider@gmail.com" - */ - emailServiceUser: string; - - /** - * The password of the email service - * e.g: "provider_password" - */ - emailServicePassword: string; /** * The administrative user. This is the root user that will have access to the information in the database. * This can be anything you like, but try to use passwords that are hard to guess - * eg: - + * eg: + "adminUser": { "username": "root", "email": "root_email@host.com", @@ -516,14 +527,20 @@ declare module UsersInterface /** * Information relating to the Google storage platform * - "bucket": { - "keyFile": "", - "projectId": "", - "bucketsCollection": "buckets", - "filesCollection": "files" + "google": { + "keyFile": "", + "mail":{ + "apiEmail": "", + "from": "" + }, + "bucket": { + "projectId": "", + "bucketsCollection": "buckets", + "filesCollection": "files" + } } */ - bucket: IGoogleStorage; + google: IGoogleProperties; } export interface IGetUser extends IGetResponse { } diff --git a/admin/lib/index.jade b/admin/lib/index.jade index 442fe967..b6001e23 100644 --- a/admin/lib/index.jade +++ b/admin/lib/index.jade @@ -11,7 +11,6 @@ html(lang="en") link(href="https://fonts.googleapis.com/css?family=Roboto+Condensed:300italic,300", rel="stylesheet", type="text/css") script(type="text/javascript"). var _users = "#{usersURL}" - var _media = "#{mediaURL}" var _cache = "#{cacheURL}" var _plugins = []; var _variables = !{ JSON.stringify(variables) }; diff --git a/admin/lib/references.d.ts b/admin/lib/references.d.ts index 028ac3a7..3cd57274 100644 --- a/admin/lib/references.d.ts +++ b/admin/lib/references.d.ts @@ -5,4 +5,6 @@ /// /// /// -/// \ No newline at end of file +/// +/// +/// \ No newline at end of file diff --git a/admin/lib/states/media/media-ctrl.ts b/admin/lib/states/media/media-ctrl.ts index 9224d6b8..14fbd049 100644 --- a/admin/lib/states/media/media-ctrl.ts +++ b/admin/lib/states/media/media-ctrl.ts @@ -5,7 +5,7 @@ */ export class MediaCtrl { - private mediaURL: string; + private usersURL: string; public folderFormVisible: boolean; public scope: any; public entries: Array; @@ -27,11 +27,11 @@ private searchTerm: string; // $inject annotation. - public static $inject = ["$scope", "$http", "mediaURL", "Upload", "$q"]; - constructor(scope: any, http: ng.IHttpService, mediaURL: string, upload: any, $q : ng.IQService) + public static $inject = ["$scope", "$http", "usersURL", "Upload", "$q"]; + constructor(scope: any, http: ng.IHttpService, usersURL: string, upload: any, $q : ng.IQService) { this.scope = scope; - this.mediaURL = mediaURL; + this.usersURL = usersURL; this.folderFormVisible = false; this.confirmDelete = false; this.editMode = false; @@ -65,7 +65,7 @@ { var file = files[i]; this.uploader.upload({ - url: `${that.mediaURL}/upload/${that.selectedFolder.name}`, + url: `${that.usersURL}/buckets/${that.selectedFolder.name}/upload`, file: file }).success(function (data, status, headers, config) @@ -99,7 +99,7 @@ return; } - this.http.post(`${that.mediaURL}/create-bucket/${Authenticator.user.username}/${folderName}`, null).then(function(token) + this.http.post(`${that.usersURL}/users/${Authenticator.user.username}/buckets/${folderName}`, null).then(function(token) { if (token.data.error) { @@ -138,7 +138,7 @@ that.error = false; that.errorMsg = ""; that.loading = true; - var command = (this.selectedFolder ? "remove-files" : "remove-buckets"); + var command = (this.selectedFolder ? "files" : "buckets"); var entities = ""; @@ -155,7 +155,7 @@ entities = (entities.length > 0 ? entities.substr(0, entities.length - 1) : "" ); - that.http.delete(`${that.mediaURL}/${command}/${entities}`).then(function (token) + that.http.delete(`${that.usersURL}/${command}/${entities}`).then(function (token) { if (token.data.error) { @@ -180,7 +180,7 @@ that.errorMsg = ""; that.loading = true; - that.http.put(`${that.mediaURL}/rename-file/${file.identifier}`, { name: $("#file-name").val() }).then(function (token) + that.http.put(`${that.usersURL}/files/${file.identifier}/rename-file`, { name: $("#file-name").val() }).then(function (token) { if (token.data.error) { @@ -245,9 +245,9 @@ var command = ""; if (that.selectedFolder) - command = `${that.mediaURL}/get-files/${Authenticator.user.username}/${that.selectedFolder.name}/?index=${index}&limit=${limit}&search=${that.searchTerm}` + command = `${that.usersURL}/users/${Authenticator.user.username}/buckets/${that.selectedFolder.name}/get-files?index=${index}&limit=${limit}&search=${that.searchTerm}` else - command = `${that.mediaURL}/get-buckets/${Authenticator.user.username}/?index=${index}&limit=${limit}&search=${that.searchTerm}` + command = `${that.usersURL}/users/${Authenticator.user.username}/buckets?index=${index}&limit=${limit}&search=${that.searchTerm}` return new that._q(function(resolve, reject) { diff --git a/admin/lib/states/password-reset/password-ctrl.ts b/admin/lib/states/password-reset/password-ctrl.ts index 1ea20a0b..61073d1f 100644 --- a/admin/lib/states/password-reset/password-ctrl.ts +++ b/admin/lib/states/password-reset/password-ctrl.ts @@ -58,7 +58,7 @@ this.errorMsg = ""; this.loading = true; - this.http.get(`${host}/request-password-reset/${that.loginToken.user}`).then(function (response) + this.http.get(`${host}/users/${that.loginToken.user}/request-password-reset`).then(function (response) { var responseToken = response.data; if (responseToken.error) @@ -80,9 +80,9 @@ that.loading = false; that.errorMsg = "Could not communicate with server"; }); - + } - + /** * Attempts to reset the password based on the current credentials */ diff --git a/admin/lib/states/posts/posts-ctrl.ts b/admin/lib/states/posts/posts-ctrl.ts index 9f83f736..8196b289 100644 --- a/admin/lib/states/posts/posts-ctrl.ts +++ b/admin/lib/states/posts/posts-ctrl.ts @@ -10,7 +10,6 @@ public showNewPostForm: boolean; public editMode: boolean; public apiURL: string; - public mediaURL: string; public scope: any; public successMessage: string; public tagString: string; @@ -35,13 +34,12 @@ private pager: IPagerRemote; // $inject annotation. - public static $inject = ["$scope", "$http", "apiURL", "mediaURL", "categories", "$q"]; - constructor(scope, http: ng.IHttpService, apiURL: string, mediaURL: string, categories: Array, $q: ng.IQService) + public static $inject = ["$scope", "$http", "apiURL", "categories", "$q"]; + constructor(scope, http: ng.IHttpService, apiURL: string, categories: Array, $q: ng.IQService) { this.newCategoryMode = false; this.scope = scope; this.apiURL = apiURL; - this.mediaURL = mediaURL; this.posts = []; this.successMessage = ""; this.tagString = ""; diff --git a/admin/lib/states/register/register-ctrl.ts b/admin/lib/states/register/register-ctrl.ts index 73c99458..9658153d 100644 --- a/admin/lib/states/register/register-ctrl.ts +++ b/admin/lib/states/register/register-ctrl.ts @@ -22,7 +22,7 @@ this.http = http; this.q = q; this.usersURL = usersURL; - + // Create the register token this.registerToken = { username: "", @@ -33,7 +33,7 @@ privileges: 3, meta: {} }; - + this.error = false; this.showSuccessMessage = false; this.errorMsg = ""; @@ -41,7 +41,7 @@ this.loading = false; // Initialize the google captcha - jQuery('#google-captcha').each(function(){ + jQuery('#google-captcha').each(function(){ Recaptcha.create("6LdiW-USAAAAAGxGfZnQEPP2gDW2NLZ3kSMu3EtT", this, { theme: "white" }); }); } @@ -54,7 +54,7 @@ var that = this; var token = this.registerToken; var user = (token.email && token.email != "" ? token.email : token.username); - + this.loading = true; this.error = false; this.showSuccessMessage = false; @@ -69,7 +69,7 @@ return; } - this.http.get(`${that.usersURL}/resend-activation/${user}`).then(function (response) + this.http.get(`${that.usersURL}/users/${user}/resend-activation`).then(function (response) { var responseToken = response.data; if (responseToken.error) diff --git a/admin/lib/states/users/users-ctrl.ts b/admin/lib/states/users/users-ctrl.ts index a5c1dc94..82cdb494 100644 --- a/admin/lib/states/users/users-ctrl.ts +++ b/admin/lib/states/users/users-ctrl.ts @@ -96,7 +96,7 @@ this.errorMsg = ""; this.loading = true; - that.http.delete(`${that.usersURL}/remove-user/${user.username}`).then(function (token) + that.http.delete(`${that.usersURL}/users/${user.username}/remove-user`).then(function (token) { if (token.data.error) { that.error = true; diff --git a/admin/package.json b/admin/package.json index 121c9821..696300cd 100644 --- a/admin/package.json +++ b/admin/package.json @@ -23,6 +23,8 @@ "gulp-if": "^2.0.0", "gulp-sass": "^2.2.0", "sprity-sass": "^1.0.4", - "rimraf": "^2.5.2" + "rimraf": "^2.5.2", + "gulp-download": "^0.0.1", + "gulp-rename": "^1.2.2" } } \ No newline at end of file diff --git a/admin/tsconfig.json b/admin/tsconfig.json index 90e2cdb2..17b79507 100644 --- a/admin/tsconfig.json +++ b/admin/tsconfig.json @@ -13,15 +13,7 @@ }, "files": [ "../server/src/definitions/custom/modepress-api.d.ts", - "lib/definitions/required/es6-promise.d.ts", - "lib/definitions/required/jquery.d.ts", - "lib/definitions/required/angular.d.ts", - "lib/definitions/required/angular-ui-router.d.ts", - "lib/definitions/required/recaptcha.d.ts", - "lib/definitions/required/webinate-users.d.ts", - "lib/definitions/custom/tinymce.d.ts", - "lib/definitions/custom/modepress-client.d.ts", - "lib/states/paged-content-ctrl.ts", + "lib/references.d.ts", "lib/states/seo/seo-ctrl.ts", "lib/states/login/login-ctrl.ts", "lib/states/register/register-ctrl.ts", diff --git a/server/dist/definitions/definitions.d.ts b/server/dist/definitions/definitions.d.ts index f0db54e5..febdd980 100644 --- a/server/dist/definitions/definitions.d.ts +++ b/server/dist/definitions/definitions.d.ts @@ -109,7 +109,7 @@ declare module clientAdmin { * Controller for the dashboard media section */ class MediaCtrl { - private mediaURL; + private usersURL; folderFormVisible: boolean; scope: any; entries: Array; @@ -129,7 +129,7 @@ declare module clientAdmin { private pager; private searchTerm; static $inject: string[]; - constructor(scope: any, http: ng.IHttpService, mediaURL: string, upload: any, $q: ng.IQService); + constructor(scope: any, http: ng.IHttpService, usersURL: string, upload: any, $q: ng.IQService); upload(files: any): void; /** * Creates a new folder @@ -207,7 +207,6 @@ declare module clientAdmin { showNewPostForm: boolean; editMode: boolean; apiURL: string; - mediaURL: string; scope: any; successMessage: string; tagString: string; @@ -230,7 +229,7 @@ declare module clientAdmin { private errorMsg; private pager; static $inject: string[]; - constructor(scope: any, http: ng.IHttpService, apiURL: string, mediaURL: string, categories: Array, $q: ng.IQService); + constructor(scope: any, http: ng.IHttpService, apiURL: string, categories: Array, $q: ng.IQService); /** * Opens the media browser */ @@ -365,7 +364,6 @@ declare module clientAdmin { } } declare var _users: string; -declare var _media: string; declare var _cache: string; declare var _plugins: Array; /** diff --git a/server/dist/src/path-handler.js b/server/dist/src/path-handler.js index 3ea1a3e9..c1d0174c 100644 --- a/server/dist/src/path-handler.js +++ b/server/dist/src/path-handler.js @@ -31,10 +31,7 @@ var PathHandler = (function () { var path = this._path; var requestIsSecure = (req.connection.encrypted || req.headers["x-forwarded-proto"] == "https" ? true : false); var url = (requestIsSecure ? "https" : "http") + "://" + config.host; - var options = { - usersURL: "" + users_service_1.UsersService.usersURL, - mediaURL: "" + users_service_1.UsersService.mediaURL, - url: url }; + var options = { usersURL: "" + users_service_1.UsersService.usersURL, url: url }; options.plugins = path.plugins || []; options.variables = {}; // Add any custom variables diff --git a/server/dist/src/users-service.js b/server/dist/src/users-service.js index 10143471..1e1ad4f8 100644 --- a/server/dist/src/users-service.js +++ b/server/dist/src/users-service.js @@ -9,8 +9,7 @@ var UsersService = (function () { * @param {IConfig} config The config file of this server */ function UsersService(config) { - UsersService.usersURL = config.usersURL + "/users"; - UsersService.mediaURL = config.usersURL + "/media"; + UsersService.usersURL = config.usersURL; this._secret = config.usersSecret; } /** @@ -39,7 +38,7 @@ var UsersService = (function () { UsersService.prototype.setMetaValue = function (name, val, user, req) { var that = this; return new Promise(function (resolve, reject) { - request.post(UsersService.usersURL + "/meta/" + user + "/" + name, { body: { secret: that._secret, value: val }, headers: { cookie: req.headers.cookie } }, function (error, response, body) { + request.post(UsersService.usersURL + "/users/" + user + "/meta/" + name, { body: { secret: that._secret, value: val }, headers: { cookie: req.headers.cookie } }, function (error, response, body) { if (error) return reject(error); var token = JSON.parse(body); @@ -59,7 +58,7 @@ var UsersService = (function () { UsersService.prototype.setMeta = function (val, user, req) { var that = this; return new Promise(function (resolve, reject) { - request.post(UsersService.usersURL + "/meta/" + user, { body: { secret: that._secret, value: val }, headers: { cookie: req.headers.cookie } }, function (error, response, body) { + request.post(UsersService.usersURL + "/users/" + user + "/meta", { body: { secret: that._secret, value: val }, headers: { cookie: req.headers.cookie } }, function (error, response, body) { if (error) return reject(error); var token = JSON.parse(body); @@ -79,7 +78,7 @@ var UsersService = (function () { UsersService.prototype.getMetaVal = function (user, name, req) { var that = this; return new Promise(function (resolve, reject) { - request.get(UsersService.usersURL + "/meta/" + user + "/" + name, { headers: { cookie: req.headers.cookie } }, function (error, response, body) { + request.get(UsersService.usersURL + "/users/" + user + "/meta/" + name, { headers: { cookie: req.headers.cookie } }, function (error, response, body) { if (error) return reject(error); var token = JSON.parse(body); @@ -150,7 +149,7 @@ var UsersService = (function () { UsersService.prototype.getStats = function (user, req) { var that = this; return new Promise(function (resolve, reject) { - request.get(UsersService.mediaURL + "/get-stats/" + user, { headers: { cookie: req.headers.cookie } }, function (error, response, body) { + request.get(UsersService.usersURL + "/stats/get-stats/" + user, { headers: { cookie: req.headers.cookie } }, function (error, response, body) { if (error) return reject(error); var token = JSON.parse(body); diff --git a/server/src/definitions/required/webinate-users.d.ts b/server/src/definitions/required/webinate-users.d.ts index d7b2edef..68b7951a 100644 --- a/server/src/definitions/required/webinate-users.d.ts +++ b/server/src/definitions/required/webinate-users.d.ts @@ -361,15 +361,9 @@ declare module UsersInterface /** * The RESTful path of this service. - * eg: If "/api", then the API url would be 127.0.0.1:80/api (or rather host:port/restURL) + * eg: If "/api", then the API url would be 127.0.0.1:80/api (or rather host:port/api) */ - restURL: string; - - /** - * The RESTful path of the media API - * eg: If "/media", then the API url would be 127.0.0.1:80/media (or rather host:port/restURL) - */ - mediaURL: string; + apiPrefix: string; /** * A secret string to identify authenticated servers diff --git a/server/src/path-handler.ts b/server/src/path-handler.ts index c01143c0..a8dbd10f 100644 --- a/server/src/path-handler.ts +++ b/server/src/path-handler.ts @@ -43,10 +43,7 @@ export class PathHandler var requestIsSecure = ((req.connection).encrypted || req.headers["x-forwarded-proto"] == "https" ? true : false); var url = `${(requestIsSecure ? "https" : "http") }://${config.host}`; - var options: any = { - usersURL: `${UsersService.usersURL}`, - mediaURL: `${UsersService.mediaURL}`, - url: url }; + var options: any = { usersURL: `${UsersService.usersURL}`, url: url }; options.plugins = path.plugins || []; options.variables = {}; diff --git a/server/src/users-service.ts b/server/src/users-service.ts index 73f3db80..d14535b0 100644 --- a/server/src/users-service.ts +++ b/server/src/users-service.ts @@ -11,7 +11,6 @@ export class UsersService private static _singleton: UsersService; public static usersURL: string; - public static mediaURL: string; private _secret: string; /** @@ -20,9 +19,8 @@ export class UsersService */ constructor(config: IConfig ) { - UsersService.usersURL = config.usersURL + "/users"; - UsersService.mediaURL = config.usersURL + "/media"; - this._secret = config.usersSecret; + UsersService.usersURL = config.usersURL; + this._secret = config.usersSecret; } /** @@ -33,7 +31,7 @@ export class UsersService sendAdminEmail(message: string): Promise { var that = this; - return new Promise(function(resolve, reject) + return new Promise(function(resolve, reject) { request.post(`${UsersService.usersURL}/message-webmaster`, { form: { message: message } }, function (error, response, body) { @@ -58,7 +56,7 @@ export class UsersService var that = this; return new Promise(function (resolve, reject) { - request.post(`${UsersService.usersURL}/meta/${user}/${name}`, { body: { secret: that._secret, value: val }, headers: { cookie: (req).headers.cookie } }, function (error, response, body) + request.post(`${UsersService.usersURL}/users/${user}/meta/${name}`, { body: { secret: that._secret, value: val }, headers: { cookie: (req).headers.cookie } }, function (error, response, body) { if (error) return reject(error); @@ -85,7 +83,7 @@ export class UsersService var that = this; return new Promise(function (resolve, reject) { - request.post(`${UsersService.usersURL}/meta/${user}`, { body: { secret: that._secret, value: val }, headers: { cookie: (req).headers.cookie } }, function (error, response, body) + request.post(`${UsersService.usersURL}/users/${user}/meta`, { body: { secret: that._secret, value: val }, headers: { cookie: (req).headers.cookie } }, function (error, response, body) { if (error) return reject(error); @@ -112,7 +110,7 @@ export class UsersService var that = this; return new Promise(function (resolve, reject) { - request.get(`${UsersService.usersURL}/meta/${user}/${name}`, { headers: { cookie: (req).headers.cookie } }, function (error, response, body) + request.get(`${UsersService.usersURL}/users/${user}/meta/${name}`, { headers: { cookie: (req).headers.cookie } }, function (error, response, body) { if (error) return reject(error); @@ -185,7 +183,7 @@ export class UsersService * @returns {boolean} */ hasPermission(user: UsersInterface.IUserEntry, level: number, existingUser?: string): boolean - { + { if (existingUser !== undefined) { if ((user.email != existingUser && user.username != existingUser) && user.privileges > level) @@ -196,7 +194,7 @@ export class UsersService return true; } - + /** * Attempts to download a users usage stats * @param {express.Request} req @@ -206,7 +204,7 @@ export class UsersService var that = this; return new Promise(function (resolve, reject) { - request.get(`${UsersService.mediaURL}/get-stats/${user}`, { headers: { cookie: (req).headers.cookie } }, function (error, response, body) + request.get(`${UsersService.usersURL}/stats/get-stats/${user}`, { headers: { cookie: (req).headers.cookie } }, function (error, response, body) { if (error) return reject(error); @@ -234,7 +232,7 @@ export class UsersService { if (error) return reject(error); - + resolve(JSON.parse(body)); }); }); diff --git a/test/tests.js b/test/tests.js index 1bf041fa..74d10a83 100644 --- a/test/tests.js +++ b/test/tests.js @@ -48,7 +48,7 @@ var tempPost = null; describe('Log in as an admin user', function() { it('logged in with a valid username & valid password', function(done){ usersAgent - .post('/users/login').set('Accept', 'application/json').expect(200).expect('Content-Type', /json/) + .post('/login').set('Accept', 'application/json').expect(200).expect('Content-Type', /json/) .send({username: uconfig.adminUser.username, password: uconfig.adminUser.password }) .end(function(err, res) { test.bool(res.body.error).isNotTrue()