@@ -102,6 +102,7 @@ export class Angular2TokenService implements CanActivate {
102102
103103 let defaultOptions : Angular2TokenOptions = {
104104 apiPath : null ,
105+ apiBase : '' ,
105106
106107 signInPath : 'auth/sign_in' ,
107108 signInRedirect : null ,
@@ -122,11 +123,14 @@ export class Angular2TokenService implements CanActivate {
122123
123124 userTypes : null ,
124125
126+ oAuthBase : window . location . origin ,
125127 oAuthPaths : {
126128 github : 'auth/github'
127129 } ,
128130 oAuthCallbackPath : 'oauth_callback' ,
129131 oAuthWindowType : 'newWindow' ,
132+ oAuthWindowOptions : null ,
133+
130134 globalOptions : {
131135 headers : {
132136 'Content-Type' : 'application/json' ,
@@ -150,6 +154,7 @@ export class Angular2TokenService implements CanActivate {
150154
151155 let body = JSON . stringify ( {
152156 email : registerData . email ,
157+ name : registerData . name ,
153158 password : registerData . password ,
154159 password_confirmation : registerData . passwordConfirmation ,
155160 confirm_success_url : this . _options . registerAccountCallback
@@ -191,7 +196,20 @@ export class Angular2TokenService implements CanActivate {
191196 let authUrl : string = this . _buildOAuthUrl ( oAuthPath , callbackUrl , oAuthWindowType ) ;
192197
193198 if ( oAuthWindowType == 'newWindow' ) {
194- let popup = window . open ( authUrl , '_blank' , 'closebuttoncaption=Cancel' ) ;
199+ let oAuthWindowOptions = this . _options . oAuthWindowOptions ;
200+ let windowOptions = '' ;
201+
202+ if ( oAuthWindowOptions ) {
203+ for ( let key in oAuthWindowOptions ) {
204+ windowOptions += `,${ key } =${ oAuthWindowOptions [ key ] } ` ;
205+ }
206+ }
207+
208+ let popup = window . open (
209+ authUrl ,
210+ '_blank' ,
211+ `closebuttoncaption=Cancel${ windowOptions } `
212+ ) ;
195213 return this . _requestCredentialsViaPostMessage ( popup ) ;
196214 } else if ( oAuthWindowType == 'sameWindow' ) {
197215 window . location . href = authUrl ;
@@ -242,21 +260,26 @@ export class Angular2TokenService implements CanActivate {
242260 if ( updatePasswordData . userType != null )
243261 this . _currentUserType = this . _getUserTypeByName ( updatePasswordData . userType ) ;
244262
245- let body : string ;
263+ let args : any ;
246264
247265 if ( updatePasswordData . passwordCurrent == null ) {
248- body = JSON . stringify ( {
266+ args = {
249267 password : updatePasswordData . password ,
250268 password_confirmation : updatePasswordData . passwordConfirmation
251- } ) ;
269+ }
252270 } else {
253- body = JSON . stringify ( {
271+ args = {
254272 current_password : updatePasswordData . passwordCurrent ,
255273 password : updatePasswordData . password ,
256274 password_confirmation : updatePasswordData . passwordConfirmation
257- } ) ;
275+ } ;
276+ }
277+
278+ if ( updatePasswordData . resetPasswordToken ) {
279+ args . reset_password_token = updatePasswordData . resetPasswordToken ;
258280 }
259281
282+ let body = JSON . stringify ( args ) ;
260283 return this . put ( this . _constructUserPath ( ) + this . _options . updatePasswordPath , body ) ;
261284 }
262285
@@ -505,16 +528,16 @@ export class Angular2TokenService implements CanActivate {
505528
506529 private _constructUserPath ( ) : string {
507530 if ( this . _currentUserType == null )
508- return '' ;
531+ return '/ ' ;
509532 else
510533 return this . _currentUserType . path + '/' ;
511534 }
512535
513536 private _constructApiPath ( ) : string {
514537 if ( this . _options . apiPath == null )
515- return ' ';
538+ return this . _options . apiBase + '/ ';
516539 else
517- return this . _options . apiPath + '/' ;
540+ return this . _options . apiBase + '/' + this . _options . apiPath + '/' ;
518541 }
519542
520543 private _getOAuthPath ( oAuthType : string ) : string {
@@ -523,20 +546,20 @@ export class Angular2TokenService implements CanActivate {
523546 oAuthPath = this . _options . oAuthPaths [ oAuthType ] ;
524547
525548 if ( oAuthPath == null )
526- oAuthPath = ' /auth/${oAuthType}' ;
549+ oAuthPath = ` /auth/${ oAuthType } ` ;
527550
528551 return oAuthPath ;
529552 }
530553
531554 private _buildOAuthUrl ( oAuthPath : string , callbackUrl : string , windowType : string ) : string {
532555 let url : string ;
533556
534- url = '${window.location.origin }/${oAuthPath}' ;
535- url += ' ?omniauth_window_type=${windowType}' ;
536- url += ' &auth_origin_url=${encodeURIComponent(callbackUrl)}' ;
557+ url = ` ${ this . _options . oAuthBase } /${ oAuthPath } ` ;
558+ url += ` ?omniauth_window_type=${ windowType } ` ;
559+ url += ` &auth_origin_url=${ encodeURIComponent ( callbackUrl ) } ` ;
537560
538561 if ( this . _currentUserType != null )
539- url += ' &resource_class=${this._currentUserType.name}' ;
562+ url += ` &resource_class=${ this . _currentUserType . name } ` ;
540563
541564 return url ;
542565 }
@@ -545,7 +568,7 @@ export class Angular2TokenService implements CanActivate {
545568 let pollerObserv = Observable . interval ( 500 ) ;
546569
547570 let responseObserv = Observable . fromEvent ( window , 'message' ) . pluck ( 'data' )
548- . filter ( this . _oAuthWindowResponseFilter ) ;
571+ . filter ( this . _oAuthWindowResponseFilter ) ;
549572
550573 let responseSubscription = responseObserv . subscribe (
551574 this . _getAuthDataFromPostMessage . bind ( this )
0 commit comments