Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
akurilov committed Nov 26, 2023
1 parent 4059e3d commit 52987fd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
4 changes: 2 additions & 2 deletions web/inbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const templateInboxNav = subId => `
<button title="Toggle Notification Sound" onclick="Events.toggleAudio()" class="h-8 w-8 rounded-md border border-indigo-700 shadow-2xl hover:bg-indigo-200 text-indigo-700 items-center">
<img id="img_toggle_audio" src=${Events.audioEnabled ? "notifications-on.svg" : "notifications-off.svg"} alt="Toggle Notification Sound" class="px-1"/>
</button>
<button title="Edit Subscription" onclick="window.location.assign('//sub-edit.html?id=${subId}')" class="h-8 w-8 rounded-md border border-blue-700 shadow-2xl hover:bg-blue-200 text-blue-700 items-center">
<button title="Edit Subscription" onclick="window.location.assign('sub-edit.html?id=${subId}')" class="h-8 w-8 rounded-md border border-blue-700 shadow-2xl hover:bg-blue-200 text-blue-700 items-center">
<img src="sub-edit.svg" alt="Edit Subscription" class="px-1"/>
</button>
<button title="New Message" onclick="window.location.assign('//msg-new.html')" class="h-8 w-8 rounded-md border border-cyan-700 shadow-2xl hover:bg-cyan-200 text-cyan-700 items-center">
<button title="New Message" onclick="window.location.assign('msg-new.html')" class="h-8 w-8 rounded-md border border-cyan-700 shadow-2xl hover:bg-cyan-200 text-cyan-700 items-center">
<img src="msg-new.svg" alt="New Message" class="px-1" style="padding-top: 0.25rem"/>
</button>
<button type="button" title="Exit" onclick="logout()" class="h-8 w-8 text-sm focus:outline-none text-gray-500 rounded-md border border-gray-500 hover:bg-gray-200 flex items-center">
Expand Down
7 changes: 1 addition & 6 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,11 @@
src="https://telegram.org/js/telegram-widget.js?22"
data-telegram-login="AwakariBot"
data-size="large"
data-onauth="onTelegramAuth(user)"
data-onauth="handleAuthTelegram(creds)"
data-request-access="write"
data-radius="4"
data-userpic="false">
</script>
<script type="text/javascript">
function onTelegramAuth(user) {
alert('Logged in as ' + JSON.stringify(user));
}
</script>

</div>

Expand Down
24 changes: 17 additions & 7 deletions web/login.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
const defaultGroupId = "default"

function handleAuthGoogle(response) {
const credential = response.credential;
const tokenEncoded = response.credential;
// Decode the JWT token
const decodedToken = jwt_decode(credential);
const tokenDecoded = jwt_decode(tokenEncoded);
// Extract the user email from the decoded token
const userEmail = decodedToken.email;
sessionStorage.setItem("userEmail", userEmail)
const userEmail = tokenDecoded.email;
sessionStorage.setItem("userId", `${tokenDecoded.iss}/${tokenDecoded.sub}`);
sessionStorage.setItem("authToken", tokenEncoded);
// go to subscriptions list
window.location.assign("subs.html")
window.location.assign("subs.html");
}

function handleAuthTelegram(creds) {
sessionStorage.setItem("userId", `tg://user?id=${creds.id}`);
const token = btoa(JSON.stringify(creds));
sessionStorage.setItem("authToken", token);
}

function logout() {
if (confirm("Confirm exit?")) {
sessionStorage.removeItem("userEmail")
window.location.assign("index.html")
sessionStorage.removeItem("userEmail");
sessionStorage.removeItem("userId");
window.location.assign("index.html");
}
}
4 changes: 2 additions & 2 deletions web/subs.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
<button title="Toggle Notification Sound" onclick="Events.toggleAudio()" class="h-8 w-8 rounded-md border border-indigo-700 shadow-2xl hover:bg-indigo-200 text-indigo-700 items-center">
<img id="img_toggle_audio" src="notifications-off.svg" alt="Toggle Notification Sound" class="px-1"/>
</button>
<button title="New Subscription" onclick="window.location.assign('//sub-new.html')" class="h-8 w-8 rounded-md border border-blue-700 shadow-2xl hover:bg-blue-200 text-blue-700 items-center">
<button title="New Subscription" onclick="window.location.assign('sub-new.html')" class="h-8 w-8 rounded-md border border-blue-700 shadow-2xl hover:bg-blue-200 text-blue-700 items-center">
<img src="sub-new.svg" alt="New Subscription" class="px-1"/>
</button>
<button title="New Message" onclick="window.location.assign('//msg-new.html')" class="h-8 w-8 rounded-md border border-cyan-700 shadow-2xl hover:bg-cyan-200 text-cyan-700 items-center">
<button title="New Message" onclick="window.location.assign('msg-new.html')" class="h-8 w-8 rounded-md border border-cyan-700 shadow-2xl hover:bg-cyan-200 text-cyan-700 items-center">
<img src="msg-new.svg" alt="New Message" class="px-1" style="padding-top: 0.25rem"/>
</button>
<button type="button" title="Exit" onclick="logout()" class="h-8 w-8 text-sm focus:outline-none text-gray-500 rounded-md border border-gray-500 hover:bg-gray-200 flex items-center">
Expand Down
7 changes: 5 additions & 2 deletions web/subs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ const templateSub = (sub) => `
let eventsLoadingRunning = false;

function loadSubscriptions() {
let userEmail = sessionStorage.getItem("userEmail")
let authToken = sessionStorage.getItem("authToken");
let userId = sessionStorage.getItem("userId");
let optsReq = {
method: "GET",
headers: {
"X-Awakari-User-Id": userEmail,
"Authorization": `Bearer: ${authToken}`,
"X-Awakari-Group-Id": defaultGroupId,
"X-Awakari-User-Id": userId,
},
cache: "default",
}
Expand Down

0 comments on commit 52987fd

Please sign in to comment.