def lbl_forgotpwd_click(self, event): if getattr(self, 'txt_in_username').get_text() == '': MessageModal( self, title='Error', message= f'Please enter your username to recieve an email containing the verification code!', messageType='info') else: user = Container.filter( User, User.userName == getattr( self, 'txt_in_username').get_text()).first() if user == None: MessageModal(self, title='Error', message=f'This username doesn\'t exist!', messageType='error') else: sparepwd = Container.filter( SparePwd, SparePwd.userId == user.id).first() if sparepwd == None or sparepwd.expirationDate < datetime.now( ): sparepwd = SparePwd(user=user, expirationDate=datetime.now() + timedelta(days=1), verificationCode=generate_code()) Container.save(sparepwd) MessageModal( self, title='Success', message='A verification code has been sent to your email!', messageType='info') send_email(user, sparepwd.verificationCode)
def btn_signup_next(self, event): validated_fields = self.validate_step() if self.current + 1 == 3 and validated_fields == 2: if Container.filter( User, User.userName == getattr( self, 'txt_up_username').get_text()).first() != None: MessageModal( self, title='UserName taken', message= f'{getattr(self, "txt_up_username").get_text()} is already taken\nplease pick another userName!', messageType='error') else: atts = {} Container.save( User(email=self.txt_email.get_text(), userName=self.txt_up_username.get_text(), firstName=self.txt_firstname.get_text(), lastName=self.txt_lastname.get_text(), password=self.txt_up_pwd.get_text(), company=self.txt_company.get_text(), gender=self.txt_gender.get_text())) self.empty_all() MessageModal( self, title='Success', message= 'Account created !\nFeel free to Login and good luck with your work!', messageType='info') MoveTransition(self.frm_veil_set_x, self.frm_veil_get_x, 0, 2.5) else: return validated_fields
def invite_user(self, username): def send_invite(msg, user, privilege): inv = Invitation(privilege=privilege, invitationTime=datetime.datetime.now(), sender=CollaborationWindow.ACTIVE_USER, recipient=user, session=self.session) Container.save(inv) notif = Notification(type=NotificationType.INVITED.value, notificationTime=datetime.datetime.now(), nature=NotificationNature.INV.value, invitationId=inv.id, actor=inv.sender, recipient=inv.recipient) Container.save(notif) msg.destroy() MessageModal( self, title=f'Success', message=f'Invitation sent to {user.userName} successfully!', messageType='info') user = Container.filter(User, User.userName == username).first() collabs = Container.filter( User, Collaboration.sessionId == self.session.id, or_(User.id == Collaboration.userId, User.id == self.session.ownerId)).all() if user == None: MessageModal( self, title='User error 404', message=f'{username} doesn\'t exist!' if username != '' and not str.isspace(username) else 'Please enter a username!', messageType='error') elif user in collabs: MessageModal(self, title='User already in', message=f'{username} is already in the session!', messageType='error') elif Container.filter(Invitation, Invitation.recipientId == user.id, Invitation.sessionId == self.session.id, Invitation.status == Status.PENDING.value).first() != None: MessageModal(self, title='User already invited', message=f'An invite is already sent to {username}!', messageType='info') else: msg = MessageModal( self, title=f'Confirmation', message= f'An invitation will be sent to [{username}], but do you want to give him the right to make changes?', messageType='prompt', actions={ 'yes': lambda e: send_invite(msg, user, 'edit'), 'no': lambda e: send_invite(msg, user, 'read') })
def join_project(self, modal): link = modal.get_form_data()['txt_link'] slink = Container.filter(ShareLink, ShareLink.link == link).first() if slink == None: MessageModal(self, title= f'Link error' ,message= 'This link doesn\'t exist!', messageType= 'error') elif slink.expirationDate < datetime.now(): MessageModal(self, title= f'Link error' ,message= 'This link has expired!', messageType= 'error') else: if slink.project.owner != HomeWindow.ACTIVE_USER :noti = Notification(notificationTime= datetime.now(), type= NotificationType.JOINED.value, nature= NotificationNature.SHARELINK.value, invitationId= slink.id, actor= HomeWindow.ACTIVE_USER, recipient= slink.project.owner) modal.destroy() self.windowManager.run(EditorWindow(self.master, slink.project))
def btn_signin_click(self, event): if getattr(self, 'txt_in_username').get_text() == '' or getattr( self, 'txt_in_password').get_text() == '': MessageModal( self, title='Error', message=f'Please enter your username and password to login!', messageType='info') else: user = Container.filter( User, User.userName == getattr( self, 'txt_in_username').get_text()).first() if user == None: MessageModal(self, title='Error', message=f'This username doesn\'t exist!', messageType='error') else: if user.password != getattr(self, 'txt_in_password').get_text(): sparepwd = Container.filter( SparePwd, SparePwd.userId == user.id).order_by( SparePwd.expirationDate.desc()).first() if sparepwd != None and sparepwd.verificationCode == getattr( self, 'txt_in_password').get_text(): if sparepwd.expirationDate < datetime.now(): MessageModal( self, title='Expired code', message=f'This verification code has expired!', messageType='error') else: window = ProfileWindow(self.master, user=user) self.windowManager.run(window) MessageModal( self, title='Change password', message=f'Please change your password!', messageType='info') else: MessageModal( self, title='Wrong password', message= f'Wrong password, please try again or request a verification code!', messageType='error') else: self.windowManager.run(HomeWindow(self.master, user=user))
def revert_changes(msg, history): history.project.file = history.file history.project.lastEdited = history.editDate history.project.image = history.image Container.save(history.project) msg.destroy() for li in self.historyItems: if li.dataObject.editDate >= history.editDate: Container.deleteObject(li.dataObject) li.destroy() photo = getdisplayableimage(history.image, (self.frm_preview.winfo_width(), self.frm_preview.winfo_height())) self.lbl_image.configure(image=photo) self.lbl_image.image = photo MessageModal( self, title=f'Success', message= f'Changes reverted to the following date:\n{history.editDate.strftime("%x - %X")}!', messageType='info') getattr( self, 'lbl_' + CollaborationWindow.lblSettings[2]['prop'] )['text'] = history.editDate.strftime( "%d/%m/%Y" ) if datetime.datetime.now( ).strftime("%x") != history.editDate.strftime( "%x") else 'Today at - ' + history.editDate.strftime("%X")
def kick_user(self, user): def delete_collaboration(user): Container.deleteObject( Container.filter( Collaboration, Collaboration.userId == user.id, Collaboration.sessionId == self.session.id).first()) msg.destroy() for li in self.collaboratorItems: if li.dataObject == user: li.destroy() getattr( self, 'lbl_' + CollaborationWindow.lblSettings[3]['prop'] )['text'] = str( Container.filter( Collaboration, Collaboration.sessionId == self.session.id).count() + 1) MessageModal( self, title=f'Success', message=f'{user.userName} has been kicked out of the session!', messageType='info') msg = MessageModal( self, title=f'Confirmation', message=f'Are you sure you want to kick {user.userName}?', messageType='prompt', actions={'yes': lambda e: delete_collaboration(user)})
def create(self, modal, nature= PROJECT_LI, load= False): title = modal.get_form_data()['txt_title'] date = datetime.now() def create_project(bytesFile= None): project = Project(title= title, creationDate= datetime.now(), lastEdited= datetime.now(), owner= HomeWindow.ACTIVE_USER, file= bytesFile) Container.save(project) self.lv_project.grid_item(project, {'title': project.title, 'creationDate': project.creationDate, 'lastEdited': project.lastEdited}, None, lambda i: self.create_list_item(i, HomeWindow.PROJECT_LI), 15) def create_session(): project = Project(title= title+'Project', creationDate= date, lastEdited= date, owner= HomeWindow.ACTIVE_USER) session = Session(title= title, creationDate= date, owner= HomeWindow.ACTIVE_USER, project= project) message = Message(content=f'welcome to the chat',user=HomeWindow.ACTIVE_USER, session=session, sentDate=session.creationDate) Container.save(project, session, message) seenmessage = SeenMessage(date=session.creationDate, seer=HomeWindow.ACTIVE_USER, messageId=message.id) Container.save(seenmessage) self.lv_session.grid_item(session, {'title': session.title, 'creationDate': project.creationDate, 'lastEdited': project.lastEdited, 'memberCount': str(Container.filter(Collaboration,Collaboration.sessionId == session.id).count()+1)}, None, lambda i: self.create_list_item(i, HomeWindow.SESSION_LI), 15) def load_project(): title = modal.get_form_data()['txt_title'] filename: str= modal.lbl_filename['text'] if filename.endswith('...') != True and filename != '': create_project(filetobytes(filename)) if not re.fullmatch('^[a-zA-Z0-9_]+( [a-zA-Z0-9_]+)*$', title): MessageModal(self,title=f'Title error',message=f'\n1. Must be between 4 - 20 characters \n2. It should not contain any special character',messageType='error') else: create_session() if nature == HomeWindow.SESSION_LI else ( create_project() if load == False else load_project()) modal.destroy()
def check_privilege(msg, modal, inv): def generate_link(msg2, modal, inv, privilege): msg2.destroy() if inv != None: Container.deleteObject(inv) link = f'bpmntool//{self.session.title}/{datetime.datetime.now()}/' Container.save( InvitationLink(link=link, expirationDate=datetime.datetime.now() + datetime.timedelta(days=1), privilege=privilege, sender=CollaborationWindow.ACTIVE_USER, session=self.session)) self.clean_notifications() set_link(link) if msg != None: msg.destroy() msg2 = MessageModal( self, title=f'Confirmation', message=f'Do you want to grant this link the "edit" privilege?', messageType='prompt', actions={ 'yes': lambda e: generate_link(msg2, modal, inv, 'edit'), 'no': lambda e: generate_link(msg2, modal, inv, 'read') })
def refresh_window(self, message=None): window = ProfileWindow(self.master) self.windowManager.run(window) if message != None: MessageModal(window, title=f'Success', message=message, messageType='info') self.destroy()
def export_project(self, title, date, fileBytes): if fileBytes == None: MessageModal(self, title='Error', message='No changes has been made on this project!', messageType='error') else: folderName = filedialog.askdirectory( initialdir="/", title='Please select a directory') if folderName != '': bytestofile(f'{folderName}', f'{title}_{date.strftime("%d-%m-%Y_%H-%M-%S")}', 'xml', fileBytes) MessageModal(self, title=f'Success', message=f'File saved in {folderName}!', messageType='info')
def join_session(self, modal): link = modal.get_form_data()['txt_link'] date = datetime.now() invlink = Container.filter(InvitationLink, InvitationLink.link == link).first() if invlink == None: MessageModal(self, title= f'Link error' ,message= 'This link doesn\'t exist!', messageType= 'error') elif invlink.expirationDate < datetime.now(): MessageModal(self, title= f'Link error' ,message= 'This link has expired!', messageType= 'error') elif Container.filter(Collaboration, Collaboration.userId == HomeWindow.ACTIVE_USER.id, Collaboration.sessionId == invlink.sessionId).first() != None or invlink.session.owner == HomeWindow.ACTIVE_USER: MessageModal(self, title= f'Error' ,message= f'You are already in {invlink.session.title} session!', messageType= 'error') else: # create relations if they don't exist if Container.filter(Relation,Relation.userOne == HomeWindow.ACTIVE_USER, Relation.userTwo == invlink.sender ).first() == None: Container.save(Relation(userOne= HomeWindow.ACTIVE_USER, userTwo= invlink.sender)) if Container.filter(Relation,Relation.userTwo == HomeWindow.ACTIVE_USER, Relation.userOne == invlink.sender ).first() == None: Container.save(Relation(userTwo= HomeWindow.ACTIVE_USER, userOne= invlink.sender)) # create collaboration Container.save(Collaboration(joiningDate= date, privilege= invlink.privilege, user= HomeWindow.ACTIVE_USER, session= invlink.session)) # add an acceptedInv type notification noti = Notification(notificationTime= date, type= NotificationType.JOINED.value, nature= NotificationNature.INVLINK.value, invitationId= invlink.id, actor= HomeWindow.ACTIVE_USER, recipient= invlink.sender) modal.destroy() self.windowManager.run(CollaborationWindow(self.master, invlink.session))
def generate_inviationlink(self, modal): # modal.form[0]['input'].entry.get() def set_link(link): modal.form[0]['input'].entry.delete(0, END) modal.form[0]['input'].entry.insert(0, link) def check_privilege(msg, modal, inv): def generate_link(msg2, modal, inv, privilege): msg2.destroy() if inv != None: Container.deleteObject(inv) link = f'bpmntool//{self.session.title}/{datetime.datetime.now()}/' Container.save( InvitationLink(link=link, expirationDate=datetime.datetime.now() + datetime.timedelta(days=1), privilege=privilege, sender=CollaborationWindow.ACTIVE_USER, session=self.session)) self.clean_notifications() set_link(link) if msg != None: msg.destroy() msg2 = MessageModal( self, title=f'Confirmation', message=f'Do you want to grant this link the "edit" privilege?', messageType='prompt', actions={ 'yes': lambda e: generate_link(msg2, modal, inv, 'edit'), 'no': lambda e: generate_link(msg2, modal, inv, 'read') }) def set_old_link(msg, modal): set_link(inv.link) msg.destroy() inv = Container.filter( InvitationLink, InvitationLink.senderId == CollaborationWindow.ACTIVE_USER.id, InvitationLink.sessionId == self.session.id).first() if inv != None: msg = check_privilege( None, modal, inv ) if inv.expirationDate < datetime.datetime.now( ) else MessageModal( self, title='link found', message=f'A link already exists, Do you want to override it?', messageType='prompt', actions={ 'yes': lambda e: check_privilege(msg, modal, inv), 'no': lambda e: set_old_link(msg, modal) }) else: check_privilege(None, modal, None)
def check_privilege(msg, modal, slink): def generate_link(msg2, modal, slink, privilege): msg2.destroy() if slink != None: Container.deleteObject(slink) link= f'bpmntool//{dataObject.title}/{datetime.now()}/' Container.save(ShareLink(link=link, expirationDate=datetime.now()+timedelta(days=1), privilege= privilege, project=dataObject)) self.clean_notifications() set_link(link) if msg != None: msg.destroy() msg2 = MessageModal(self,title=f'Confirmation',message=f'Do you want to grant this link the "edit" privilege?',messageType='prompt',actions={'yes' : lambda e: generate_link(msg2, modal, slink, 'edit'), 'no' : lambda e: generate_link(msg2, modal, slink, 'read')})
def validate_form_data(self, data): try: for key, value in data.items(): if value == None and key not in ['confirmPwd', 'image']: raise Exception(camel_case(key), f'{key} Cannot be null!') elif key in ['firstName', 'lastName'] and not re.fullmatch( '[A-Za-z]{2,15}( [A-Za-z]{2,15})?', value): raise Exception( camel_case(key), f'\n1. Can contain 2 words with 1 space in between\n2.Must be between 2 - 15 alphabets each' ) elif key in [ 'userName', 'password' ] and not re.fullmatch('^[a-zA-Z0-9_.-]+$', value): raise Exception( camel_case(key), f'can only be alphanumeric and contain (. _ -)') elif key == 'email' and not re.fullmatch( '[^@]+@[^@]+\.[^@]+', value): raise Exception( camel_case(key), f'Please enter a valid email!\nExample: [email protected]' ) elif key == 'company' and value != None and not re.fullmatch( '^[a-zA-Z0-9_]+( [a-zA-Z0-9_]+)*$', value): raise Exception( camel_case(key), f'\n1. Must be between 4 - 20 characters\n2. Should not contain any special characters' ) elif key == 'gender' and value != None and value.lower( ) not in ['female', 'male']: raise Exception(camel_case(key), f'Gender must be either male or female!') elif key == 'confirmPwd' and value != data['password']: raise Exception( 'password confirmation', f'Passwords don\'t match, please confirm your password!' ) return True except Exception as ex: MessageModal(self, title=f'{ex.args[0]} Error', message=ex.args[1], messageType='error') return False
def generate_share_link(self, dataObject, modal): def set_link(link): modal.form[0]['input'].entry.delete(0, END) modal.form[0]['input'].entry.insert(0, link) def check_privilege(msg, modal, slink): def generate_link(msg2, modal, slink, privilege): msg2.destroy() if slink != None: Container.deleteObject(slink) link = f'bpmntool//{dataObject.title}/{datetime.datetime.now()}/' Container.save( ShareLink(link=link, expirationDate=datetime.datetime.now() + datetime.timedelta(days=1), privilege=privilege, project=dataObject)) self.clean_notifications() set_link(link) if msg != None: msg.destroy() msg2 = MessageModal( self, title=f'Confirmation', message=f'Do you want to grant this link the "edit" privilege?', messageType='prompt', actions={ 'yes': lambda e: generate_link(msg2, modal, slink, 'edit'), 'no': lambda e: generate_link(msg2, modal, slink, 'read') }) def set_old_link(msg, modal): set_link(slink.link) msg.destroy() slink = Container.filter(ShareLink, ShareLink.projectId == dataObject.id).first() if slink != None: msg = check_privilege( None, modal, slink ) if slink.expirationDate < datetime.datetime.now( ) else MessageModal( self, title='Link found', message=f'A link already exists, Do you want to override it?', messageType='prompt', actions={ 'yes': lambda e: check_privilege(msg, modal, slink), 'no': lambda e: set_old_link(msg, modal) }) else: check_privilege(None, modal, None)
def send_invite(msg, user, privilege): inv = Invitation(privilege=privilege, invitationTime=datetime.datetime.now(), sender=CollaborationWindow.ACTIVE_USER, recipient=user, session=self.session) Container.save(inv) notif = Notification(type=NotificationType.INVITED.value, notificationTime=datetime.datetime.now(), nature=NotificationNature.INV.value, invitationId=inv.id, actor=inv.sender, recipient=inv.recipient) Container.save(notif) msg.destroy() MessageModal( self, title=f'Success', message=f'Invitation sent to {user.userName} successfully!', messageType='info')
def delete_collaboration(user): Container.deleteObject( Container.filter( Collaboration, Collaboration.userId == user.id, Collaboration.sessionId == self.session.id).first()) msg.destroy() for li in self.collaboratorItems: if li.dataObject == user: li.destroy() getattr( self, 'lbl_' + CollaborationWindow.lblSettings[3]['prop'] )['text'] = str( Container.filter( Collaboration, Collaboration.sessionId == self.session.id).count() + 1) MessageModal( self, title=f'Success', message=f'{user.userName} has been kicked out of the session!', messageType='info')
def remove_collaborator(self, relation): def delete_relation(relation): # delete relation Container.deleteObject(relation) # destroy message msg.destroy() # remove deleted collaborator's listItem for li in self.collaboratorsItems: if li.dataObject == relation: li.destroy() # self.collaboratorItems.remove(li) self.refresh_window( f'{relation.userTwo.userName} has been removed succefully!') # confirm with the user msg = MessageModal( self, title=f'Confirmation', message= f'Are you sure you want to remove {relation.userTwo.userName} from your collaboration list?', messageType='prompt', actions={'yes': lambda e: delete_relation(relation)})
def validate_step(self): valid_fields = 0 try: for i in self.up_congig[self.steptitles[self.current]]: if getattr(self, i.get('name')).get_text() == '' and i.get( 'name') not in ['txt_confirm']: raise Exception(camel_case(i.get("label")), f'{i.get("label")} Cannot be null!') elif i.get('name') in [ 'txt_firstname', 'txt_lastname' ] and not re.fullmatch('[A-Za-z]{2,15}( [A-Za-z]{2,15})?', getattr(self, i.get('name')).get_text()): raise Exception( camel_case(i.get("label")), f'\n1.Can contain 2 words with 1 space in between\n2.Must be between 2 - 15 alphabets each' ) elif i.get('name') in [ 'txt_up_username', 'txt_up_pwd' ] and not re.fullmatch('^[a-zA-Z0-9_.-]+$', getattr(self, i.get('name')).get_text()): raise Exception( camel_case(i.get("label")), f'can only be alphanumeric and contain (. _ -)') elif i.get('name') == 'txt_email' and not re.fullmatch( '[^@]+@[^@]+\.[^@]+', getattr(self, i.get('name')).get_text()): raise Exception( camel_case(i.get("label")), f'Please enter a valid email!\nEX: [email protected]' ) elif i.get('name') == 'txt_company' and getattr( self, i.get('name')).get_text() != '' and not re.fullmatch( '^[a-zA-Z0-9_]+( [a-zA-Z0-9_]+)*$', getattr(self, i.get('name')).get_text()): raise Exception( camel_case(i.get("label")), f'\n1. Must be between 4 - 20 characters\n2. It should not contain any special characters' ) elif i.get('name') == 'txt_gender' and getattr( self, i.get('name')).get_text() != '' and getattr( self, i.get('name')).get_text().lower() not in [ 'female', 'male' ]: raise Exception(camel_case(i.get("label")), f'Gender must be either male or female!') elif i.get('name') == 'txt_confirm' and getattr( self, i.get('name')).get_text() != getattr( self, 'txt_up_pwd').get_text(): raise Exception( 'Password confirmation', f'Password doesn\'t match.\nPlease confirm your password!' ) valid_fields += 1 except Exception as ex: MessageModal(self, title=f'{ex.args[0]} Error', message=ex.args[1], messageType='error') finally: return valid_fields
def quit_session(self, dataObject): MessageModal(self,title=f'Confirmation',message=f'Do you want to quit [{dataObject.title}] session?',messageType='prompt',actions={'yes' : lambda e: self.delete(Container.filter(Collaboration, Collaboration.userId == HomeWindow.ACTIVE_USER.id, Collaboration.sessionId == dataObject.id).first())})
def delete_session(self, dataObject): MessageModal(self,title=f'Confirmation',message=f'Do you want to delete [{dataObject.title}] session?',messageType='prompt',actions={'yes' : lambda e: self.delete(dataObject.project)})