mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-06-17 18:13:21 +02:00
Login page of "subscribe dialog", still WIP, but looking nice
This commit is contained in:
parent
1599793de2
commit
6d343c0f1a
8 changed files with 366 additions and 11 deletions
web/src/app
|
@ -4,11 +4,11 @@ import Subscriptions from "./Subscriptions";
|
|||
export class Repository {
|
||||
loadSubscriptions() {
|
||||
console.log(`[Repository] Loading subscriptions from localStorage`);
|
||||
|
||||
const subscriptions = new Subscriptions();
|
||||
const serialized = localStorage.getItem('subscriptions');
|
||||
if (serialized === null) return subscriptions;
|
||||
|
||||
if (serialized === null) {
|
||||
return subscriptions;
|
||||
}
|
||||
try {
|
||||
const serializedSubscriptions = JSON.parse(serialized);
|
||||
serializedSubscriptions.forEach(s => {
|
||||
|
@ -26,7 +26,6 @@ export class Repository {
|
|||
|
||||
saveSubscriptions(subscriptions) {
|
||||
console.log(`[Repository] Saving ${subscriptions.size()} subscription(s) to localStorage`);
|
||||
|
||||
const serialized = JSON.stringify(subscriptions.map( (id, subscription) => {
|
||||
return {
|
||||
baseUrl: subscription.baseUrl,
|
||||
|
@ -37,6 +36,30 @@ export class Repository {
|
|||
}));
|
||||
localStorage.setItem('subscriptions', serialized);
|
||||
}
|
||||
|
||||
loadUsers() {
|
||||
console.log(`[Repository] Loading users from localStorage`);
|
||||
const serialized = localStorage.getItem('users');
|
||||
if (serialized === null) {
|
||||
return {};
|
||||
}
|
||||
try {
|
||||
return JSON.parse(serialized);
|
||||
} catch (e) {
|
||||
console.log(`[Repository] Unable to deserialize users: ${e.message}`);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
saveUser(baseUrl, username, password) {
|
||||
console.log(`[Repository] Saving users to localStorage`);
|
||||
const users = this.loadUsers();
|
||||
users[baseUrl] = {
|
||||
username: username,
|
||||
password: password
|
||||
};
|
||||
localStorage.setItem('users', users);
|
||||
}
|
||||
}
|
||||
|
||||
const repository = new Repository();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue