コード例 #1
0
class SharedWithMeFilesOptionsDialog(tk.Toplevel):
    def __init__(self, master: tk.Frame, masterParent: tk.Tk,
                 fileDetails: tuple):
        super().__init__(master)
        self.root = master
        self.fileDetails = fileDetails
        self.masterParent = masterParent

        self.dqueue = Queue()
        self.downloadResponse = None

        self.title(fileDetails[1])
        self.resizable(False, False)
        self.grab_set()
        self.overrideredirect(True)
        centerWindow(self, 300, 100)

        tk.Label(self, text="Download").pack(expand=True)
        tk.Button(self, text="Download",
                  command=self.downloadFile).pack(expand=True)
        tk.Button(self, text="Cancel", command=self.remove).pack(expand=True)

    def remove(self):
        self.grab_release()
        self.withdraw()

    def signOut(self):
        print("signout called")
        result = RemoveUserLoginInfo().remove()
        if result:
            self.root.destroy()
            loginScreen.LoginScreen(self.masterParent)
        else:
            GenericDialog(
                self.root,
                title="Database Error!",
                message="Unable to remove login info!\nProgram will exit now.")

    def downloadFile(self):
        print("Download")
        self.dqueue = Queue()
        self.remove()
        self.waitDialog = StickyDialog(self,
                                       message="Downloading! Please wait...")
        userFileDownloadThread = DownloadFile(queue=self.dqueue,
                                              owner=self.fileDetails[0],
                                              name=self.fileDetails[1])
        userFileDownloadThread.start()
        self.checkDownloadQueue()

    def checkDownloadQueue(self):
        if not self.dqueue.empty():
            self.downloadResponse = self.dqueue.get()
            self.waitDialog.remove()
            print(self.downloadResponse)
            self.afterDownloadResponse()
        else:
            self.root.after(100, self.checkDownloadQueue)

    def afterDownloadResponse(self):
        if self.downloadResponse == StatusCode.OK:
            GenericDialog(self.root,
                          title="Success!",
                          message="File saved to Desktop")
        elif self.downloadResponse == StatusCode.INTERNAL:
            GenericDialog(self.root,
                          title="Error!",
                          message="Internal server error!")
        else:
            GenericDialog(self.root,
                          title="Error!",
                          message="Some other error occurred!")
コード例 #2
0
class SignUpScreen:
    def __init__(self, master: tk.Tk):
        self.root = master
        self.root.title("Sign Up")
        centerWindow(self.root, 800, 600)
        self.root.config(menu=tk.Menu(self.root))

        self.username = tk.StringVar()
        self.email = tk.StringVar()
        self.password = tk.StringVar()
        self.confirmPassword = tk.StringVar()

        self.queue = Queue()
        self.signUpResponse = None
        self.waitDialog = None

        self.initSignUpScreen()

    def initSignUpScreen(self):
        self.frame = tk.Frame(self.root)
        self.frame.pack(expand=True, anchor=tk.CENTER)

        self.logo = getLogo()
        self.logoLabel = tk.Label(self.frame, image=self.logo)
        self.logoLabel.image = self.logo
        self.logoLabel.pack(expand=True, padx=30, pady=30)

        tk.Label(self.frame, text="Create a new account!").pack(expand=True,
                                                                padx=5,
                                                                pady=5)

        self.nameFrame = tk.Frame(self.frame)
        self.nameFrame.pack(side=tk.TOP)
        tk.Label(self.nameFrame, text="Name", padx=38).pack(side=tk.LEFT,
                                                            expand=True)
        tk.Entry(self.nameFrame,
                 textvariable=self.username).pack(side=tk.RIGHT,
                                                  fill=tk.X,
                                                  expand=True)

        self.emailFrame = tk.Frame(self.frame)
        self.emailFrame.pack(side=tk.TOP)
        tk.Label(self.emailFrame, text="Email", padx=40).pack(side=tk.LEFT,
                                                              expand=True)
        tk.Entry(self.emailFrame, textvariable=self.email).pack(side=tk.RIGHT,
                                                                fill=tk.X,
                                                                expand=True)

        self.passwordFrame = tk.Frame(self.frame)
        self.passwordFrame.pack(side=tk.TOP)
        tk.Label(self.passwordFrame, text="Password",
                 padx=26).pack(side=tk.LEFT, expand=True)
        tk.Entry(self.passwordFrame, textvariable=self.password,
                 show="*").pack(side=tk.RIGHT, fill=tk.X, expand=True)

        self.confirmPasswordFrame = tk.Frame(self.frame)
        self.confirmPasswordFrame.pack(side=tk.TOP)
        tk.Label(self.confirmPasswordFrame,
                 text="Confirm Password").pack(side=tk.LEFT, expand=True)
        tk.Entry(self.confirmPasswordFrame,
                 textvariable=self.confirmPassword,
                 show="*").pack(side=tk.RIGHT, fill=tk.X, expand=True)

        tk.Button(self.frame, text="Sign Up",
                  command=self.signUpInitiator).pack(expand=True,
                                                     padx=15,
                                                     pady=15,
                                                     ipadx=15)

        tk.Label(self.frame,
                 text="Already have an account?").pack(expand=True,
                                                       side=tk.TOP,
                                                       padx=20,
                                                       pady=(35, 10))
        tk.Button(self.frame, text="Login Now",
                  command=self.launchLoginScreen).pack(expand=True,
                                                       side=tk.TOP,
                                                       ipadx=15)

    def launchLoginScreen(self):
        self.frame.destroy()
        loginscreen.LoginScreen(self.root)

    def signUpInitiator(self):
        name = self.username.get()
        email = self.email.get()
        password = self.password.get()
        confPassword = self.confirmPassword.get()

        if name == "" or not validateUsername(name) or len(name) > 32:
            GenericDialog(
                self.root,
                title="Validation Error",
                message=
                "Invalid name!\nContains only alphabets.\nMax length: 32.")
        elif not validateEmail(email):
            GenericDialog(self.root,
                          title="Validation Error",
                          message="Invalid Email Address!")
        elif password != confPassword:
            GenericDialog(self.root,
                          title="Validation Error",
                          message="Passwords do not match!")
        elif password == confPassword and len(password) < 8:
            GenericDialog(self.root,
                          title="Validation Error",
                          message="Password minimum length: 8")
        elif password == confPassword and len(password) > 64:
            GenericDialog(self.root,
                          title="Validation Error",
                          message="Password maximum length: 64")
        else:
            # initiate sign up
            self.waitDialog = StickyDialog(self.root, message="Please wait!")
            userSignUpThread = UserSignUp(queue=self.queue,
                                          username=name,
                                          email=email,
                                          password=password)
            userSignUpThread.start()
            self.root.after(100, self.checkQueue)

    def checkQueue(self):
        if not self.queue.empty():
            self.signUpResponse = self.queue.get()
            self.waitDialog.remove()
            self.afterSignUpResponse()
        else:
            self.root.after(100, self.checkQueue)

    def afterSignUpResponse(self):
        if self.signUpResponse == StatusCode.OK:
            GenericDialog(self.root,
                          title="Success",
                          message="User account created.\nYou can now login!")
        elif self.signUpResponse == StatusCode.ALREADY_EXISTS:
            GenericDialog(
                self.root,
                title="Account Error",
                message="User account already exists.\nPlease login!")
        elif self.signUpResponse == StatusCode.INTERNAL:
            GenericDialog(self.root,
                          title="Error",
                          message="Internal Server Error!")
        elif self.signUpResponse == StatusCode.UNAVAILABLE:
            GenericDialog(self.root,
                          title="Error",
                          message="Could not connect to server!")
        else:
            GenericDialog(self.root,
                          title="Unknown Error",
                          message="Error Code: " + self.signUpResponse + "!")
コード例 #3
0
class LoginScreen:
    def __init__(self, master: tk.Tk):
        # TODO check if user is already logged-in here
        if CheckDbLoginStatus().check():
            user = GetUser().get()
            if user != None:
                HomeScreen(master=master, user=user)
        else:
            self.root = master
            self.root.title("Login")
            centerWindow(self.root, 800, 600)
            self.root.config(menu=tk.Menu(self.root))

            self.email = tk.StringVar()
            self.password = tk.StringVar()
            self.queue = Queue()

            self.loginResponse = None
            self.dbWriteResponse = None
            self.emailStr = ""
            self.passwordStr = ""

            self.waitDialog = None

            self.initLoginScreen()

    def initLoginScreen(self):
        self.frame = tk.Frame(self.root)
        self.frame.pack(expand=True, anchor=tk.CENTER)

        self.logo = getLogo()
        self.logoLabel = tk.Label(self.frame, image=self.logo)
        self.logoLabel.image = self.logo
        self.logoLabel.pack(expand=True, padx=30, pady=30)

        tk.Label(self.frame,
                 text="Please Login to continue!").pack(expand=True,
                                                        padx=15,
                                                        pady=15)

        self.emailFrame = tk.Frame(self.frame)
        self.emailFrame.pack(side=tk.TOP)
        tk.Label(master=self.emailFrame, text="Email",
                 padx=15).pack(side=tk.LEFT, expand=True)
        tk.Entry(self.emailFrame, textvariable=self.email).pack(side=tk.RIGHT,
                                                                fill=tk.X,
                                                                expand=True)

        self.passwordFrame = tk.Frame(self.frame)
        self.passwordFrame.pack(side=tk.TOP)
        tk.Label(self.passwordFrame, text="Password").pack(side=tk.LEFT)
        tk.Entry(self.passwordFrame, textvariable=self.password,
                 show="*").pack(side=tk.RIGHT, fill=tk.X, expand=True)

        tk.Button(self.frame, text="Login",
                  command=self.loginInitiator).pack(expand=True,
                                                    padx=15,
                                                    pady=15,
                                                    ipadx=15)

        tk.Label(self.frame, text="Don't have an account?").pack(expand=True,
                                                                 side=tk.TOP,
                                                                 padx=20,
                                                                 pady=(35, 10))
        tk.Button(self.frame,
                  text="Create a new account",
                  command=self.launchSignUpScreen).pack(expand=True,
                                                        side=tk.TOP,
                                                        ipadx=15)

    def launchSignUpScreen(self):
        self.frame.destroy()
        SignUpScreen(self.root)

    def loginInitiator(self):
        self.emailStr = self.email.get()
        self.passwordStr = self.password.get()
        if not validateEmail(self.emailStr):
            GenericDialog(self.root,
                          title="Validation Error",
                          message="Invalid Email Address!")
        elif self.passwordStr == "" or len(self.passwordStr) < 8:
            GenericDialog(self.root,
                          title="Validation Error",
                          message="Password must be 8 characters long!")
        else:
            self.waitDialog = StickyDialog(self.root, message="Please wait!")
            userLoginThread = UserLogin(self.queue,
                                        email=self.emailStr,
                                        password=self.passwordStr)
            userLoginThread.start()
            self.root.after(100, self.checkQueueForLogin)

    def checkQueueForLogin(self):
        if not self.queue.empty():
            self.loginResponse = self.queue.get()
            self.waitDialog.remove()
            self.afterLoginResponse()
        else:
            self.root.after(100, self.checkQueueForLogin)

    def afterLoginResponse(self):
        if isinstance(self.loginResponse, ussPb.LoginResponse):
            # print(self.loginResponse)
            self.saveUserInfoInitiator()
        elif self.loginResponse == StatusCode.INTERNAL:
            GenericDialog(self.root,
                          title="Server Error",
                          message="Internal server error!")
        elif self.loginResponse == StatusCode.NOT_FOUND:
            GenericDialog(self.root, title="Error", message="User not found!")
        elif self.loginResponse == StatusCode.FAILED_PRECONDITION:
            GenericDialog(self.root,
                          title="Validation Error",
                          message="Wrong password!")
        elif self.loginResponse == StatusCode.UNAVAILABLE:
            GenericDialog(self.root,
                          title="Internal Error",
                          message="Server not available!")
        else:
            GenericDialog(self.root,
                          title="Unknown Error",
                          message="Some other error occurred!")

    def saveUserInfoInitiator(self):
        self.waitDialog = StickyDialog(self.root,
                                       message="Initializing...\nPlease wait!")
        self.user = User(userId=self.loginResponse.uid,
                         name=self.loginResponse.name,
                         email=self.emailStr)
        self.queue = Queue()
        saveUserInfoThread = SaveUserLoginInfo(
            self.queue,
            user=self.user,
            accJwt=self.loginResponse.accessToken,
            refJwt=self.loginResponse.refreshToken)
        saveUserInfoThread.start()
        self.root.after(100, self.checkQueueForDb)

    def checkQueueForDb(self):
        if not self.queue.empty():
            self.dbWriteResponse = self.queue.get()
            self.waitDialog.remove()
            self.afterDbResponse()
        else:
            self.root.after(100, self.checkQueueForDb)

    def afterDbResponse(self):
        if self.dbWriteResponse:
            self.frame.destroy()
            HomeScreen(self.root, user=self.user)
        else:
            GenericDialog(
                self.root,
                title="Database Error!",
                message="Unable to save login info!\nProgram will exit now.")
            self.root.quit()
コード例 #4
0
class MyFilesOptionsDialog(tk.Toplevel):
    def __init__(self, master: tk.Frame, masterParent: tk.Tk,
                 fileDetails: tuple):
        super().__init__(master)
        self.root = master
        self.fileDetails = fileDetails
        self.masterParent = masterParent

        self.queue = Queue()
        self.aclUpdateResponse = None

        self.emailEntry = tk.StringVar()

        self.title(fileDetails[1])
        self.resizable(False, False)
        self.grab_set()
        self.overrideredirect(True)
        centerWindow(self, 300, 300)

        tk.Label(self, text="Download").pack(expand=True)
        tk.Button(self, text="Download",
                  command=self.downloadFile).pack(expand=True)

        tk.Label(self, text="Sharing").pack(expand=True)
        entry = tk.Entry(self, textvariable=self.emailEntry)
        entry.pack(expand=True)
        tk.Button(self, text="Cancel", command=self.remove).pack(expand=True,
                                                                 side=tk.LEFT)
        tk.Button(self, text="Revoke",
                  command=self.revokeAccess).pack(expand=True, side=tk.LEFT)
        tk.Button(self, text="Grant",
                  command=self.grantAccess).pack(expand=True, side=tk.LEFT)

    def remove(self):
        self.grab_release()
        self.withdraw()

    def signOut(self):
        print("signout called")
        result = RemoveUserLoginInfo().remove()
        if result:
            self.root.destroy()
            loginScreen.LoginScreen(self.masterParent)
        else:
            GenericDialog(
                self.root,
                title="Database Error!",
                message="Unable to remove login info!\nProgram will exit now.")

    def downloadFile(self):
        print("Download")
        self.dqueue = Queue()
        self.remove()
        self.waitDialog = StickyDialog(self,
                                       message="Downloading! Please wait...")
        userFileDownloadThread = DownloadFile(queue=self.dqueue,
                                              owner=self.fileDetails[0],
                                              name=self.fileDetails[1])
        userFileDownloadThread.start()
        self.checkDownloadQueue()

    def checkDownloadQueue(self):
        if not self.dqueue.empty():
            self.downloadResponse = self.dqueue.get()
            self.waitDialog.remove()
            print(self.downloadResponse)
            self.afterDownloadResponse()
        else:
            self.root.after(100, self.checkDownloadQueue)

    def afterDownloadResponse(self):
        if self.downloadResponse == StatusCode.OK:
            GenericDialog(self.root,
                          title="Success!",
                          message="File saved to Desktop")
        elif self.downloadResponse == StatusCode.INTERNAL:
            GenericDialog(self.root,
                          title="Error!",
                          message="Internal server error!")
        elif self.downloadResponse == StatusCode.UNAUTHENTICATED:
            GenericDialog(self.root,
                          title="Error!",
                          message="Internal server error!")
        else:
            GenericDialog(self.root,
                          title="Error!",
                          message="Some other error occurred!")

    def revokeAccess(self):
        print("revoking")
        toEmail = self.emailEntry.get()
        self.remove()
        if validateEmail(email=toEmail):
            self.waitDialog = StickyDialog(self,
                                           message="Revoking! Please wait...")
            updateAclGrantThread = UpdateFileACL(queue=self.queue,
                                                 owner=self.fileDetails[0],
                                                 name=self.fileDetails[1],
                                                 grant=False,
                                                 toEmail=toEmail)
            updateAclGrantThread.start()
            self.checkACLUpdateQueue()
        else:
            GenericDialog(self,
                          title="Error!",
                          message="Invalid Email Address!")

    def grantAccess(self):
        print("granting")
        toEmail = self.emailEntry.get()
        self.remove()
        if validateEmail(email=toEmail):
            self.waitDialog = StickyDialog(self,
                                           message="Granting! Please wait...")
            updateAclGrantThread = UpdateFileACL(queue=self.queue,
                                                 owner=self.fileDetails[0],
                                                 name=self.fileDetails[1],
                                                 grant=True,
                                                 toEmail=toEmail)
            updateAclGrantThread.start()
            self.checkACLUpdateQueue()
        else:
            GenericDialog(self,
                          title="Error!",
                          message="Invalid Email Address!")

    def checkACLUpdateQueue(self):
        if not self.queue.empty():
            self.aclUpdateResponse = self.queue.get()
            self.waitDialog.remove()
            print(self.aclUpdateResponse)
            self.afterACLUpdateResponse()
        else:
            self.root.after(100, self.checkACLUpdateQueue)

    def afterACLUpdateResponse(self):
        if self.aclUpdateResponse == StatusCode.OK:
            GenericDialog(self.root, title="Success!", message="ACL Updated")
        elif self.aclUpdateResponse == StatusCode.FAILED_PRECONDITION:
            GenericDialog(self.root,
                          title="Error!",
                          message="No such user email found!")
        elif self.aclUpdateResponse == StatusCode.NOT_FOUND:
            GenericDialog(self.root,
                          title="Error!",
                          message="File not found.\nRefresh and try again!")
        elif self.aclUpdateResponse == StatusCode.INTERNAL:
            GenericDialog(self.root,
                          title="Error!",
                          message="Internal server error!")
        else:
            GenericDialog(self.root,
                          title="Error!",
                          message="Some other error occurred!")