Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NyaomiDEV committed Aug 13, 2024
1 parent 0ffe8b0 commit 5d21a47
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/lib/applock.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import router from "../router";
import { securityConfig } from "./config";
import sha1 from "./util/sha1";

let isLocked = true;
let isLocked = false;
if (securityConfig.password)
isLocked = true;

export function getLockedStatus(){
if (securityConfig.password === undefined || !securityConfig.usePassword) return false;
Expand All @@ -14,7 +15,6 @@ export function unlock(plaintextPwd: string) {

if(securityConfig.password === password) {
isLocked = false;
router.replace("/");
return true;
}

Expand Down
11 changes: 11 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { tryPersistStorage } from "./lib/util/storageManager";
import { getSystem, newSystem } from "./lib/db/entities/system";
import { appConfig } from "./lib/config";
import { getLockedStatus } from "./lib/applock";
import { RouteLocationNormalizedGeneric } from "vue-router";

if(!window.isSecureContext){
console.error("Cannot continue, this is not a safe environment!");
Expand All @@ -74,15 +75,25 @@ if(!window.isSecureContext){

const app = createApp(App).use(IonicVue).use(router).use(I18NextVue, { i18next: i18n });

let wantedRoute: RouteLocationNormalizedGeneric | undefined;
router.beforeEach((to) => {
if(getLockedStatus()) {
if(to.path === "/lock")
return true;

wantedRoute = to;

return { path: "/lock" };
}

if (to.fullPath === "/" || to.path === "/lock") {

if(wantedRoute){
const _r = wantedRoute;
wantedRoute = undefined;
return _r;
}

// route to default view
switch (appConfig.view) {
case "members":
Expand Down
7 changes: 5 additions & 2 deletions src/views/LockView.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<script setup lang="ts">
import { IonPage, IonContent, IonLabel, IonInput } from "@ionic/vue";
import { IonPage, IonContent, IonLabel, IonInput, useIonRouter } from "@ionic/vue";
import { unlock } from "../lib/applock";
const router = useIonRouter();
function checkAndTryUnlocking(e){
console.log(unlock(e.detail.value));
if(unlock(e.detail.value))
router.replace("/");
}
</script>

Expand Down

0 comments on commit 5d21a47

Please sign in to comment.