diff options
| author | Noah Hefner <noahhefner@users.noreply.github.com> | 2021-07-15 10:14:06 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-15 07:14:06 -0700 |
| commit | 9df3bbcb402cc35e2b2cd8aa2ec9d2b799e84e3e (patch) | |
| tree | e879e96754eb1221d5a38151b11b0de265a8198e /src/components | |
| parent | 8c812c903f38ddffda0fd696bb32a0aa71db4fd6 (diff) | |
[Feature Request #39] Added encryption options (#43)
* Added encryption options [Feature Request #39]
* Added encryption options [Feature Request #39]
* Removed encrypt options from print page
* made requested changes
* fixed css issue
* checked WPA/WPA2 as default encryption type
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/Card.js | 81 | ||||
| -rw-r--r-- | src/components/style.css | 2 |
2 files changed, 64 insertions, 19 deletions
diff --git a/src/components/Card.js b/src/components/Card.js index ffdd097..98c5f6b 100644 --- a/src/components/Card.js +++ b/src/components/Card.js | |||
| @@ -7,6 +7,7 @@ export const Card = () => { | |||
| 7 | const [qrvalue, setQrvalue] = useState(''); | 7 | const [qrvalue, setQrvalue] = useState(''); |
| 8 | const [network, setNetwork] = useState({ | 8 | const [network, setNetwork] = useState({ |
| 9 | ssid: '', | 9 | ssid: '', |
| 10 | encryptionMode: 'WPA', | ||
| 10 | password: '', | 11 | password: '', |
| 11 | hidePassword: false, | 12 | hidePassword: false, |
| 12 | }); | 13 | }); |
| @@ -28,8 +29,13 @@ export const Card = () => { | |||
| 28 | }; | 29 | }; |
| 29 | 30 | ||
| 30 | const onPrint = () => { | 31 | const onPrint = () => { |
| 31 | if (network.password.length < 8) { | 32 | if (network.password.length < 8 && network.encryptionMode === 'WPA') { |
| 32 | alert('Password must be at least 8 characters'); | 33 | alert('Password must be at least 8 characters'); |
| 34 | } else if ( | ||
| 35 | network.password.length < 5 && | ||
| 36 | network.encryptionMode === 'WEP' | ||
| 37 | ) { | ||
| 38 | alert('Password must be at least 5 characters'); | ||
| 33 | } else { | 39 | } else { |
| 34 | window.print(); | 40 | window.print(); |
| 35 | } | 41 | } |
| @@ -43,7 +49,7 @@ export const Card = () => { | |||
| 43 | 49 | ||
| 44 | const ssid = escape(network.ssid); | 50 | const ssid = escape(network.ssid); |
| 45 | const password = escape(network.password); | 51 | const password = escape(network.password); |
| 46 | setQrvalue(`WIFI:T:WPA;S:${ssid};P:${password};;`); | 52 | setQrvalue(`WIFI:T:${network.encryptionMode};S:${ssid};P:${password};;`); |
| 47 | }, [network]); | 53 | }, [network]); |
| 48 | 54 | ||
| 49 | return ( | 55 | return ( |
| @@ -79,17 +85,17 @@ export const Card = () => { | |||
| 79 | value={network.ssid} | 85 | value={network.ssid} |
| 80 | onChange={(e) => setNetwork({ ...network, ssid: e.target.value })} | 86 | onChange={(e) => setNetwork({ ...network, ssid: e.target.value })} |
| 81 | /> | 87 | /> |
| 82 | <label className={network.hidePassword ? 'hide-password' : ''}> | 88 | <label className={network.hidePassword ? 'no-print' : ''}> |
| 83 | Password | 89 | Password |
| 84 | </label> | 90 | </label> |
| 85 | <textarea | 91 | <textarea |
| 86 | id="password" | 92 | id="password" |
| 87 | type="text" | 93 | type="text" |
| 94 | className={network.hidePassword ? 'no-print' : ''} | ||
| 88 | style={{ | 95 | style={{ |
| 89 | height: | 96 | height: |
| 90 | portrait && network.password.length > 40 ? '5em' : 'auto', | 97 | portrait && network.password.length > 40 ? '5em' : 'auto', |
| 91 | }} | 98 | }} |
| 92 | className={network.hidePassword ? 'hide-password' : ''} | ||
| 93 | maxLength="63" | 99 | maxLength="63" |
| 94 | placeholder="Password" | 100 | placeholder="Password" |
| 95 | autoComplete="off" | 101 | autoComplete="off" |
| @@ -97,22 +103,61 @@ export const Card = () => { | |||
| 97 | autoCapitalize="none" | 103 | autoCapitalize="none" |
| 98 | spellCheck="false" | 104 | spellCheck="false" |
| 99 | value={network.password} | 105 | value={network.password} |
| 100 | onChange={(e) => | 106 | onChange={(e) => { |
| 101 | setNetwork({ ...network, password: e.target.value }) | 107 | setNetwork({ ...network, password: e.target.value }); |
| 102 | } | 108 | }} |
| 103 | /> | 109 | /> |
| 104 | 110 | ||
| 105 | <input | 111 | <div className="no-print"> |
| 106 | type="checkbox" | 112 | <input |
| 107 | id="hide-password-checkbox" | 113 | type="checkbox" |
| 108 | className="hide-password" | 114 | id="hide-password-checkbox" |
| 109 | onChange={() => | 115 | onChange={() => |
| 110 | setNetwork({ ...network, hidePassword: !network.hidePassword }) | 116 | setNetwork({ |
| 111 | } | 117 | ...network, |
| 112 | /> | 118 | hidePassword: !network.hidePassword, |
| 113 | <label for="hide-password-checkbox" className="hide-password"> | 119 | }) |
| 114 | Hide password field before printing | 120 | } |
| 115 | </label> | 121 | /> |
| 122 | <label for="hide-password-checkbox"> | ||
| 123 | Hide password field before printing | ||
| 124 | </label> | ||
| 125 | </div> | ||
| 126 | |||
| 127 | <div className="no-print"> | ||
| 128 | <label>Encryption:</label> | ||
| 129 | <input | ||
| 130 | type="radio" | ||
| 131 | name="encrypt-select" | ||
| 132 | id="encrypt-none" | ||
| 133 | value="nopass" | ||
| 134 | onChange={(e) => { | ||
| 135 | setNetwork({ ...network, encryptionMode: e.target.value }); | ||
| 136 | }} | ||
| 137 | /> | ||
| 138 | <label for="encrypt-none">None</label> | ||
| 139 | <input | ||
| 140 | type="radio" | ||
| 141 | name="encrypt-select" | ||
| 142 | id="encrypt-wpa-wpa2" | ||
| 143 | value="WPA" | ||
| 144 | onChange={(e) => | ||
| 145 | setNetwork({ ...network, encryptionMode: e.target.value }) | ||
| 146 | } | ||
| 147 | defaultChecked | ||
| 148 | /> | ||
| 149 | <label for="encrypt-wpa-wpa2">WPA/WPA2</label> | ||
| 150 | <input | ||
| 151 | type="radio" | ||
| 152 | name="encrypt-select" | ||
| 153 | id="encrypt-wep" | ||
| 154 | value="WEP" | ||
| 155 | onChange={(e) => | ||
| 156 | setNetwork({ ...network, encryptionMode: e.target.value }) | ||
| 157 | } | ||
| 158 | /> | ||
| 159 | <label for="encrypt-wep">WEP</label> | ||
| 160 | </div> | ||
| 116 | </div> | 161 | </div> |
| 117 | </div> | 162 | </div> |
| 118 | 163 | ||
diff --git a/src/components/style.css b/src/components/style.css index 6887d59..5ce3d34 100644 --- a/src/components/style.css +++ b/src/components/style.css | |||
| @@ -56,7 +56,7 @@ button#rotate { | |||
| 56 | #print-area textarea { | 56 | #print-area textarea { |
| 57 | border: none; | 57 | border: none; |
| 58 | } | 58 | } |
| 59 | .hide-password { | 59 | .no-print { |
| 60 | display: none; | 60 | display: none; |
| 61 | } | 61 | } |
| 62 | #print-area { | 62 | #print-area { |
