def register(): '''allows user to register by creating a username and password; if username is unique, encrypts passwords and store it''' try: username = request.form['username'] password1 = request.form['password1'] password2 = request.form['password2'] if password1 != password2: flash('Passwords do not match.') return redirect(url_for('login')) hashed = bcrypt.hashpw(password1.encode('utf-8'), bcrypt.gensalt()) #hashed=password1 conn = getConn() curs = conn.cursor(MySQLdb.cursors.DictCursor) curs.execute('select email from user where email=%s', [username]) row = curs.fetchone() if row is not None: flash('This email has already been used') return redirect(url_for('login')) curs.execute('insert into user(email,hashed) values (%s,%s)', [username, hashed]) session['username'] = username session['logged_in'] = True flash('Successfully logged in as' + username) return redirect(url_for('login')) except Exception as err: flash('From submission error' + str(err)) return redirect(url_for('home'))
def login(): #the code below works well if request.method=='GET': return render_template('login.html') else: try: print("test enter") username=request.form['username'] password=request.form['password'] conn=getConn() curs=conn.cursor(MySQLdb.cursors.DictCursor) curs.execute('select hashed from user where email=%s',[username]) row=curs.fetchone() if row is None: flash('Login failed. Please register or try again') return redirect(url_for('home')) hashed=row['password'] if bcrypt.hashpw(password.encode('utf-8'),hashed.encode('utf-8'))==hashed: print("test enter1") flash('Login failed. Please register or try again') return redirect(url_for('home')) hashed=row['password'] if (bcrypt.hashpw(password.encode('utf-8'),hashed.encode('utf-8'))==hashed.encode('utf-8')): print("test enter2") flash('Successfully logged in as'+username) session['username']=username session['logged_in']= True return redirect(url_for('home')) else: flash('Login failed. Please register or try again') return redirect(url_for('login')) except Exception as err: flash('From submission error'+str(err)) return redirect(url_for('home'))
def jobs(): conn = getConn() if request.method == 'GET': jobs = clickDatabase.getJobs(conn) return render_template('jobs.html', jobs=jobs) else: if request.form['submit'] == 'Search': search = request.form.get('searchJobs') filteredJobs = clickDatabase.searchJobs(conn, search) return render_template('jobs.html', jobs=filteredJobs)
def submit_insertPosting(): conn = getConn() if request.method == 'POST': # checking database to see if the given pid is in use if (clickDatabase.search_project_pid( conn, request.form['project-pid'])) != None: flash('bad input: project\'s pid already in use.') return render_template('insertProject.html') # checking if info is missing in input if ((request.form['project-pid'] == "") or (request.form['project-name'] == "") or (request.form['project-pay'] == "") or (request.form['project-minHours'] == "") or (request.form['project-location'] == "")): if request.form['project-pid'] == "": flash('missing input: project\'s pid is missing.') if request.form['project-name'] == "": flash('missing input: name is missing.') if request.form['project-pay'] == "": flash('missing input: pay is missing.') if request.form['project-minHours'] == "": flash('missing input: minimum hours is missing.') if request.form['project-location'] == "": flash('missing input: location is missing.') return render_template('insertProject.html') if ((request.form['project-pid'] == "") and (request.form['project-name'] == "") and (request.form['project-pay'] == "") and (request.form['project-minHours'] == "") and (request.form['project-location'] == "")): projectInfo = clickDatabase.search_project_pid( conn, request.form['project-pid']) if projectInfo == None: clickDatabase.insert_project(conn, request.form['project-pid'], request.form['project-name'], request.form['project-pay'], request.form['project-minHours'], request.form['project-location']) flash('Project {name} was created successfully'.format( title=request.form['project-name'])) else: flash("Project already exists") return redirect( url_for('updateProject', pid=request.form['project-pid']))
def posting(pid): conn = getConn() #if GET, renders page with all information about that posting in database if request.method == 'GET': postingInfo = clickDatabase.getPosting(conn, pid) return render_template('posting.html', name = postingInfo['name'], minHours = postingInfo['minHours'], pay = postingInfo['pay'], location = postingInfo['location'], )
def filterProjects(): '''Routes that deal with sorting and filtering project''' conn = getConn() dropdown = request.form.get("menu-tt") checkbox = request.form.get("type") projectByLocation = search_project.getProjectByLocation(conn, checkbox) allProjects = search_project.getAllProjects(conn) #when no dropdown is selected if dropdown == "none": #when checkbox is also not selected if checkbox is None: return render_template('project.html', allProjects=allProjects) #when checkbox is selected else: #there is no project of the selected location if (len(projectByLocation) == 0): flash("There are no projects in the chosen location: " + checkbox) return render_template('project.html', allProjects=projectByLocation) #dropdown is selected else: #check box not selected if checkbox is None: if (dropdown == "Min Hours Ascending"): sortedProjects = search_project.sortProectByMinHoursAscending( conn) return render_template('project.html', allProjects=sortedProjects) elif (dropdown == "Pay Descending"): sortedProjects = search_project.sortProectByPayDescending(conn) return render_template('project.html', allProjects=sortedProjects) elif (dropdown == "Alphabetical By Location"): sortedProjects = search_project.sortProjectByLocation(conn) return render_template('project.html', allProjects=sortedProjects) #both dropdown and checkbox selected else: multiFilter = search_project.multipleFilters( conn, checkbox, dropdown) return render_template('project.html', allProjects=multiFilter)
def login(): #the code below works well '''if request.method=='GET': ======= <<<<<<< HEAD #return render_template('login.html') #somehow the code below gives Bad Request: The browser (or proxy) sent a request that this server could not understand. try: ======= if request.method=='GET': >>>>>>> 667fcb65abf1fd6db4f8400e8f6d928f2b0fb71d return render_template('login.html') else:''' try: print("test enter") username=request.form['username'] password=request.form['password'] conn=getConn() curs=conn.cursor(MySQLdb.cursors.DictCursor) curs.execute('select hashed from user where email=%s',[username]) row=curs.fetchone() if row is None: flash('Login failed. Please register or try again') return redirect(url_for('home')) hashed=row['password'] if bcrypt.hashpw(password.encode('utf-8'),hashed.encode('utf-8'))==hashed: print("test enter1") flash('Login failed. Please register or try again') return redirect(url_for('home')) hashed=row['password'] if (bcrypt.hashpw(password.encode('utf-8'),hashed.encode('utf-8'))==hashed.encode('utf-8')): print("test enter2") flash('Successfully logged in as'+username) session['username']=username session['logged_in']= True return redirect(url_for('home')) else: flash('Login failed. Please register or try again') return redirect(url_for('login')) except Exception as err: flash('From submission error'+str(err)) return redirect(url_for('home'))
def selectPosting(): conn = getConn() allPostings = clickDatabase.find_allPostings(conn) return render_template('selectPosting.html', allPostings=allPostings)
def selectProject(): conn = getConn() allProjects = clickDatabase.find_allProjects(conn) return render_template('selectProject.html', allProjects=allProjects)
#Import of the required classes/packages import connection as vdc import os from libcloud.compute.deployment import ScriptDeployment import allocate_ip_and_port_forwarding_rules as nodeCreator #Assigning the connection driver driver = vdc.getConn() #Assigning the node to bootstrap on it node = nodeCreator.nodeCreator.getNode() #Defining the shell script which installs chef on a unix-based system BOOTSTRAP_SCRIPT = ''' #!/usr/bin/env bash curl -L https://www.opscode.com/chef/install.sh | sudo bash ''' script = ScriptDeployment(script=BOOTSTRAP_SCRIPT) #Run the shell script on the node print 'Running shell script on node: ' + node.name driver._connect_and_run_deployment_script(node=node, task=script, ssh_hostname=node.public_ips[0], ssh_port=22, ssh_username='******', ssh_password=node.extra['password'], ssh_key_file=None, ssh_timeout=10, timeout=600, max_tries=3) print script.stdout
curs.execute('''select last_insert_id();''') result=curs.fetchall() return(result[0][0]) #SQL query to get specifically email of a student with a given name def get_email(conn, name): curs = conn.cursor() curs.execute('''select email from user where name like %s;''', [name + '%']) email = curs.fetchone() return email[0] <<<<<<< HEAD ======= if __name__ == '__main__': conn = getConn('clickdb') #addSkill(conn, "*****@*****.**", "editing") #print(removeSkill(conn, "*****@*****.**", "math tutoring")) #studentSkills(conn, "*****@*****.**") >>>>>>> 83ff4049c0cd53beb03af46781f41625937ed593 if __name__ == '__main__': conn = getConn('clickdb') #addSkill(conn, "*****@*****.**", "public speaking") #print(removeSkill(conn, "*****@*****.**", "math tutoring")) #print(studentSkills(conn, "*****@*****.**"))
def getProjectByLocation(conn, location): """Returns all projects of a specific location""" curs = conn.cursor(MySQLdb.cursors.DictCursor) curs.execute( '''select name,minHours,pay,location from project where location = %s''', [location]) return curs.fetchall() def multipleFilters(conn, fil, sort): """Returns projects after filtering and sorting""" curs = conn.cursor(MySQLdb.cursors.DictCursor) if (sort == "Min Hours Ascending"): curs.execute( '''select name,minHours,pay,location from project where location= %s order by minHours asc''', [fil]) elif (sort == "Pay Descending"): curs.execute( '''select name,minHours,pay,location from project where location= %s order by pay desc''', [fil]) elif (sort == "Alphabetical By Location"): curs.execute( '''select name,minHours,pay,location from project where location= %s order by location''', [fil]) return curs.fetchall() if __name__ == '__main__': conn = getConn()
#Task: Creating a VM on Interoute's VDC 2.0 # #With this program the user chooses from lists of resources to put together the configuration to create a VM import pprint import inputchooser #Import the connection driver import connection as vdc from libcloud.compute.base import NodeAuthPassword #Choose the location (equals the VDC zone) #[Note: is it possible to pass parameter available=true ?] locations = vdc.getConn().list_locations() location_ids= [l.id for l in locations] location_names = [l.name for l in locations] choice = -1 while choice == -1: choice = inputchooser.choose_item_from_list( location_names, prompt='Select your zone:' ) if choice == -1: print() print('Please select a zone.')
#Task: Creating a VM on Interoute's VDC 2.0 # #With this program the user chooses from lists of resources to put together the configuration to create a VM import pprint import inputchooser #Import the connection driver import connection as vdc from libcloud.compute.base import NodeAuthPassword #Choose the location (equals the VDC zone) #[Note: is it possible to pass parameter available=true ?] locations = vdc.getConn().list_locations() location_ids = [l.id for l in locations] location_names = [l.name for l in locations] choice = -1 while choice == -1: choice = inputchooser.choose_item_from_list(location_names, prompt='Select your zone:') if choice == -1: print() print('Please select a zone.') location_num = choice
#Import of the connection driver import connection as vdc from libcloud.compute.base import NodeAuthPassword import random #Setting the configuration details for the VM to be created image = [image for image in vdc.getConn().list_images() if 'IRT-CENTOS-6.5' in image.name][0] size = [size for size in vdc.getConn().list_sizes() if size.name == '6144-2'][0] net = [network for network in vdc.getConn().ex_list_networks() if 'London' in network.name] location = [location for location in vdc.getConn().list_locations() if 'London' in location.name][0] name = 'Interoute-Node' + str(random.randint(0, 100)) #Creating the VM - Equivalent libcloud command: create_node print 'Creating node: ' + name if len(net) == 0 : node = [vdc.getConn().create_node(name=name, image=image, size=size, location=location)] else: node = [vdc.getConn().create_node(name=name, image=image, size=size, location=location, networks=[net[0]])] print 'Created node: ' + name print 'Password: '******'password'] #Method getNode #Returns the node def getNode(): return node[0]