简体   繁体   English

我可以使用 pin 码保护 PWA 中的特定页面吗?

[英]Can I protect certain page in PWA with a pin code?

I'm building a PWA for a restaurant and I need to protect certain pages with a pincode or password.我正在为一家餐厅构建 PWA,我需要使用 pin 码或密码来保护某些页面。 Platform: Safari, iPads.平台:Safari,iPad。

The app itself has only 2 views:该应用程序本身只有 2 个视图:

  • show all tables显示所有表
  • show the bill of a specific table显示特定表的账单

When a waiter clicks a table it will show a bill that then will be handed over to the client.当服务员点击一张桌子时,它会显示一张账单,然后将账单交给客户。 How can I restrict a client from going back to the main screen with all tables with a pin code or a password that will be set at the beginning of the work session, for example (when the waiter authenticates)?例如,如何限制客户返回主屏幕,其中所有表格都带有 pin 码或将在工作开始时设置的密码 session(当服务员进行身份验证时)?

You can use a router middleware to prevent the client to navigate elsewhere.您可以使用路由器中间件来防止客户端导航到其他地方。

router.beforeEach(function(to, from, next) {
    if (isLocked) {
        alert('Navigation is locked');
        next(false);
    } else {
        next();
    }
});

Here is an example where the waiter can lock the page after selecting the bill.这是一个例子,服务员可以在选择账单后锁定页面。 Although it can be automatically set in mounted.虽然在mounted中可以自动设置。 You can adjust the code to your own needs.您可以根据自己的需要调整代码。

Jsfiddle小提琴

You can use session storage in JavaScript to store the password and check it whenever a client tries to access the main screen.您可以使用 JavaScript 中的 session 存储来存储密码,并在客户端尝试访问主屏幕时检查它。 Here's the code:这是代码:

// setting the password
sessionStorage.setItem('password', '1234');

// checking the password
const password = sessionStorage.getItem('password');
if (inputPassword !== password) {
alert('Incorrect password');
return;
}

// redirecting to the main screen
window.location.href = '/main-screen';

This code sets a password of '1234' and checks it every time a client tries to access the main screen.此代码设置密码“1234”,并在每次客户端尝试访问主屏幕时检查它。 If the input password is incorrect, an alert will be shown and the client will not be able to access the main screen.如果输入的密码不正确,将显示警报并且客户端将无法访问主屏幕。 If the password is correct, the client will be redirected to the main screen.如果密码正确,客户端将被重定向到主屏幕。

You can add this code in the event handler of the table click or the password input form.您可以将此代码添加到表格点击或密码输入表单的事件处理程序中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何保护单页应用程序免受CSRF的侵害 - How can I protect my Single Page Application against CSRF VueJS PWA在我的小型PWA中说“网络错误”。 即使我无法登录 - VueJS PWA says Network Error in my small PWA. Even I can't login 如何强制用户使用PWA的最新版本? - How can I force users on to the latest version of a PWA? 我可以在不缓存任何资产的情况下拥有 PWA 吗? - Can I have a PWA without caching any assets? vue PWA 如何使用precache? 我仍然收到“页面无法离线工作” - How does vue PWA use the precache? I still get "Page does not work offline" 使用 Vuetify PWA 模板时如何更改 Android 状态栏颜色 - How can i change the Android Status Bar Color when using Vuetify PWA Template 如何在 PWA 模式下移除 Nuxt 加载页面 - How to remove the Nuxt loading page in PWA mode Vue组件是rendring但页面是空白的。我可以通过检查页面来查看代码 - Vue component is rendring but page is blank.I can see the code by inspectinng the page 我想在我的登录页面添加一个忘记密码的页面,但我更新代码后无法跳转 - I want to add a forgotten password page to my login page, but I can't jump to it after I update the code 我如何使用keycloak来保护我的vue.js页面和spring引导rest api? - How can I use keycloak to protect my vue js pages and spring boot rest api?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM