Skip to content

Commit

Permalink
add passwordless authentication featrue
Browse files Browse the repository at this point in the history
  • Loading branch information
vintikzzz committed Apr 3, 2024
1 parent 33b225b commit 8bb030c
Show file tree
Hide file tree
Showing 87 changed files with 7,089 additions and 4,838 deletions.
2 changes: 1 addition & 1 deletion .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tmp_dir = "tmp"

[build]
args_bin = ['s', '--assets-host', 'http://localhost:8082']
bin = "./tmp/main"
bin = ";SUPERTOKENS_DEBUG=1 GIN_MODE=debug ./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata", "node_modules"]
Expand Down
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/web-ui-v2.iml

This file was deleted.

1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM alpine:latest as certs
# getting certs
RUN apk update && apk upgrade && apk add --no-cache ca-certificates

FROM node:16 as build_assets
FROM node:20 as build_assets

WORKDIR /app

Expand Down Expand Up @@ -35,6 +35,9 @@ RUN go build -ldflags '-w -s' -a -installsuffix cgo -o server

FROM alpine:latest

# set work dir
WORKDIR /app

# copy our static linked library
COPY --from=build /app/server .
# copy templates
Expand All @@ -48,5 +51,7 @@ COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# tell we are exposing our service on ports 8080 8081
EXPOSE 8080 8081

ENV GIN_MODE=release

# run it!
CMD ["./server", "serve"]
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ Some features to mention:
- [x] OpenSubtitles support
- [ ] Subtitle uploading support
- [ ] Chromecast support
- [ ] Authentication with Patreon
- [ ] Subtitle size control
- [x] Authentication
- [x] Passwordless authentication
- [ ] Patreon account linking
- [ ] Ads integration
- [ ] Embed support
- [ ] 🚀Switch webtor.io to web-ui-v2

Expand Down
21 changes: 0 additions & 21 deletions assets/src/action.js

This file was deleted.

13 changes: 0 additions & 13 deletions assets/src/index.js

This file was deleted.

27 changes: 27 additions & 0 deletions assets/src/js/app/action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const target = document.currentScript.parentElement;
const av = (await import('../lib/asyncView')).initAsyncView;
av(target, 'action/post', async function() {
const self = this;
const progress = self.querySelector('form');
const el = document.createElement('div');
const closeable = target.querySelector('.closeable');
if (closeable) {
const initCloseable = (await import('../lib/closeable')).initCloseable;
initCloseable(closeable);
}
const initProgressLog = (await import('../lib/progressLog')).initProgressLog;
const pb = initProgressLog(progress, function(ev) {
if (ev.level == 'rendertemplate') {
window.addEventListener('player_ready', function(e) {
progress.classList.add('hidden');
el.classList.remove('hidden');
}, {once: true});
el.classList.add('hidden');
el.classList.add('mb-5')
self.appendChild(el);
ev.render(el);
}
});
});

export {}
24 changes: 24 additions & 0 deletions assets/src/js/app/action/player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import '../../../styles/player.css';
const target = document.currentScript.parentElement;
function ready() {
const event = new CustomEvent('player_ready');
window.dispatchEvent(event);
}


const av = (await import('../../lib/asyncView')).initAsyncView;
av(target, 'action/preview_image', () => {
ready();
});

for (const format of ['audio', 'video']) {
av(target, 'action/stream_'+format, async function() {
const initPlayer = (await import('../../lib/mediaelement')).initPlayer;
initPlayer(this, ready);
}, async function() {
const destroyPlayer = (await import('../../lib/mediaelement')).destroyPlayer;
destroyPlayer();
});
}

export {}
17 changes: 17 additions & 0 deletions assets/src/js/app/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {init} from '../lib/supertokens';
window.addEventListener('DOMContentLoaded', async () => {
try {
const res = await init();
} catch (err) {
console.log(err);
}
});
const av = (await import('../lib/asyncView')).initAsyncView;
av(document.querySelector('nav'), 'index', async function() {
const self = this;
window.addEventListener('auth', function() {
self.load();
}, { once: true });
});

export {}
32 changes: 32 additions & 0 deletions assets/src/js/app/auth/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
window.submitLoginForm = function(target, e) {
(async (data) => {
const initProgressLog = (await import('../../lib/progressLog')).initProgressLog;
const pl = initProgressLog(document.querySelector('.progress-alert'));
pl.clear();
pl.inProgress('sending magic link to ' + data.email, 'login');
const supertokens = (await import('../../lib/supertokens'));
const closeable = document.querySelector('.closeable');
if (closeable) {
const initCloseable = (await import('../../lib/closeable')).initCloseable;
initCloseable(closeable);
}
try {
const resp = await supertokens.sendMagicLink(data);
pl.done('login');
pl.finish('magic link sent to ' + data.email);
} catch (err) {
console.log(err);
if (err.statusText) {
pl.error(err.statusText.toLowerCase(), 'login');
} else if (err.message) {
pl.error(err.message.toLowerCase(), 'login');
} else {
pl.error('unknown error', 'login');
}
}
})({
email: target.querySelector('input[name=email]').value,
});
e.preventDefault();
return false;
}
26 changes: 26 additions & 0 deletions assets/src/js/app/auth/logout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const target = document.currentScript.parentElement;
const av = (await import('../../lib/asyncView')).initAsyncView;
av(target, 'auth/logout', async function() {
const initProgressLog = (await import('../../lib/progressLog')).initProgressLog;
const pl = initProgressLog(target.querySelector('.progress-alert'));
pl.clear();
pl.inProgress('logging out', 'logout' );
const supertokens = (await import('../../lib/supertokens'));
try {
await supertokens.logout();
pl.done('logout');
pl.finish('logout successful');
window.dispatchEvent(new CustomEvent('auth'));
} catch (err) {
console.log(err);
if (err.statusText) {
pl.error(err.statusText.toLowerCase(), 'logout');
} else if (err.message) {
pl.error(err.message.toLowerCase(), 'logout');
} else {
pl.error('unknown error', 'logout');
}
}
});

export {}
31 changes: 31 additions & 0 deletions assets/src/js/app/auth/verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const target = document.currentScript.parentElement;
const av = (await import('../../lib/asyncView')).initAsyncView;
av(target, 'auth/verify', async function() {
const initProgressLog = (await import('../../lib/progressLog')).initProgressLog;
const pl = initProgressLog(target.querySelector('.progress-alert'));
pl.clear();
pl.inProgress('checking magic link', 'verify');
const supertokens = (await import('../../lib/supertokens'));
try {
const res = await supertokens.handleMagicLinkClicked();
if (res.status === 'OK') {
pl.done('verify');
pl.finish('login successful');
window.dispatchEvent(new CustomEvent('auth'));
} else if (res.status === 'RESTART_FLOW_ERROR') {
pl.error('magic link expired, try to login again', 'verify');
} else {
pl.error('login failed, try to login again', 'verify');
}
} catch (err) {
if (err.statusText) {
pl.error(err.statusText.toLowerCase(), 'verify');
} else if (err.message) {
pl.error(err.message.toLowerCase(), 'verify');
} else {
pl.error('unknown error', 'verify');
}
}
});

export {}
22 changes: 22 additions & 0 deletions assets/src/js/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const target = document.currentScript.parentElement;
const av = (await import('../lib/asyncView')).initAsyncView;
av(target, 'index', async function() {
const dropzone = target.querySelector('.dropzone');
if (dropzone) {
const initDrop = (await import('../lib/drop')).initDrop;
initDrop(dropzone);
}

const closeable = target.querySelector('.closeable');
if (closeable) {
const initCloseable = (await import('../lib/closeable')).initCloseable;
initCloseable(closeable);
}
const progress = this.querySelector('.progress-alert');
if (progress != null) {
const initProgressLog = (await import('../lib/progressLog')).initProgressLog;
initProgressLog(progress);
}
});

export {}
56 changes: 56 additions & 0 deletions assets/src/js/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function showProgress() {
const progress = document.getElementById('progress');
progress.classList.remove('hidden');
}
function hideProgress() {
const progress = document.getElementById('progress');
progress.classList.add('hidden');
}

function hideWrapper() {
var w = document.getElementById('wrapper');
w.classList.add('hidden');
}
function showWrapper() {
var w = document.getElementById('wrapper');
if (w != null) {
w.classList.remove('hidden');
}
}

window.progress = {
show: showProgress,
hide: hideProgress,
};
window.wrapper = {
show: showWrapper,
hide: hideWrapper,
};
window.finish = function() {
hideWrapper();
};

import '../../styles/style.css';


import {bindAsync} from '../lib/async';

window.addEventListener('DOMContentLoaded', async () => {
showWrapper();
hideProgress();
bindAsync({
async fetch(f, url, fetchParams) {
showProgress();
fetchParams.headers['X-CSRF-TOKEN'] = window._CSRF;
const res = await fetch(url, fetchParams);
hideProgress();
return res;
},
fallback: {
selector: 'main',
layout: 'async',
},
});
});


Empty file.
File renamed without changes.
Loading

0 comments on commit 8bb030c

Please sign in to comment.