@@ -7,6 +7,7 @@ var _ = require('lodash'),
77 Promise = require ( 'bluebird' ) ,
88 errors = require ( '../errors' ) ,
99 config = require ( '../config' ) ,
10+ i18n = require ( '../i18n' ) ,
1011 authentication ;
1112
1213function setupTasks ( object ) {
@@ -38,7 +39,7 @@ function setupTasks(object) {
3839 // Handles the additional values set by the setup screen.
3940 if ( ! _ . isEmpty ( setupUser . blogTitle ) ) {
4041 userSettings . push ( { key : 'title' , value : setupUser . blogTitle } ) ;
41- userSettings . push ( { key : 'description' , value : 'Thoughts, stories and ideas.' } ) ;
42+ userSettings . push ( { key : 'description' , value : i18n . t ( 'common.api.authentication.sampleBlogDescription' ) } ) ;
4243 }
4344
4445 setupUser = user . toJSON ( internal ) ;
@@ -69,15 +70,15 @@ authentication = {
6970 var setup = result . setup [ 0 ] . status ;
7071
7172 if ( ! setup ) {
72- return Promise . reject ( new errors . NoPermissionError ( 'Setup must be completed before making this request.' ) ) ;
73+ return Promise . reject ( new errors . NoPermissionError ( i18n . t ( 'errors.api.authentication.setupMustBeCompleted' ) ) ) ;
7374 }
7475
7576 return utils . checkObject ( object , 'passwordreset' ) ;
7677 } ) . then ( function ( checkedPasswordReset ) {
7778 if ( checkedPasswordReset . passwordreset [ 0 ] . email ) {
7879 email = checkedPasswordReset . passwordreset [ 0 ] . email ;
7980 } else {
80- return Promise . reject ( new errors . BadRequestError ( 'No email provided.' ) ) ;
81+ return Promise . reject ( new errors . BadRequestError ( i18n . t ( 'errors.api.authentication.noEmailProvided' ) ) ) ;
8182 }
8283
8384 return settings . read ( { context : { internal : true } , key : 'dbHash' } )
@@ -94,7 +95,7 @@ authentication = {
9495 mail : [ {
9596 message : {
9697 to : email ,
97- subject : 'Reset Password' ,
98+ subject : i18n . t ( 'common.api.authentication.mail.resetPassword' ) ,
9899 html : emailContent . html ,
99100 text : emailContent . text
100101 } ,
@@ -103,7 +104,7 @@ authentication = {
103104 } ;
104105 return mail . send ( payload , { context : { internal : true } } ) ;
105106 } ) . then ( function ( ) {
106- return Promise . resolve ( { passwordreset : [ { message : 'Check your email for further instructions.' } ] } ) ;
107+ return Promise . resolve ( { passwordreset : [ { message : i18n . t ( 'common.api.authentication.mail.checkEmailForInstructions' ) } ] } ) ;
107108 } ) . catch ( function ( error ) {
108109 return Promise . reject ( error ) ;
109110 } ) ;
@@ -125,7 +126,7 @@ authentication = {
125126 var setup = result . setup [ 0 ] . status ;
126127
127128 if ( ! setup ) {
128- return Promise . reject ( new errors . NoPermissionError ( 'Setup must be completed before making this request.' ) ) ;
129+ return Promise . reject ( new errors . NoPermissionError ( i18n . t ( 'errors.api.authentication.setupMustBeCompleted' ) ) ) ;
129130 }
130131
131132 return utils . checkObject ( object , 'passwordreset' ) ;
@@ -143,7 +144,7 @@ authentication = {
143144 dbHash : dbHash
144145 } ) ;
145146 } ) . then ( function ( ) {
146- return Promise . resolve ( { passwordreset : [ { message : 'Password changed successfully.' } ] } ) ;
147+ return Promise . resolve ( { passwordreset : [ { message : i18n . t ( 'common.api.authentication.mail.passwordChanged' ) } ] } ) ;
147148 } ) . catch ( function ( error ) {
148149 return Promise . reject ( new errors . UnauthorizedError ( error . message ) ) ;
149150 } ) ;
@@ -166,7 +167,7 @@ authentication = {
166167 var setup = result . setup [ 0 ] . status ;
167168
168169 if ( ! setup ) {
169- return Promise . reject ( new errors . NoPermissionError ( 'Setup must be completed before making this request.' ) ) ;
170+ return Promise . reject ( new errors . NoPermissionError ( i18n . t ( 'errors.api.authentication.setupMustBeCompleted' ) ) ) ;
170171 }
171172
172173 return utils . checkObject ( object , 'invitation' ) ;
@@ -189,7 +190,7 @@ authentication = {
189190 // Setting the slug to '' has the model regenerate the slug from the user's name
190191 return dataProvider . User . edit ( { name : name , email : email , slug : '' } , { id : user . id } ) ;
191192 } ) . then ( function ( ) {
192- return Promise . resolve ( { invitation : [ { message : 'Invitation accepted.' } ] } ) ;
193+ return Promise . resolve ( { invitation : [ { message : i18n . t ( 'common.api.authentication.mail.invitationAccepted' ) } ] } ) ;
193194 } ) . catch ( function ( error ) {
194195 return Promise . reject ( new errors . UnauthorizedError ( error . message ) ) ;
195196 } ) ;
@@ -207,7 +208,7 @@ authentication = {
207208 var setup = result . setup [ 0 ] . status ;
208209
209210 if ( ! setup ) {
210- return Promise . reject ( new errors . NoPermissionError ( 'Setup must be completed before making this request.' ) ) ;
211+ return Promise . reject ( new errors . NoPermissionError ( i18n . t ( 'errors.api.authentication.setupMustBeCompleted' ) ) ) ;
211212 }
212213
213214 if ( options . email ) {
@@ -219,7 +220,7 @@ authentication = {
219220 }
220221 } ) ;
221222 } else {
222- return Promise . reject ( new errors . BadRequestError ( 'The server did not receive a valid email' ) ) ;
223+ return Promise . reject ( new errors . BadRequestError ( i18n . t ( 'errors.api.authentication.invalidEmailReceived' ) ) ) ;
223224 }
224225 } ) ;
225226 } ,
@@ -243,7 +244,7 @@ authentication = {
243244 var setup = result . setup [ 0 ] . status ;
244245
245246 if ( setup ) {
246- return Promise . reject ( new errors . NoPermissionError ( 'Setup has already been completed.' ) ) ;
247+ return Promise . reject ( new errors . NoPermissionError ( i18n . t ( 'errors.api.authentication.setupAlreadyCompleted' ) ) ) ;
247248 }
248249
249250 return setupTasks ( object ) ;
@@ -258,7 +259,7 @@ authentication = {
258259 } ) . then ( function ( emailContent ) {
259260 var message = {
260261 to : setupUser . email ,
261- subject : 'Your New Ghost Blog' ,
262+ subject : i18n . t ( 'common.api.authentication.mail.yourNewGhostBlog' ) ,
262263 html : emailContent . html ,
263264 text : emailContent . text
264265 } ,
@@ -272,8 +273,8 @@ authentication = {
272273 mail . send ( payload , { context : { internal : true } } ) . catch ( function ( error ) {
273274 errors . logError (
274275 error . message ,
275- 'Unable to send welcome email, your blog will continue to function.' ,
276- 'Please see http://support.ghost.org/mail/ for instructions on configuring email.'
276+ i18n . t ( 'errors.api.authentication.unableToSendWelcomeEmail' , { url : 'http://support.ghost.org/mail/' } ) ,
277+ i18n . t ( 'errors.api.authentication.checkEmailConfigInstructions' )
277278 ) ;
278279 } ) ;
279280 } ) . then ( function ( ) {
@@ -283,14 +284,14 @@ authentication = {
283284
284285 updateSetup : function updateSetup ( object , options ) {
285286 if ( ! options . context || ! options . context . user ) {
286- return Promise . reject ( new errors . NoPermissionError ( 'You are not logged in.' ) ) ;
287+ return Promise . reject ( new errors . NoPermissionError ( i18n . t ( 'errors.api.authentication.notLoggedIn' ) ) ) ;
287288 }
288289
289290 return dataProvider . User . findOne ( { role : 'Owner' , status : 'all' } ) . then ( function ( result ) {
290291 var user = result . toJSON ( ) ;
291292
292293 if ( user . id !== options . context . user ) {
293- return Promise . reject ( new errors . NoPermissionError ( 'You are not the blog owner.' ) ) ;
294+ return Promise . reject ( new errors . NoPermissionError ( i18n . t ( 'errors.api.authentication.notTheBlogOwner' ) ) ) ;
294295 }
295296
296297 return setupTasks ( object ) ;
@@ -307,14 +308,14 @@ authentication = {
307308 } else if ( object . token_type_hint && object . token_type_hint === 'refresh_token' ) {
308309 token = dataProvider . Refreshtoken ;
309310 } else {
310- return errors . BadRequestError ( 'Invalid token_type_hint given.' ) ;
311+ return errors . BadRequestError ( i18n . t ( 'errors.api.authentication.invalidTokenTypeHint' ) ) ;
311312 }
312313
313314 return token . destroyByToken ( { token : object . token } ) . then ( function ( ) {
314315 return Promise . resolve ( { token : object . token } ) ;
315316 } , function ( ) {
316317 // On error we still want a 200. See https://tools.ietf.org/html/rfc7009#page-5
317- return Promise . resolve ( { token : object . token , error : 'Invalid token provided' } ) ;
318+ return Promise . resolve ( { token : object . token , error : i18n . t ( 'errors.api.authentication.invalidTokenProvided' ) } ) ;
318319 } ) ;
319320 }
320321} ;
0 commit comments