def deleteAccount(environ, start_response): wasloggedin = login.isLoggedIn(login.getLoginToken(environ)) conn = connectToDatabase.connect() c = conn.cursor() c.execute("DELETE FROM users WHERE userid = %s", [login.getUserId(login.getLoginToken(environ))]) conn.commit() c.close() conn.close() string += genHTML.genPageHeader('EngCupid') string += genHTML.genMenuBar("EngCupid", [dict(link='browse.py', name='Browse', active=True)], login.getLoginToken(environ)) string += genHTML.beginContainer() if wasloggedin: string += """\ <div class='span12'> <div class="hero-unit"> <H1>Account Deleted</H1> <p>Your account has been removed from our system.</p> </div> </div> """ else: return forbidden.forbidden(environ,start_response) string += genHTML.endContainer() string += genHTML.genPageFooter() start_response(ok.code(), [('Content-type', 'text/html')]) return string
def printPage(environ, start_response): if not login.isLoggedIn(login.getLoginToken(environ)): return forbidden.forbidden(environ,start_response) string = '' qs = parse_qs(environ['QUERY_STRING'], keep_blank_values=True) excepted = False try: if 'pagenum' in qs: pagenum = int(qs['pagenum'][0]) else: pagenum = 0 except: pagenum = 0 excepted = True try: search = qs['search'][0] except: search = '' responseCode = ok.code() string += genHTML.genPageHeader('EngCupid') string += genHTML.genMenuBar("EngCupid", [dict(link='browse.py', name='Browse', active=False)], login.getLoginToken(environ)) string += genHTML.beginContainer() if excepted or pagenum > (countUserProfiles(search, '%', '%')-1)/10 and countUserProfiles(search, '%', '%')!= 0: return notFound.notFound(environ, start_response) else: if countUserProfiles(search, '%', '%') == 0: string += "<div class='span12'><div class=\"hero-unit\"><H1>No Results Found</H1><p>We're sorry but there are no users that meet your search criteria</p></div></div>" else: string += genHTML.genPagination((countUserProfiles(search, '%', '%') - 1)/10, environ['SCRIPT_NAME']+'?search='+search, pagenum) string += getUserProfiles(search, '%', '%', 10, pagenum) string += genHTML.endContainer() string += genHTML.genPageFooter() start_response(responseCode, [('Content-type', 'text/html')]) return string
def genMenuBar(title, links, token): menuString = """\ <div class="navbar navbar-fixed-top"> <div class="navbar-inner"> <div class="container"> <a class="brand" href="%(base)sindex.py">%(title)s</a> <div class="nav-collapse"> <ul class="nav"> """ % {'title':title, 'base':connectToDatabase.getDirBase()} for l in links: menuString += ("""\ <li %(activeClass)s><a href=\"%(link)s\">%(name)s</a></li>""") \ % {'link': l['link'],'name':l['name'], 'activeClass':'class="active"' if l['active'] else ''} if login.isLoggedIn(token): menuString += """\ </ul> <ul class="nav pull-right"> <li> <form action="search.py" method="GET" name='search' class="navbar-search"> <input type="text" name="search" placeholder="Search" class="search-query span2"> </form> </li> <li class="divider-vertical"></li> <li class="dropdown"> <a data-toggle="dropdown" class="dropdown-toggle" href="#">%(name)s<b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="logout.py">Log Out</a></li> </ul> </li> </ul> </div><!--/.nav-collapse --> </div> </div> </div> """ % {'name':login.getName(token)} else: menuString += """\ </ul> <ul class="nav pull-right"> <li><a href="login.py">Log In</a></li> </ul> </div><!--/.nav-collapse --> </div> </div> </div> """ return menuString
def getUserImage(environ, start_response): m = re.search('userid=([^&]*)', environ['QUERY_STRING']) headers = [] status = '' message = '' if not login.isLoggedIn(login.getLoginToken(environ)): return forbidden.forbidden(environ,start_response) if m==None: return notFound.notFound(environ,start_response) userid = m.group(1) connection = connectToDatabase.connect() c = connection.cursor() c.execute("SELECT image,gender FROM users WHERE userid = %s", [userid]) i = c.fetchone() c.close() connection.close() if i==None: return notFound.notFound(environ,start_response) imageData = '' if i[0] == None: if i[1] == None or i[1] == 'M': imageData = open (os.getcwd() + os.sep + 'anonymouse_images' + os.sep + 'wikipedia_annonymous_male.png').read() else: imageData = open(os.getcwd() + os.sep + 'anonymouse_images' + os.sep + 'wikipedia_annonymous_female.png').read() else: imageData = i[0] mime,contentEncoding = mimetypes.guess_type(imageData) headers = [('Content-type', str(mime))] if not contentEncoding == None: headers.append(('Content-encoding', str(contentEncoding))) message = imageData status = ok.code() headers.append(('Content-Length', str(len(message)))) start_response(status, headers) return message
def printPage(environ, start_response): if not login.isLoggedIn(login.getLoginToken(environ)): return forbidden.forbidden(environ,start_response) qs = parse_qs(environ['QUERY_STRING'], keep_blank_values=True) if ('userid' in qs): if countUserProfiles(qs['userid'], '', '') > 0: l = getUserInfo("SELECT * FROM users WHERE userid = %s", [qs['userid']]) else: return notFound.notFound(environ,start_response) else: return notFound.notFound(environ,start_response) responseCode = ok.code() string = '' string += genHTML.genPageHeader('EngCupid') string += genHTML.genMenuBar("EngCupid", [dict(link='browse.py', name='Browse', active=False)], login.getLoginToken(environ)) string += genHTML.beginContainer() string += printUser.getUserProfile(l) string += genHTML.endContainer() string += genHTML.genPageFooter() start_response(responseCode, [('Content-type', 'text/html')]) return string
def __init__(self): super().__init__() #Initializing window self.setDarkMode() self.left = 0 self.top = 0 self.title = 'Bajton helper' self.width = 1000 self.height = 700 self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) #Checking user login if (login.isLoggedIn() == " "): login.loginForm(app) else: print("[OK]Last known login is valid") #display tabs self.tabs_widget = Tabs(self) self.setCentralWidget(self.tabs_widget) #check if configured to be headless parser = ConfigParser() parser.read('props.ini') if (parser["GUI"]["headless"] != "True"): self.show()
def deleteAccount(environ, start_response): loggedin = login.isLoggedIn(login.getLoginToken(environ)) userid = '' qs = parse_qs(environ['QUERY_STRING'], keep_blank_values=True) if loggedin: userid = login.getUserId(login.getLoginToken(environ)) elif 'userid' in qs: userid = qs['userid'] else: return forbidden.forbidden(environ,start_response) conn = connectToDatabase.connect() c = conn.cursor() c.execute("UPDATE FROM users SET account_status = 'Active' WHERE userid = %s", [userid]) conn.commit() c.close() conn.close() string += genHTML.genPageHeader('EngCupid') string += genHTML.genMenuBar("EngCupid", [dict(link='browse.py', name='Browse', active=True)], login.getLoginToken(environ)) string += genHTML.beginContainer() string += """\ <div class='span12'> <div class="hero-unit"> <H1>Account Deleted</H1> <p>Your account is now active.</p> <p><a class="btn btn-primary btn-large" href="login.py"> Login </a></p> </div> </div> """ string += genHTML.endContainer() string += genHTML.genPageFooter() start_response(ok.code(), [('Content-type', 'text/html')]) return string