11window . matrixLogin = {
22 endpoint : location . origin + "/_matrix/client/r0/login" ,
33 serverAcceptsPassword : false ,
4+ serverAcceptsCas : false ,
45 serverAcceptsSso : false ,
56} ;
67
7- var title_pre_auth = "Log in with one of the following methods" ;
8- var title_post_auth = "Logging in..." ;
9-
108var submitPassword = function ( user , pwd ) {
119 console . log ( "Logging in with password..." ) ;
12- set_title ( title_post_auth ) ;
1310 var data = {
1411 type : "m.login.password" ,
1512 user : user ,
1613 password : pwd ,
1714 } ;
1815 $ . post ( matrixLogin . endpoint , JSON . stringify ( data ) , function ( response ) {
16+ show_login ( ) ;
1917 matrixLogin . onLogin ( response ) ;
2018 } ) . error ( errorFunc ) ;
2119} ;
2220
2321var submitToken = function ( loginToken ) {
2422 console . log ( "Logging in with login token..." ) ;
25- set_title ( title_post_auth ) ;
2623 var data = {
2724 type : "m.login.token" ,
2825 token : loginToken
2926 } ;
3027 $ . post ( matrixLogin . endpoint , JSON . stringify ( data ) , function ( response ) {
28+ show_login ( ) ;
3129 matrixLogin . onLogin ( response ) ;
3230 } ) . error ( errorFunc ) ;
3331} ;
3432
3533var errorFunc = function ( err ) {
36- // We want to show the error to the user rather than redirecting immediately to the
37- // SSO portal (if SSO is the only login option), so we inhibit the redirect.
38- show_login ( true ) ;
34+ show_login ( ) ;
3935
4036 if ( err . responseJSON && err . responseJSON . error ) {
4137 setFeedbackString ( err . responseJSON . error + " (" + err . responseJSON . errcode + ")" ) ;
@@ -49,33 +45,26 @@ var setFeedbackString = function(text) {
4945 $ ( "#feedback" ) . text ( text ) ;
5046} ;
5147
52- var show_login = function ( inhibit_redirect ) {
48+ var show_login = function ( ) {
49+ $ ( "#loading" ) . hide ( ) ;
50+
5351 var this_page = window . location . origin + window . location . pathname ;
5452 $ ( "#sso_redirect_url" ) . val ( this_page ) ;
5553
56- // If inhibit_redirect is false, and SSO is the only supported login method, we can
57- // redirect straight to the SSO page
58- if ( matrixLogin . serverAcceptsSso ) {
59- if ( ! inhibit_redirect && ! matrixLogin . serverAcceptsPassword ) {
60- $ ( "#sso_form" ) . submit ( ) ;
61- return ;
62- }
63-
64- // Otherwise, show the SSO form
65- $ ( "#sso_form" ) . show ( ) ;
66- }
67-
6854 if ( matrixLogin . serverAcceptsPassword ) {
6955 $ ( "#password_flow" ) . show ( ) ;
7056 }
7157
72- if ( ! matrixLogin . serverAcceptsPassword && ! matrixLogin . serverAcceptsSso ) {
73- $ ( "#no_login_types" ) . show ( ) ;
58+ if ( matrixLogin . serverAcceptsSso ) {
59+ $ ( "#sso_flow" ) . show ( ) ;
60+ } else if ( matrixLogin . serverAcceptsCas ) {
61+ $ ( "#sso_form" ) . attr ( "action" , "/_matrix/client/r0/login/cas/redirect" ) ;
62+ $ ( "#sso_flow" ) . show ( ) ;
7463 }
7564
76- set_title ( title_pre_auth ) ;
77-
78- $ ( "#loading" ) . hide ( ) ;
65+ if ( ! matrixLogin . serverAcceptsPassword && ! matrixLogin . serverAcceptsCas && ! matrixLogin . serverAcceptsSso ) {
66+ $ ( "#no_login_types" ) . show ( ) ;
67+ }
7968} ;
8069
8170var show_spinner = function ( ) {
@@ -85,15 +74,17 @@ var show_spinner = function() {
8574 $ ( "#loading" ) . show ( ) ;
8675} ;
8776
88- var set_title = function ( title ) {
89- $ ( "#title" ) . text ( title ) ;
90- } ;
9177
9278var fetch_info = function ( cb ) {
9379 $ . get ( matrixLogin . endpoint , function ( response ) {
9480 var serverAcceptsPassword = false ;
81+ var serverAcceptsCas = false ;
9582 for ( var i = 0 ; i < response . flows . length ; i ++ ) {
9683 var flow = response . flows [ i ] ;
84+ if ( "m.login.cas" === flow . type ) {
85+ matrixLogin . serverAcceptsCas = true ;
86+ console . log ( "Server accepts CAS" ) ;
87+ }
9788 if ( "m.login.sso" === flow . type ) {
9889 matrixLogin . serverAcceptsSso = true ;
9990 console . log ( "Server accepts SSO" ) ;
@@ -111,7 +102,7 @@ var fetch_info = function(cb) {
111102matrixLogin . onLoad = function ( ) {
112103 fetch_info ( function ( ) {
113104 if ( ! try_token ( ) ) {
114- show_login ( false ) ;
105+ show_login ( ) ;
115106 }
116107 } ) ;
117108} ;
0 commit comments