@@ -28,11 +28,6 @@ function AuthModal(options) {
2828 }
2929
3030 var self = this ;
31- if ( ! options . callback ) {
32- options . callback = function ( ) {
33- self . successRedirect ( ) ;
34- } ;
35- }
3631
3732 this . options = options ;
3833 this . setContent ( clientRender ( loginForm ) ) ;
@@ -168,7 +163,7 @@ AuthModal.prototype.initEventHandlers = function() {
168163 var request = this . request ( {
169164 method : 'POST' ,
170165 url : '/auth/reverify' ,
171- body : payload
166+ body : payload
172167 } ) ;
173168
174169 var self = this ;
@@ -214,10 +209,10 @@ AuthModal.prototype.submitRegisterForm = function(form) {
214209 payload . append ( "successRedirect" , this . options . successRedirect ) ;
215210
216211 var request = this . request ( {
217- method : 'POST' ,
218- url : '/auth/register' ,
212+ method : 'POST' ,
213+ url : '/auth/register' ,
219214 normalStatuses : [ 201 , 400 ] ,
220- body : payload
215+ body : payload
221216 } ) ;
222217
223218 var self = this ;
@@ -226,15 +221,14 @@ AuthModal.prototype.submitRegisterForm = function(form) {
226221 if ( this . status == 201 ) {
227222 self . setContent ( clientRender ( loginForm ) ) ;
228223 self . showFormMessage (
229- "<p>С адреса [email protected] отправлено письмо со ссылкой-подтверждением.</p>" + 230- "<p><a href='#' data-action-verify-email='" + form . elements . email . value + "'>перезапросить подтверждение.</a></p>" ,
224+ "<p>С адреса [email protected] отправлено письмо со ссылкой-подтверждением.</p>" + 225+ "<p><a href='#' data-action-verify-email='" + form . elements . email . value + "'>перезапросить подтверждение.</a></p>" ,
231226 'success'
232227 ) ;
233228 return ;
234229 }
235230
236231 if ( this . status == 400 ) {
237- debugger ;
238232 for ( var field in event . result . errors ) {
239233 self . showInputError ( form . elements [ field ] , event . result . errors [ field ] ) ;
240234 }
@@ -263,10 +257,10 @@ AuthModal.prototype.submitForgotForm = function(form) {
263257 payload . append ( "successRedirect" , this . options . successRedirect ) ;
264258
265259 var request = this . request ( {
266- method : 'POST' ,
267- url : '/auth/forgot' ,
260+ method : 'POST' ,
261+ url : '/auth/forgot' ,
268262 normalStatuses : [ 200 , 404 ] ,
269- body : payload
263+ body : payload
270264 } ) ;
271265
272266 var self = this ;
@@ -325,22 +319,36 @@ AuthModal.prototype.submitLoginForm = function(form) {
325319
326320 if ( hasErrors ) return ;
327321
328- var request = this . request ( {
329- method : 'POST' ,
330- url : '/auth/login/local' ,
322+ var request = xhr ( {
323+ method : 'POST' ,
324+ url : '/auth/login/local' ,
325+ noDocumentEvents : true , // we handle all events/errors in this code
331326 normalStatuses : [ 200 , 401 ] ,
332- body : new FormData ( form )
327+ body : new FormData ( form )
333328 } ) ;
334329
335- var self = this ;
336- request . addEventListener ( 'success' , function ( event ) {
330+ var onEnd = this . startRequestIndication ( ) ;
331+
332+ request . addEventListener ( 'success' , ( event ) => {
337333
338- if ( this . status != 200 ) {
339- self . onAuthFailure ( event . result . message ) ;
334+ if ( request . status == 401 ) {
335+ onEnd ( ) ;
336+ this . onAuthFailure ( event . result . message ) ;
340337 return ;
341338 }
342339
343- self . onAuthSuccess ( event . result . user ) ;
340+ // don't stop progress indication if login successful && we're making redirect
341+ if ( ! this . options . callback ) {
342+ this . onAuthSuccess ( event . result . user ) ;
343+ } else {
344+ onEnd ( ) ;
345+ this . onAuthSuccess ( event . result . user ) ;
346+ }
347+ } ) ;
348+
349+ request . addEventListener ( 'fail' , ( event ) => {
350+ onEnd ( ) ;
351+ this . onAuthFailure ( event . reason ) ;
344352 } ) ;
345353
346354} ;
@@ -362,7 +370,11 @@ AuthModal.prototype.openAuthPopup = function(url) {
362370 */
363371AuthModal . prototype . onAuthSuccess = function ( user ) {
364372 window . currentUser = user ;
365- this . options . callback ( ) ;
373+ if ( this . options . callback ) {
374+ this . options . callback ( ) ;
375+ } else {
376+ this . successRedirect ( ) ;
377+ }
366378} ;
367379
368380
0 commit comments