Skip to content

Commit

Permalink
Merge pull request #26 from retog/deploy
Browse files Browse the repository at this point in the history
Allow token/ip in Link
  • Loading branch information
JakobJFL authored Jan 4, 2024
2 parents f75e03b + c25b18f commit 5e1476c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ <h4 class="pt-4">Why do i have to do this?</h4>
</div>
</div>
<script src="bootstrap-5.0.0-dist/js/bootstrap.js"></script>
<script src="js/qrcode.min.js"></script>
<script src="js/api.js"></script>
<script src="js/actions.js"></script>
<script src="libraries/rgb-color-converter/ColorConverter.js"></script>
Expand Down
6 changes: 6 additions & 0 deletions js/dashboardSite.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class DashboardPage {
if (settingsObj.effects) effects = "checked";
if (settingsObj.showUnreachable) showUnreachableC = "checked";

const connectedLink = `${document.location.protocol}//${document.location.host}${document.location.pathname}?token=${acc.token}&ip=${acc.ip}`;

let header = `<div class="container pt-4">
<header class="pb-3 mb-4">
<div class="top-bar">
Expand Down Expand Up @@ -90,6 +92,10 @@ class DashboardPage {
<tbody>
<tr><th class="text-muted" scope="row">IP Address:</th><td>${acc.ip}</td></tr>
<tr><th class="text-muted" scope="row">Access token:</th><td>${acc.token}</td> </tr>
<tr><th class="text-muted" scope="row">Connected Link:</th><td><a style="color: #474747 !important;" href="${connectedLink}">${connectedLink}</a></td> <br>
</tr>
<tr><th class="text-muted" scope="row">Connected QR:</th><td id="qrcode" title="${connectedLink}"></td>
</tr>
</tbody>
</table>
<h3 class="fs-5 text-muted" >Remove saved details</h3>
Expand Down
19 changes: 18 additions & 1 deletion js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,22 @@ document.getElementById("manuallyIpBtn").addEventListener("click", manuallyIpNew
let interval;
const refreshTime = 1500;
const postJsonObj = {devicetype: "Hue-Browser-Controller"};
checkLocalStorage();
checkQueryArgs().then(checkLocalStorage);

function checkQueryArgs() {
const params = new URLSearchParams(window.location.search);
const token = params.get("token")
const ip = params.get("ip")
if (token && ip) {
const acc = {token,ip};
return connectionGood(acc).then(() => {
localStorage.setItem('hueAcc', JSON.stringify(acc));
window.history.replaceState({}, document.title, window.location.origin+window.location.pathname);
})
} else {
return Promise.resolve();
}
}

function checkLocalStorage() {
let acc;
Expand Down Expand Up @@ -169,6 +184,8 @@ function setDashboard() {
let acc = getAccess();
getDashboard(acc).then(dashboard => {
document.getElementById("mainSite").innerHTML = dashboard.getHtml(acc);
const qrcodeElt = document.getElementById("qrcode");
new QRCode(qrcodeElt, qrcodeElt.title);
let storage = localStorage.getItem('siteSettings');
if (storage)
changeTheme(JSON.parse(storage).theme);
Expand Down
Loading

0 comments on commit 5e1476c

Please sign in to comment.