Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Account.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Account Management

TODO: change password and add userName
"""

Expand Down Expand Up @@ -38,7 +37,6 @@ def logIn(email, psd):
IF USER NOT EXISTS, return string
-1: user not exists
2: already logged in

"""

if DB.checkUserExists(email):
Expand Down Expand Up @@ -92,15 +90,15 @@ def promoteToSU(email):
return True


def createGuest(email, password):
def createGuest(email, password,name, techInterest):
"""
For GU
:param email:
:param password: IS AN EMPTY STRING
:return:
"""
if not DB.checkUserExists(email):
DB.addUser(email, password, '2') # 2 for GU
DB.addUser(email, password, '2', name, techInterest) # 2 for GU
return True


Expand Down
7 changes: 2 additions & 5 deletions Control.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

def userType(email):
"""

:param email:
:return: return the user type of current user
"""
Expand All @@ -25,7 +24,6 @@ def userType(email):
def ROOTUSER(email):
"""
GUI guide: 在初始登录界面,如果数据库有SU用户,可以直接登录SU

在OU用户登录后,出现一个管理按钮。如果数据库里没有SU,弹窗询问是否升级为SU
如果选择是,当前OU升级为SU
:param email:
Expand All @@ -44,7 +42,7 @@ def signUp(email, password, name, techInterest):
:return:
"""
if password == "":
if Account.createGuest(email, password):
if Account.createGuest(email, password, name, techInterest):
return 0

if Account.createAcc(email, password, name, techInterest):
Expand All @@ -55,7 +53,6 @@ def signUp(email, password, name, techInterest):

def signIn(email, password):
"""

:param email: required
:param password: required only for OU and SU, GU can leave it blank
:return: login status in string format
Expand Down Expand Up @@ -92,4 +89,4 @@ def manage(email):


if __name__ == '__main__':
signUp('test','123','haoran',['computer','sleep'])
print(signUp('testababa123','','guest',['computer','sleep']))
10 changes: 4 additions & 6 deletions DB.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from firebase_admin import db
from Firebase_cred.Firebase import initial
from time import strftime, localtime
from Firebase_cred import Firebase

initial()
Firebase.initial()

root = db.reference()
tabooWord = root.child('Taboo_word')
Expand Down Expand Up @@ -36,7 +35,7 @@ def addUser(email, psd, userType, name, techInterest):
'Password': psd,
'User_type': userType,
'Logged_in': False,
'Name': name,
'Name': name
})

for interest in techInterest:
Expand Down Expand Up @@ -83,7 +82,6 @@ def changeUserType(email, userType):

def changeLoginStat(email, stat):
"""

:param email:
:param stat: False for logged out, True for logged in
:return:
Expand Down Expand Up @@ -198,4 +196,4 @@ def getApplDecision(email):


if __name__ == '__main__':
print(getApplDecision('guest'))
print(SUexists())
18 changes: 8 additions & 10 deletions Document.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def saveDoc(email, doc, fileName):

def listallfiles(email):
"""

:param email:
:return: list of all the current user documents
"""
Expand All @@ -73,7 +72,6 @@ def listallfiles(email):

def listallhistory(email, filename):
"""

:param filename:
:return: list of edit history for a file
"""
Expand All @@ -99,7 +97,6 @@ def getLastestVersion(email, filename):

def openfile(email, fileOwner, filename, version):
"""

:param email:
:param filename:
:param version: if blank then open the newest one, use listallhistory to get one of the version
Expand All @@ -115,10 +112,10 @@ def openfile(email, fileOwner, filename, version):
url = "https://firebasestorage.googleapis.com/v0/b/llhc-db662.appspot.com/o/savedocs%2F" + DB.removeIllegalChar(
email) + "%2F" + filename + "%2F" + version + "?alt=media"

urllib.request.urlretrieve(url, "cache")
file = open('cache', "r")
fileout = file.read()
file.close()
urllib.request.urlretrieve(url, "../cache")
#file = open('../cache', "r")
#fileout = file.read()
#file.close()

if not email == fileOwner:
ref = DB.user.child(DB.removeIllegalChar(email)).child("View_counter")
Expand All @@ -130,7 +127,7 @@ def openfile(email, fileOwner, filename, version):
}
})

return fileout
#return fileout


def isFileLocked(email, filename):
Expand Down Expand Up @@ -171,7 +168,6 @@ def changeLock(email, filename):

def getMostview():
"""

:return: the three of the most viewed docs
"""

Expand Down Expand Up @@ -221,4 +217,6 @@ def getPermissionFiles(permissionType):
#print(getMostview())
#print(listallfiles('guest'))
#setPermission('viewtest','test1','public')
getPermissionFiles('public')
#print(getMostview())
#saveDoc('hrgutou@gmail.com','test.txt','test2')
pass
36 changes: 0 additions & 36 deletions GUI/Controller.py

This file was deleted.

155 changes: 155 additions & 0 deletions GUI/OUSUmainwindow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!
import time

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QDialog
import User, DB
#from GUI.editor import Ui_MainWindow as EDITOR
from GUI import editor_Dialog
from GUI.editor_Dialog import Ui_Dialog as UI_Dialog_editor


import atexit

class OUSU_mainwindow_Dialog(QDialog):
def setupUi(self, Dialog, email):
QtWidgets.QWidget.__init__(self)

self.email = email
userType = DB.currentUserGroup(email)

if userType == 1:
self.userObject = User.OU(email) ######## object
else:
self.userObject = User.SU(email) ######## object


Dialog.setObjectName("Dialog")
Dialog.resize(792, 563)
Dialog.setStyleSheet("QDialog {background-image: url(images/ou_su_image.JPG)\n"
"}")
self.welcome_label = QtWidgets.QLabel(Dialog)
self.welcome_label.setGeometry(QtCore.QRect(30, 20, 181, 31))
self.welcome_label.setStyleSheet("#welcome_label{\n"
" color: purple\n"
"}")
self.welcome_label.setObjectName("welcome_label")
self.email_label = QtWidgets.QLabel(Dialog)
self.email_label.setGeometry(QtCore.QRect(20, 50, 201, 16))
self.email_label.setStyleSheet("#email_label{\n"
" color: purple;\n"
"}")
self.email_label.setText("")
self.email_label.setObjectName("email_label")
self.email_label.setText(email)
self.listWidget = QtWidgets.QListWidget(Dialog)
self.listWidget.setGeometry(QtCore.QRect(-5, 141, 811, 421))
self.listWidget.setObjectName("listWidget")
self.addItem()


self.horizontalLayoutWidget = QtWidgets.QWidget(Dialog)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(430, 40, 341, 83))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.textEdit = QtWidgets.QTextEdit(self.horizontalLayoutWidget)
self.textEdit.setMaximumSize(QtCore.QSize(16777215, 20))
self.textEdit.setObjectName("textEdit")
self.horizontalLayout.addWidget(self.textEdit)
self.search_button = QtWidgets.QPushButton(self.horizontalLayoutWidget)
self.search_button.setObjectName("search_button")
self.horizontalLayout.addWidget(self.search_button)
self.manage_button = QtWidgets.QPushButton(Dialog)
self.manage_button.setGeometry(QtCore.QRect(650, 0, 114, 32))
self.manage_button.setObjectName("manage_button")
self.manage_button.setText("Manage")
self.manage_button.setVisible(False)

# check if SU exist
if not DB.SUexists():
print("not exist ")
self.manage_button.setVisible(True)
else:
if DB.currentUserGroup(email) == 0:
self.manage_button.setVisible(True)
#########################3 button event ########################
self.manage_button.clicked.connect(self.manage_event)
self.listWidget.itemActivated.connect(self.listClickListener)
#######################################################################


self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
Dialog.setTabOrder(self.textEdit, self.search_button)

def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.welcome_label.setText(_translate("Dialog", "<html><head/><body><p><span style=\" font-size:18pt; font-weight:600;\">Welcome, </span></p></body></html>"))
self.search_button.setText(_translate("Dialog", "Search"))

def listClickListener(self,item):
clickedTarget = item.text()
if not clickedTarget == "New Document":
clickedTarget = clickedTarget.replace(" ","_")
self.userObject.openDoc(self.email, clickedTarget, "")
#this will store a cache file in disk for BE to read
editor_Dialog.loadBE()
time.sleep(1)
self.editorWindow = QtWidgets.QDialog()
self.editor = UI_Dialog_editor()
self.editor.setupUi(self.editorWindow)
self.editor.setFileName(clickedTarget)
self.editorWindow.exec_()
self.editor.uploadDoc(self.email, False)
else:
### This will create a new document ###
editor_Dialog.loadBE()
time.sleep(1)
self.editorWindow = QtWidgets.QDialog()
self.editor = UI_Dialog_editor()
self.editor.setupUi(self.editorWindow)
self.editorWindow.exec_()
self.editor.uploadDoc(self.email, True)#true because it is new file

def manage_event(self):
print("manage button is clicked")

def addItem(self):
self.listWidget.addItem("New Document")

listofFile = self.userObject.listallfiles()
if listofFile == 0:
listofFile = self.userObject.mostPopular()
# got the list of tuples


# else:
# for file in listofFile:
#
# self.listWidget.addItem(file.replace("_", " "))


##if click New Document, call editor


#def clickList(self):

def exitEvent():
pass
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = OUSU_mainwindow_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
Loading