33 'utils/url' ,
44 'core/box' ,
55 'core/session' ,
6- 'core/addons'
7- ] , function ( hr , url , box , session , addons ) {
6+ 'core/addons' ,
7+ 'core/box'
8+ ] , function ( hr , url , box , session , addons , box ) {
89
910 // Define base application
1011 var Application = hr . Application . extend ( {
@@ -23,7 +24,6 @@ define([
2324 // Constructor
2425 initialize : function ( ) {
2526 Application . __super__ . initialize . apply ( this , arguments ) ;
26- this . isAuth = false ;
2727
2828 box . on ( "status" , function ( state ) {
2929 this . $ ( ".codebox-connexion-alert" ) . toggle ( ! state ) ;
@@ -37,7 +37,6 @@ define([
3737 return {
3838 'email' : queries . email || hr . Storage . get ( "email" ) ,
3939 'token' : queries . token || hr . Storage . get ( "token" ) ,
40- 'isAuth' : this . isAuth
4140 } ;
4241 } ,
4342
@@ -50,7 +49,7 @@ define([
5049
5150 if ( email && password ) {
5251 this . doLogin ( email , password , true ) ;
53- } else if ( this . isAuth ) {
52+ } else if ( box . isAuth ( ) ) {
5453 addons . loadAll ( ) . then ( function ( ) {
5554 that . $ ( ".codebox-loading-alert" ) . remove ( ) ;
5655
@@ -73,14 +72,18 @@ define([
7372 var password = this . $ ( ".login-box #login-token" ) . val ( ) ;
7473 var tosave = this . $ ( ".login-box #login-save" ) . is ( ":checked" ) ;
7574
76- this . doLogin ( email , password , tosave ) . fail ( function ( ) {
77- that . $ ( ".login-box .form-group" ) . addClass ( "has-error" ) ;
78- } ) ;
75+ this . doLogin ( email , password , tosave ) ;
7976 } ,
8077
8178 // Do login
8279 doLogin : function ( email , password , tosave ) {
8380 var that = this ;
81+
82+ // If no password: generate a random one
83+ if ( ! password ) {
84+ password = Math . random ( ) . toString ( 36 ) . substring ( 8 ) ;
85+ }
86+
8487 return session . start ( email , password ) . then ( function ( ) {
8588 if ( tosave ) {
8689 hr . Storage . set ( "email" , email ) ;
@@ -89,9 +92,9 @@ define([
8992 hr . Storage . set ( "email" , "" ) ;
9093 hr . Storage . set ( "token" , "" ) ;
9194 }
92-
93- that . isAuth = true ;
9495 that . render ( ) ;
96+ } ) . fail ( function ( ) {
97+ that . $ ( ".login-box .form-group" ) . addClass ( "has-error" ) ;
9598 } ) ;
9699 }
97100 } ) ;
0 commit comments