def sign_up(self, user_name, user_password, tech_interest):
        '''This is the function called when "sign up" is clicked'''

        # Check if all fields are filled
        if user_name == '' or user_password == '' or tech_interest == '':
            tk.messagebox.showerror("", "Please fill out all the fields!")
            return

        # Check if username already existed in pending applications
        if AccountsManager.is_pending(user_name):
            tk.messagebox.showerror("Error", "You application is still pending, please wait for approval!")
            return

        # Check if username already existed in accounts db
        if AccountsManager.username_exists(user_name):
            tk.messagebox.showerror("Error", "User name already existed, please re-enter!")
            return

        # Add account application to db
        AccountsManager.add_pending_user({
            'username': user_name,
            'password': user_password,
            'technical_interest': tech_interest
        })
        tk.messagebox.showinfo("Information", "Registration is successful, please wait for approval.")
        self.controller.show_frame("MainPage")
Beispiel #2
0
    def log_in(self, username_input, password_input):

        # Check if all fields are filled
        if username_input == '' or password_input == '':
            tk.messagebox.showerror("Error", "Please fill out all the fields!")
            return

        # Check if username is in pending applications db
        if AccountsManager.is_pending(username_input):
            tk.messagebox.showerror("Error",
                                    "Your application is still pending!")
            return

        # Check if username exists in db, if yes then check password
        if not AccountsManager.username_exists(username_input):
            tk.messagebox.showerror("Error", "Wrong username!")
        else:
            user = AccountsManager.validate_user(username_input,
                                                 password_input)
            if user:
                # If password match (validates successfully), set user info into the system by calling the controller method
                username = username_input
                userid = user['userid']
                usertype = user['usertype']
                self.controller.log_in(username, userid, usertype)
            else:
                tk.messagebox.showerror("Error", "Wrong password!")