简体   繁体   English

当用户未登录时,如何让应用程序要求登录。在 KivyMD 中

[英]How to make the app ask for login when a user is not logged in. In KivyMD

I am making a Music App using Kivy rather KivyMD in Python.我正在使用 Kivy 而不是 Python 中的 KivyMD 制作音乐应用程序。 I want to make the app to ask for login when the app has been opened for first time in the mobile or opened after a logout.我想让应用程序在手机中首次打开或注销后打开时要求登录。 Please help me请帮我

I don't know Kivy, but if you have your login written in Python:我不知道 Kivy,但是如果您的登录名是用 Python 编写的:

Create a bool that is set to true whenever the user logs in and false when logged out and on default (for the first time opening the app).创建一个bool ,当用户登录时设置为true ,注销时设置为false ,默认情况下(第一次打开应用程序)。 Then, on startups, check the bool value with an if statement, and if the bool is false , prompt a login.然后,在启动时,使用if语句检查 bool 值,如果boolfalse ,则提示登录。 Something like this (bear in mind, I'm not the best with Python):像这样的东西(请记住,我不是 Python 最擅长的):

bool loggedIn = False;

def LogIn():
    #other login stuff
    loggedIn = True
          
def LogOut():
    #other login stuff
    loggedIn = True

def StartUpFunction():
    if loggedIn == False:
        LogIn()

I don't know how to do it in Kivy and on mobile, but for webpages you save a usertoken encrypted in the localstorage of your browser.我不知道如何在 Kivy 和移动设备上执行此操作,但是对于网页,您可以在浏览器的本地存储中保存加密的用户令牌。 I would use a file, where I add and delete this token and check the file (or Database) every time you start the app我会使用一个文件,在其中添加和删除此令牌,并在每次启动应用程序时检查文件(或数据库)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM