@@ -81,21 +81,23 @@ class LedInfo {
8181}
8282
8383class WifiInfo {
84- constructor ( hostname , ssid , password ) {
84+ constructor ( hostname , ssid , authType , password ) {
8585 this . hostname = hostname
8686 this . ssid = ssid ;
87+ this . authType = authType ;
8788 this . password = password ;
8889 }
8990 toJson ( ) {
9091 return {
9192 "hostname" : this . hostname ,
9293 "SSID" : this . ssid ,
94+ "auth_type" : this . authType ,
9395 "password" : this . password ,
9496 } ;
9597 }
9698 static Builder = class {
9799 fromJson ( message ) {
98- return new WifiInfo ( message . hostname , message . SSID , atob ( message . password ) ) ;
100+ return new WifiInfo ( message . hostname , message . SSID , message . auth_type , atob ( message . password ) ) ;
99101 }
100102 }
101103}
@@ -348,6 +350,15 @@ function getWifiInfo() {
348350 let wifiInfo = new WifiInfo . Builder ( ) . fromJson ( data ) ;
349351 document . getElementById ( "hostname" ) . value = wifiInfo . hostname ;
350352 document . getElementById ( "ssid" ) . value = wifiInfo . ssid ;
353+ selectRadioChoiceByName ( "authTypeChoice" , wifiInfo . authType ) ;
354+ if ( wifiInfo . authType == "open" ) {
355+ wifiInfo . password = "" ;
356+ document . getElementById ( "password" ) . disabled = true ;
357+ document . getElementById ( "passwordVerify" ) . disabled = true ;
358+ } else {
359+ document . getElementById ( "password" ) . disabled = false ;
360+ document . getElementById ( "passwordVerify" ) . disabled = false ;
361+ }
351362 document . getElementById ( "password" ) . value = wifiInfo . password ;
352363 document . getElementById ( "passwordVerify" ) . value = wifiInfo . password ;
353364 } )
@@ -371,22 +382,31 @@ function setWifiInfo() {
371382 logLabel . style . color = errorColor ;
372383 return ;
373384 }
374- if ( document . getElementById ( "password" ) . value == "" ) {
375- console . log ( "Wifi password cannot be empty" ) ;
376- logLabel . innerHTML = "Error: Wifi password cannot be empty" ;
377- logLabel . style . color = errorColor ;
378- return ;
379- }
380- if ( document . getElementById ( "password" ) . value != document . getElementById ( "passwordVerify" ) . value ) {
381- console . log ( "Wifi passwords are not matching" ) ;
382- logLabel . innerHTML = "Error: Passwords are not matching" ;
383- logLabel . style . color = errorColor ;
384- return ;
385+ if ( getSelectedRadioChoice ( "authTypeChoice" ) != "open" ) {
386+ if ( document . getElementById ( "password" ) . value == "" ) {
387+ console . log ( "Wifi password cannot be empty" ) ;
388+ logLabel . innerHTML = "Error: Wifi password cannot be empty" ;
389+ logLabel . style . color = errorColor ;
390+ return ;
391+ }
392+ if ( document . getElementById ( "password" ) . value . length < 8 ) {
393+ console . log ( "Use at least 8 characters for password" ) ;
394+ logLabel . innerHTML = "Error: Use at least 8 characters for password" ;
395+ logLabel . style . color = errorColor ;
396+ return ;
397+ }
398+ if ( document . getElementById ( "password" ) . value != document . getElementById ( "passwordVerify" ) . value ) {
399+ console . log ( "Wifi passwords are not matching" ) ;
400+ logLabel . innerHTML = "Error: Passwords are not matching" ;
401+ logLabel . style . color = errorColor ;
402+ return ;
403+ }
385404 }
386405 logLabel . innerHTML = "" ;
387406 let wifiInfo = new WifiInfo (
388407 document . getElementById ( "hostname" ) . value ,
389408 document . getElementById ( "ssid" ) . value ,
409+ getSelectedRadioChoice ( "authTypeChoice" ) ,
390410 btoa ( document . getElementById ( "password" ) . value ) ) ;
391411 const requestOptions = {
392412 method : 'POST' ,
@@ -411,7 +431,9 @@ function selectRadioChoiceByName(name, value) {
411431 for ( i = 0 ; i < choices . length ; i ++ ) {
412432 if ( choices [ i ] . getAttribute ( "value" ) == value ) {
413433 choices [ i ] . className += " active" ;
414- break ;
434+ } else {
435+ // clear if any choice was active previously
436+ choices [ i ] . className = choices [ i ] . className . replace ( " active" , "" ) ;
415437 }
416438 }
417439}
@@ -458,4 +480,16 @@ function updateColorBox() {
458480 hsv . v = document . getElementById ( "sliderValue" ) . value ;
459481 let color = "hsla(" + hsv . h + "," + hsv . s + "%," + "50%," + hsv . v + "%)" ;
460482 document . getElementById ( "colorBox" ) . style . backgroundColor = color ;
483+ }
484+
485+ function handleAtuhTypeChoice ( evt ) {
486+ if ( selectRadioChoiceByEvent ( evt ) == "open" ) {
487+ document . getElementById ( "password" ) . disabled = true ;
488+ document . getElementById ( "password" ) . value = "" ;
489+ document . getElementById ( "passwordVerify" ) . disabled = true ;
490+ document . getElementById ( "passwordVerify" ) . value = "" ;
491+ } else {
492+ document . getElementById ( "password" ) . disabled = false ;
493+ document . getElementById ( "passwordVerify" ) . disabled = false ;
494+ }
461495}
0 commit comments