1- var ed = {
1+ var $ = id => document . getElementById ( id )
2+
3+ var riv = {
24 partnerId : 1222 ,
35 brand : 'RiV Mesh' ,
46 applicationName : "RiV Mesh QNAP NAS OS App" ,
@@ -12,9 +14,9 @@ var ed = {
1214 }
1315} ;
1416
15- $ ( function ( ) {
17+ function handleToken ( ) {
1618
17- ed . nasLoginCall = function ( nasLoginSuccess , nasLoginFailure ) {
19+ riv . nasLoginCall = function ( nasLoginSuccess , nasLoginFailure ) {
1820 /* encode function start */
1921 var ezEncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" ;
2022
@@ -78,17 +80,19 @@ $(function () {
7880
7981 var d = new Date ( ) ;
8082 d . setTime ( d . getTime ( ) + ( 30 * 60 * 1000 ) ) ;
81- document . cookie = "qnapuser=" + encodeURIComponent ( $ ( '#nasInputUser' ) . val ( ) ) + "; expires=" + d . toUTCString ( ) + "; path=/" ;
82- document . cookie = "qnappwd=" + encodeURIComponent ( ezEncode ( utf16to8 ( $ ( '#nasInputPassword' ) . val ( ) ) ) ) + "; expires=" + d . toUTCString ( ) + "; path=/" ;
83- $ . ajax ( { url : "rest/info" } ) . done ( function ( response ) {
84- window . location . reload ( ) ;
85- checkError ( response ) ;
86- } ) . fail ( function ( ) {
87- ed . nasLogoutCall ( ) ;
88- nasLoginFailure ( ) ;
83+ document . cookie = "qnapuser=" + encodeURIComponent ( $ ( 'username' ) . value ) + "; expires=" + d . toUTCString ( ) + "; path=/" ;
84+ document . cookie = "qnappwd=" + encodeURIComponent ( ezEncode ( utf16to8 ( $ ( 'password' ) . value ) ) ) + "; expires=" + d . toUTCString ( ) + "; path=/" ;
85+ fetch ( 'api/self' ) . then ( function ( response ) {
86+ if ( response . status === 200 ) {
87+ window . location . reload ( ) ;
88+ checkError ( response ) ;
89+ } else {
90+ riv . nasLogoutCall ( ) ;
91+ nasLoginFailure ( ) ;
92+ }
8993 } ) ;
9094 } ;
91- ed . nasLogoutCall = function ( ) {
95+ riv . nasLogoutCall = function ( ) {
9296 document . cookie = "qnapuser=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/" ;
9397 document . cookie = "qnappwd=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/" ;
9498 } ;
@@ -98,7 +102,9 @@ $(function () {
98102 ) ) ;
99103 return matches ? decodeURIComponent ( matches [ 1 ] ) : undefined ;
100104 }
101- ed . getNasUser = function ( ) {
105+ riv . getNasUser = function ( ) {
102106 return getCookie ( 'qnapuser' ) ;
103107 } ;
104- } ) ;
108+ } ;
109+
110+ window . onload = handleToken ;
0 commit comments