def register(): if "user" in session: flash("Please logout first to register another account!") return render_template('home.html',name=db.getName(session['user'])) if request.method=='GET': return render_template('register.html') else: name=request.form['name'] user=request.form['user'] pw=request.form['pass'] color=request.form['color'] if name == "" or user == "" or pw =="" or color == "": flash('Please fill in all the fields') return redirect('/register') elif db.existingName(user)== False: flash('Your username is already taken!') return redirect('/register') else: if db.registerUser(user,name,color,pw): return redirect('/login') else: return redirect('/about') ##should be replaced with flash
def create_group(self): description = self.textBox.get("1.0", "end-1c") initialPost = "Hello. Welcome to the group!" if self.name.get() == "" or description == "": messagebox.showwarning("Create Group Status", "All fields are required!") else: db.cursor.execute( "INSERT INTO projects(name, description, creator) VALUES(%s, %s, %s)", (self.name.get(), description, db.getName())) db.cursor.execute("SELECT id FROM projects WHERE name = '%s'" % self.name.get()) groupID = db.cursor.fetchone()[0] #Creator is auto in group db.cursor.execute("INSERT INTO group_membership VALUES (%s, %s)", (db.getName(), groupID)) #Insert intial post to db to display db.cursor.execute("INSERT into posts VALUES (%s, %s, %s, %s)", (1, groupID, db.getName(), initialPost))
def invite(self): try: for selected_item in self.tree.selection(): inviter = db.getName() invited = self.tree.item(selected_item, 'values') db.cursor.execute("SELECT LAST_INSERT_ID()") groupID = db.cursor.fetchone() db.cursor.execute("INSERT INTO invitations VALUES(%s, %s, %s)", (inviter, invited[0], groupID[0])) for selected_item in self.tree.selection(): self.tree.delete(selected_item) except db.mysql.connector.errors.IntegrityError: messagebox.showwarning("Status", "Create Group First!")
def __init__(self): self.win = Tk() self.win.title("White/Black List") self.win.geometry('{}x{}'.format(800, 450)) self.canvas = Canvas(self.win, bg='#36393F') self.frame = Frame(self.canvas, bg='#36393F', width=600, height=340) self.userSelected = StringVar() self.whitebox = Treeview(self.frame, columns=1, show="headings", height="5") self.blackbox = Treeview(self.frame, columns=1, show="headings", height="5") self.userList = Combobox(self.frame, width=20, textvariable=self.userSelected, state="readonly") self.user = db.getName()
def settings(): if 'user' not in session: session['return_to']='/settings' return redirect('/login') else: if request.method=='GET': return render_template('settings.html',name=db.getName(session['user'])) else: ##get new info and update user = session['user'] name=request.form['name'] pw = request.form['oldpw'] newpw = request.form['newpw'] color = request.form['color'] if pw == "" or not db.updateUserInfo(user,pw,newpw,name,color): flash("Please enter your correct current password to make any changes!") return redirect("/settings") else: return redirect('/home')
def login(): if "user" in session: flash("Please logout first to log into another account!") return render_template('home.html',name=db.getName(session['user'])) if request.method=='GET': return render_template('login.html') else: user=request.form['user'] pw=request.form['pass'] if db.validateUser(user,pw): session['user']=user if 'return_to' in session: s = session['return_to'] session.pop('return_to',None) return redirect(s) else: return redirect('/home') else: flash('Please enter a valid username and password') return render_template('login.html')
def login(): if "user" in session: flash("Please logout first to log into another account!") return render_template('about.html',name=db.getName(session['user'])) if request.method=='GET': return render_template('login.html') else: ## get and validate user's info user=cgi.escape(request.form['user'],quote=True) pw=cgi.escape(request.form['pass'],quote=True) if db.validateUser(user,pw): session['user']=user if 'return_to' in session: s = session['return_to'] session.pop('return_to',None) return redirect(s) else: return redirect('/about') else: flash('Please enter a valid username and password') return render_template('login.html')
def send_compliment(self): for selected_item in self.users.selection(): user_id = self.users.item(selected_item, 'values')[0] description = self.textBox.get("1.0", "end-1c") user = db.getName() db.cursor.execute( "INSERT INTO comments\ (commentator,userdirected,comment,comment_type)\ values(%s,%s,%s,1)", (user, user_id, description)) db.cursor.execute( "SELECT reputation_score FROM users WHERE username = %s", (user_id, )) curr_rs = db.cursor.fetchone()[0] new_rs = reputationScore.changeScore(curr_rs, 1) db.cursor.execute( "UPDATE users SET reputation_score = %s WHERE username = %s", ( new_rs, user_id, ))
def reject(self): for selected_item in self.list.selection(): email = self.list.item(selected_item, 'values')[2] self.list.delete(selected_item) db.cursor.execute("SELECT rejected FROM pending_users WHERE email = %s", (email,)) rejNum = db.cursor.fetchone()[0] if rejNum == 0: rejNum += 1 db.cursor.execute("UPDATE pending_users SET rejected = %s WHERE email = %s", (rejNum,email)) subject = "Application Denied" content = '''\ Sorry, but your application has been denied. \n You have one chance to appeal and the SU will make a final decision to \n reverse the rejection. If you receive another rejection, then you \n will be put in blacklist forever. \ ''' send_email(subject, content, email) elif rejNum == 1: db.cursor.execute("DELETE FROM pending_users WHERE email = %s", (email,)) db.cursor.execute("INSERT INTO black_list VALUES (%s, %s)", (db.getName(), email))
def __init__(self): self.win = Tk() self.win.title("The Hive") self.win.geometry('{}x{}'.format(800, 450)) self.canvas = Canvas(self.win, bg='#36393F') self.frame = Frame(self.canvas, bg='#36393F', width=600, height=340) self.acceptButton = Button(self.frame, text="Accept", font='Arial 15 bold', bg='#36393F', fg="#f7cc35", command=self.accept) self.declineButton = Button(self.frame, text="Decline", font='Arial 15 bold', bg='#36393F', fg="#f7cc35", command=self.decline) self.list = Treeview(self.frame, columns=(1, 2, 3, 4), show="headings", height="15") self.user = db.getName()
def __init__(self): self.win = Tk() self.win.title('Post Updates') self.win.configure(bg="#36393F") self.win.geometry('{}x{}'.format(600, 400)) #Get and store user info from database name = db.getName() db.cursor.execute("SELECT id FROM projects WHERE viewing = 'ON'") groupID = db.cursor.fetchone()[0] db.cursor.execute( "SELECT postid FROM posts WHERE group_id = '%s' ORDER BY postid DESC LIMIT 1" % groupID) postCount = db.cursor.fetchone()[0] tabooCount = db.getTabooCount() reputation = db.getRepScore() # Parent widget for the buttons self.buttons_frame = Frame(self.win) self.buttons_frame.configure(bg="black") self.buttons_frame.grid(row=0, column=0, sticky=W + E) self.btn_Image = Button(self.buttons_frame, text='Clear', command=self.clear) self.btn_Image.grid(row=0, column=0, padx=(10), pady=10) self.btn_File = Button(self.buttons_frame, text='File', command=self.open_file) self.btn_File.grid(row=0, column=2, padx=(10), pady=10) self.submit_btn = Button( self.buttons_frame, text='Submit', command=lambda: self.submit(name, groupID, postCount + 1, tabooCount, reputation)) self.submit_btn.grid(row=0, column=4, padx=(10), pady=10) self.frame = LabelFrame(self.win, text="Hive Post", padx=5, pady=5, bg="#36393F", fg="white") self.frame.grid(row=1, column=0, columnspan=3, padx=10, pady=10, sticky=E + W + N + S) self.win.columnconfigure(0, weight=1) self.win.rowconfigure(1, weight=1) self.frame.rowconfigure(0, weight=1) self.frame.columnconfigure(0, weight=1) # Create the textbox self.textbox = scrolledtext.ScrolledText(self.frame, width=40, height=10) self.textbox.grid(row=0, column=0, sticky=E + W + N + S) self.win.mainloop()
def home(): if 'user' not in session: session['return_to']='/home' return redirect('/login') else: return render_template('home.html',name=db.getName(session['user']))
def about(): if 'user' not in session: return render_template('about.html') else: return render_template('about.html',user=session['user'],name=db.getName(session['user']))
def initUI(self): # UI bckground Settings canvas = Canvas(self) self.master.title("Super User") self.pack(fill=BOTH, expand=TRUE) canvas.pack(fill=BOTH, expand=1) canvas.configure(bg='#36393F') #If user is kicked out db.cursor.execute("SELECT login_time FROM users WHERE status = 'ON'") lastTime = db.cursor.fetchone()[0] if lastTime == "LAST": messagebox.showwarning("Reminder", "This is the last time you can log in! Finish all required business before logging out as you may not log in again afterwards.") #Get and store user info from database name = db.getName() rep_score = db.getRepScore() tabooCount = db.getTabooCount() hello = "Hello " + name # scoreDisplay = "Reputation Score: " + str(rep_score) # db.cursor.close() # greeting for user canvas.create_text(120, 50, text = hello, font = ("Pursia",25), fill = "#7289DB") # display user score # canvas.create_text(120, 100, text = scoreDisplay, font = ("Pursia",15), # fill = "#7289DB") # Calculate dimensions: https://www.mathopenref.com/coordpolycalc.html user_select_1 = [674,401,587,351, 587,351,500,401, 500,401,500,501, 500,501,587,551, 587,551,674,501, 674,501,674,401] user_select_2 = [499,401,412,351, 412,351,325,401, 325,401,325,501, 325,501,412,551, 412,551,499,501, 499,501,499,401] user_select_3 = [587,250,500,200, 500,200,413,250, 413,250,413,350, 413,350,500,400, 500,400,587,350, 587,350,587,250] user_display_name = [552,370,500,340, 500,340,448,370, 448,370,448,430, 448,430,500,460, 500,460,552,430, 552,430,552,370] canvas.create_polygon(user_select_1, outline='black', fill='#2C92D6', width=2) canvas.create_polygon(user_select_2, outline='black', fill='#37CAEF', width=2) canvas.create_polygon(user_select_3, outline='black', fill='#3EDAD8', width=2) canvas.create_polygon(user_display_name, outline='black', fill='#ffffff', width=2) # hexagon for user select s1 = [412,325,390,312, 390,312,368,325, 368,325,368,350, 368,350,390,362, 390,362,412,350, 412,350,412,325] s2 = [632,325,610,312, 610,312,588,325, 588,325,588,350, 588,350,610,362, 610,362,632,350, 632,350,632,325] s3 = [522,515,500,502, 500,502,478,515, 478,515,478,540, 478,540,500,552, 500,552,522,540, 522,540,522,515] canvas.create_polygon(s1, fill='white', width=1) canvas.create_polygon(s2, fill='white', width=1) canvas.create_polygon(s3, fill='white', width=1) # Left Side Hexagon p1 = [97,388,75,375, 75,375,53,388, 53,388,53,413, 53,413,75,425, 75,425,97,413, 97,413,97,388] p2 = [97,463,75,450, 75,450,53,463, 53,463,53,488, 53,488,75,500, 75,500,97,488, 97,488,97,463] p3 = [97,538,75,525, 75,525,53,538, 53,538,53,563, 53,563,75,575, 75,575,97,563, 97,563,97,538] canvas.create_polygon(p1,fill='#2C92D6', width=1) canvas.create_polygon(p2,fill='#37CAEF', width=1) canvas.create_polygon(p3,fill='#3EDAD8', width=1) # Left labels canvas.create_text(125, 400, text = "My Projects", font = ("Pursia",15), fill = "white", anchor=W) canvas.create_text(125, 475, text = "Pending Users", font = ("Pursia",15), fill = "white",anchor=W) canvas.create_text(125, 550, text = "Evaluate Group", font = ("Pursia",15), fill = "white", anchor=W) # Right Side Hexagon g1 = [947,388,925,375, 925,375,903,388, 903,388,903,413, 903,413,925,425, 925,425,947,413, 947,413,947,388] g2 = [947,463,925,450, 925,450,903,463, 903,463,903,488, 903,488,925,500, 925,500,947,488, 947,488,947,463] g3 = [947,538,925,525, 925,525,903,538, 903,538,903,563, 903,563,925,575, 925,575,947,563, 947,563,947,538] canvas.create_polygon(g1, fill='white', width=1) canvas.create_polygon(g2, fill='white', width=1) canvas.create_polygon(g3, fill='white', width=1) # group Labels canvas.create_text(875, 400, text = "Comment", font = ("Pursia",15), fill = "white", anchor=E) canvas.create_text(875, 475, text = "Schedule", font = ("Pursia",15), fill = "white", anchor=E) canvas.create_text(875, 550, text = "Kick Out", font = ("Pursia",15), fill = "white", anchor=E) # display date date = datetime.datetime.now() current_date = date.strftime("%B %d") canvas.create_text(500, 385, text = current_date, font = ("Pursia",20), fill = "black") canvas.create_text(500, 415, text = " ", fill = "black", tags='timer') def time_now(): now = datetime.datetime.now() s = '{0:0>2d}:{1:0>2d}:{2:0>2d}'.format(now.hour, now.minute, now.second) canvas.itemconfig('timer', text = s) self.after(100, time_now) time_now()
from tkinter import * import mysql.connector import sys import db import checkForTaboo as checkT import reputationScore as repScore #Get and store user info from database name = db.getName() username = '******' + name + ']: ' db.cursor.execute("SELECT name FROM projects WHERE viewing = 'ON'") groupName = db.cursor.fetchone()[0] groupFileName = groupName + '_chat.txt' tabooCount = db.getTabooCount() reputation = db.getRepScore() # send message through button def Press_Button(name, tabooCount, reputation): get_input = input_field.get() messages.configure(state='normal') hasTaboo = checkT.check(get_input) post = get_input if hasTaboo: tabooCount += 1 newRep = repScore.tabooWord(reputation, tabooCount) db.cursor.execute( "Update users SET reputation_score = %s where username = %s", (newRep, name)) db.cursor.execute(