77 * Module Dependencies.
88 */
99
10+ var g = require ( 'strong-globalize' ) ( ) ;
11+
1012var loopback = require ( '../../lib/loopback' ) ;
1113var utils = require ( '../../lib/utils' ) ;
1214var path = require ( 'path' ) ;
@@ -203,22 +205,22 @@ module.exports = function(User) {
203205 realmDelimiter ) ;
204206
205207 if ( realmRequired && ! query . realm ) {
206- var err1 = new Error ( 'realm is required' ) ;
208+ var err1 = new Error ( g . f ( 'realm is required' ) ) ;
207209 err1 . statusCode = 400 ;
208210 err1 . code = 'REALM_REQUIRED' ;
209211 fn ( err1 ) ;
210212 return fn . promise ;
211213 }
212214 if ( ! query . email && ! query . username ) {
213- var err2 = new Error ( ' username or email is required') ;
215+ var err2 = new Error ( g . f ( '{{ username}} or {{ email}} is required') ) ;
214216 err2 . statusCode = 400 ;
215217 err2 . code = 'USERNAME_EMAIL_REQUIRED' ;
216218 fn ( err2 ) ;
217219 return fn . promise ;
218220 }
219221
220222 self . findOne ( { where : query } , function ( err , user ) {
221- var defaultError = new Error ( 'login failed' ) ;
223+ var defaultError = new Error ( g . f ( 'login failed' ) ) ;
222224 defaultError . statusCode = 401 ;
223225 defaultError . code = 'LOGIN_FAILED' ;
224226
@@ -248,7 +250,7 @@ module.exports = function(User) {
248250 if ( self . settings . emailVerificationRequired && ! user . emailVerified ) {
249251 // Fail to log in if email verification is not done yet
250252 debug ( 'User email has not been verified' ) ;
251- err = new Error ( 'login failed as the email has not been verified' ) ;
253+ err = new Error ( g . f ( 'login failed as the email has not been verified' ) ) ;
252254 err . statusCode = 401 ;
253255 err . code = 'LOGIN_FAILED_EMAIL_NOT_VERIFIED' ;
254256 fn ( err ) ;
@@ -295,7 +297,7 @@ module.exports = function(User) {
295297 } else if ( accessToken ) {
296298 accessToken . destroy ( fn ) ;
297299 } else {
298- fn ( new Error ( 'could not find accessToken' ) ) ;
300+ fn ( new Error ( g . f ( 'could not find {{ accessToken}}' ) ) ) ;
299301 }
300302 } ) ;
301303 return fn . promise ;
@@ -446,15 +448,21 @@ module.exports = function(User) {
446448
447449 options . text = options . text . replace ( / \{ h r e f \} / g, options . verifyHref ) ;
448450
451+ options . text = g . f ( options . text ) ;
452+
449453 options . to = options . to || user . email ;
450454
451455 options . subject = options . subject || 'Thanks for Registering' ;
452456
457+ options . subject = g . f ( options . subject ) ;
458+
453459 options . headers = options . headers || { } ;
454460
455461 var template = loopback . template ( options . template ) ;
456462 options . html = template ( options ) ;
457463
464+ options . html = g . f ( options . html ) ;
465+
458466 Email . send ( options , function ( err , email ) {
459467 if ( err ) {
460468 fn ( err ) ;
@@ -510,11 +518,11 @@ module.exports = function(User) {
510518 } ) ;
511519 } else {
512520 if ( user ) {
513- err = new Error ( 'Invalid token: ' + token ) ;
521+ err = new Error ( g . f ( 'Invalid token: %s' , token ) ) ;
514522 err . statusCode = 400 ;
515523 err . code = 'INVALID_TOKEN' ;
516524 } else {
517- err = new Error ( 'User not found: ' + uid ) ;
525+ err = new Error ( g . f ( 'User not found: %s' , uid ) ) ;
518526 err . statusCode = 404 ;
519527 err . code = 'USER_NOT_FOUND' ;
520528 }
@@ -543,7 +551,7 @@ module.exports = function(User) {
543551
544552 options = options || { } ;
545553 if ( typeof options . email !== 'string' ) {
546- var err = new Error ( 'Email is required' ) ;
554+ var err = new Error ( g . f ( 'Email is required' ) ) ;
547555 err . statusCode = 400 ;
548556 err . code = 'EMAIL_REQUIRED' ;
549557 cb ( err ) ;
@@ -555,7 +563,7 @@ module.exports = function(User) {
555563 return cb ( err ) ;
556564 }
557565 if ( ! user ) {
558- err = new Error ( 'Email not found' ) ;
566+ err = new Error ( g . f ( 'Email not found' ) ) ;
559567 err . statusCode = 404 ;
560568 err . code = 'EMAIL_NOT_FOUND' ;
561569 return cb ( err ) ;
@@ -591,7 +599,7 @@ module.exports = function(User) {
591599 if ( typeof plain === 'string' && plain ) {
592600 return true ;
593601 }
594- var err = new Error ( 'Invalid password: ' + plain ) ;
602+ var err = new Error ( g . f ( 'Invalid password: %s' , plain ) ) ;
595603 err . statusCode = 422 ;
596604 throw err ;
597605 } ;
@@ -650,20 +658,21 @@ module.exports = function(User) {
650658 UserModel . remoteMethod (
651659 'login' ,
652660 {
653- description : 'Login a user with username/email and password.' ,
661+ description : g . f ( 'Login a user with username/email and password.' ) ,
654662 accepts : [
655663 { arg : 'credentials' , type : 'object' , required : true , http : { source : 'body' } } ,
656664 { arg : 'include' , type : [ 'string' ] , http : { source : 'query' } ,
657- description : 'Related objects to include in the response. ' +
658- 'See the description of return value for more details.' } ,
665+ description : g . f ( 'Related objects to include in the response. ' +
666+ 'See the description of return value for more details.' ) } ,
659667 ] ,
660668 returns : {
661669 arg : 'accessToken' , type : 'object' , root : true ,
662670 description :
663- 'The response body contains properties of the AccessToken created on login.\n' +
671+ g . f ( 'The response body contains properties of the {{ AccessToken}} created on login.\n' +
664672 'Depending on the value of `include` parameter, the body may contain ' +
665673 'additional properties:\n\n' +
666- ' - `user` - `{User}` - Data of the currently logged in user. (`include=user`)\n\n' ,
674+ ' - `user` - `U+007BUserU+007D` - Data of the currently logged in user. ' +
675+ '{{(`include=user`)}}\n\n' ) ,
667676 } ,
668677 http : { verb : 'post' } ,
669678 }
@@ -672,16 +681,16 @@ module.exports = function(User) {
672681 UserModel . remoteMethod (
673682 'logout' ,
674683 {
675- description : 'Logout a user with access token.' ,
684+ description : g . f ( 'Logout a user with access token.' ) ,
676685 accepts : [
677686 { arg : 'access_token' , type : 'string' , required : true , http : function ( ctx ) {
678687 var req = ctx && ctx . req ;
679688 var accessToken = req && req . accessToken ;
680689 var tokenID = accessToken && accessToken . id ;
681690
682691 return tokenID ;
683- } , description : 'Do not supply this argument, it is automatically extracted ' +
684- 'from request headers.' ,
692+ } , description : g . f ( 'Do not supply this argument, it is automatically extracted ' +
693+ 'from request headers.' ) ,
685694 } ,
686695 ] ,
687696 http : { verb : 'all' } ,
@@ -691,7 +700,7 @@ module.exports = function(User) {
691700 UserModel . remoteMethod (
692701 'confirm' ,
693702 {
694- description : 'Confirm a user registration with email verification token.' ,
703+ description : g . f ( 'Confirm a user registration with email verification token.' ) ,
695704 accepts : [
696705 { arg : 'uid' , type : 'string' , required : true } ,
697706 { arg : 'token' , type : 'string' , required : true } ,
@@ -704,7 +713,7 @@ module.exports = function(User) {
704713 UserModel . remoteMethod (
705714 'resetPassword' ,
706715 {
707- description : 'Reset password for a user with email.' ,
716+ description : g . f ( 'Reset password for a user with email.' ) ,
708717 accepts : [
709718 { arg : 'options' , type : 'object' , required : true , http : { source : 'body' } } ,
710719 ] ,
@@ -715,7 +724,7 @@ module.exports = function(User) {
715724 UserModel . afterRemote ( 'confirm' , function ( ctx , inst , next ) {
716725 if ( ctx . args . redirect !== undefined ) {
717726 if ( ! ctx . res ) {
718- return next ( new Error ( 'The transport does not support HTTP redirects.' ) ) ;
727+ return next ( new Error ( g . f ( 'The transport does not support HTTP redirects.' ) ) ) ;
719728 }
720729 ctx . res . location ( ctx . args . redirect ) ;
721730 ctx . res . status ( 302 ) ;
@@ -733,7 +742,7 @@ module.exports = function(User) {
733742 // email validation regex
734743 var re = / ^ ( ( [ ^ < > ( ) [ \] \\ . , ; : \s @ \" ] + ( \. [ ^ < > ( ) [ \] \\ . , ; : \s @ \" ] + ) * ) | ( \" .+ \" ) ) @ ( ( \[ [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } \] ) | ( ( [ a - z A - Z \- 0 - 9 ] + \. ) + [ a - z A - Z ] { 2 , } ) ) $ / ;
735744
736- UserModel . validatesFormatOf ( 'email' , { with : re , message : 'Must provide a valid email' } ) ;
745+ UserModel . validatesFormatOf ( 'email' , { with : re , message : g . f ( 'Must provide a valid email' ) } ) ;
737746
738747 // FIXME: We need to add support for uniqueness of composite keys in juggler
739748 if ( ! ( UserModel . settings . realmRequired || UserModel . settings . realmDelimiter ) ) {
0 commit comments