示例#1
0
def browseProjects():
  conn = dbconn2.connect(dsn)
  try:
    if 'uid' in session:
      uid = session['uid']
      roleDB = updateDB.checkUserRole(conn, uid)
      roleCheck = updateDB.getRole(conn, session)
      if 'student' in roleDB['role']:
        if request.method == 'POST':
          pid = request.form['projectID']
          result = updateDB.applyToProject(conn, uid, pid)
          if result == None:
            flash('You have already applied to project ' + pid + '. You cannot apply to a project twice. ')
          else:
            flash('You have successfully applied to project  number ' + pid)
          projects = updateDB.getProjects(conn)
        else:
          projects = updateDB.getProjects(conn)
        return render_template('browse.html',
                              projects = projects,
                              role = roleCheck
                              )
      else:
        flash('Only students have access to this page, please login with a student account')
    else:
        flash('You are not logged in. Please login or join')
  except Exception as e:
    flash(e)
  return redirect( url_for('index') )
示例#2
0
def clientProjects():
  conn = dbconn2.connect(dsn)
  roleCheck = updateDB.getRole(conn, session)
  try:
    if 'uid' in session:
      uid = session['uid']
      roleDB = updateDB.checkUserRole(conn, uid)
      if 'client' in roleDB['role']:
        if request.method == 'POST':
          pid = request.form['projectID']
          updateDB.deleteProject(conn, pid) 
          flash("Project Deleted")
        projects = updateDB.getUserProjects(conn, uid)
        return render_template('clientProjects.html',
                              projects = projects,
                              role = roleCheck
                             )
      else:
        flash('Only clients have access to this page, please login with a client account')
        return redirect( url_for('index') )
    else:
        flash('You are not logged in. Please login or join')
        return redirect( url_for('index') )
  except Exception as e:
    flash(e)
    return redirect( url_for('index') )
示例#3
0
def projectApproval():
  conn = dbconn2.connect(dsn)
  roleCheck = updateDB.getRole(conn, session)
  try:
    if 'uid' in session:
      uid = session['uid']
      roleDB = updateDB.checkUserRole(conn, uid)
      if 'admin' in roleDB['role']:
        if request.method == 'POST':
          pid = request.form['projectID']
          updateDB.approveProject(conn, uid, pid) 
          flash("selection approved")
        projects = updateDB.getUnapprovedProjects(conn)
        return render_template('projectApproval.html',
                              projects = projects,
                              role = roleCheck
                             )
      else:
        flash('Only administrators have access to this page, please login with an admin account')
        return redirect( url_for('index') )
    else:
        flash('You are not logged in. Please login or join')
        return redirect( url_for('index') )
  except Exception as e:
    flash(e)
    return redirect( url_for('index') )
示例#4
0
def createProject():
  conn = dbconn2.connect(dsn)
  try:
    roleCheck = updateDB.getRole(conn, session)
    if 'uid' in session:
      uid = session['uid']
      roleDB = updateDB.checkUserRole(conn, uid)
      if 'client' in roleDB['role']: 
        if request.method == 'POST':
          projName = request.form['projectTitle']
          projDur = request.form['duration']
          projComp = request.form['compensation']
          projRoles = request.form['rolesOpen']
          projReq = request.form['requirements']
          projDesc = request.form['description']
          projCreator = uid
          if (projName == '' or projDur == '' or projComp == '' or projRoles == ''\
            or projReq == '' or projDesc == ''):
            flash('Please fill out all fields.')
          else:
            updateDB.addProject(conn, projCreator, projName, projDur, projComp,\
            projRoles, projReq, projDesc)
            flash ("Project Submitted")
            return render_template('project.html', role = roleCheck)
        else:
          return render_template('project.html', role = roleCheck) 
      else:
        flash('Only clients have access to this page, please login with a client account')
        return redirect( url_for('index') )
    else:
      flash('You are not logged in. Please login or join')
      return redirect( url_for('index') )
  except Exception as e:
    flash(e)
    return redirect( url_for('index') )
示例#5
0
def login():
  conn = dbconn2.connect(dsn)
  flaskemail = request.cookies.get('flaskemail')
  roleCheck = updateDB.getRole(conn, session)
  if request.method == 'GET':
    if 'uid' in session:
      return redirect(url_for('user', uid=session['uid']))
    else:
      return render_template('login.html',
                              email=flaskemail or "",
                              role = roleCheck)
  else:
    #case 2: user submitted a form with their name 
    try:
      email = request.form['email']
      passwd = request.form['passwd']
      row = updateDB.fetchHashed(conn, email)
      if row is None:
          # Same response as wrong password, so no information about what went wrong
          flash('Login incorrect. Try again or join.')
          return redirect( url_for('login'))
      hashed = row['hashed']

      if bcrypt.hashpw(passwd.encode('utf-8'),hashed.encode('utf-8')) == hashed:
          uid = updateDB.getUIDName(conn, email)[0]
          name = updateDB.getUIDName(conn, email)[1]

          session['uid'] = uid
          session['logged_in'] = True
          session['name'] = name

          resp = make_response(redirect( url_for('user', uid=uid) ))
          resp.set_cookie('flaskemail', email)

          flash(('Successfully logged in as {}, user number {}, with email {}').format(name,uid,email))

          return resp
      
      else:
          flash('Login incorrect. Try again or join')
          return redirect( url_for('login'))

    except Exception as err:
      flash('form submission error '+str(err))
      return redirect( url_for('index') )
示例#6
0
def viewApplications():
  conn = dbconn2.connect(dsn)
  try:
    roleCheck = updateDB.getRole(conn, session)
    if 'uid' in session:
      uid = session['uid']
      roleDB = updateDB.checkUserRole(conn, uid)
      if 'client' in roleDB['role']:
        applications = updateDB.getApplicationsPerClient(conn, uid)
        print(applications)
        return render_template('viewApplications.html', applications=applications, role = roleCheck)
      else:
        flash('Only clients have access to this page, please login with a client account')
    else:
        flash('You are not logged in. Please login or join')
  except Exception as e:
    flash(e)
  return redirect( url_for('index') )
示例#7
0
def user(uid):
  try:
      conn = dbconn2.connect(dsn)
      roleCheck = updateDB.getRole(conn, session) #gets role of user from backend
      
      if 'uid' not in session:
        flash('You are not logged in. Please login or join')
        return redirect( url_for('login') )

      #uid in session
      uid = session['uid']
      name = session['name']
      return render_template('greet.html',
                              name=name,
                              role = roleCheck
                             )
          
  except Exception as err:
      flash('Error: '+str(err))
      return redirect( url_for('index') )
示例#8
0
def createProfile():
  conn = dbconn2.connect(dsn)
  try: 
    roleCheck = updateDB.getRole(conn, session)
    if 'uid' in session:
      uid = session['uid']
      roleDB = updateDB.checkUserRole(conn, uid)
      if 'student' in roleDB['role']: 
        if request.method == 'POST':
          major = request.form['major']
          prog_languages = request.form['prog_languages']
          courses = request.form['courses']
          research_exp = request.form['research_exp']
          internship_exp = request.form['internship_exp']
          bg_info = request.form['bg_info']
          updateDB.updateUser(conn, major, prog_languages, courses, research_exp, 
          internship_exp, bg_info, uid)
          f = request.files['resume']
          mimetype = f.content_type.split('/')[1]
          if mimetype != 'pdf':
            flash('Please upload a PDF')
          else:
            filename = secure_filename(str(uid)+ '.pdf')
            pathname = 'static/' + filename
            f.save(pathname)
            flash('Upload successful')
            flash ("Profile Update Submitted")
            return render_template('profile.html', role = roleCheck, src=url_for('resume',fname=filename))
        else:
          return render_template('profile.html', role = roleCheck)
      else:
          flash('Only students have access to this page, please login with a student account')
          return redirect( url_for('index') )
    else:
      flash('You are not logged in. Please login or join')
      return redirect( url_for('index') )
  except Exception as e:
    flash(e)
    flash('Incorrectly filled, try again')
    return redirect( url_for('index') )
示例#9
0
def profile():
  conn = dbconn2.connect(dsn)
  try:
    roleCheck = updateDB.getRole(conn, session)
    if 'uid' in session:
      uid = session['uid']
      profile = updateDB.getProfileInfo(conn, uid)
      if request.method == 'POST':
        return redirect( url_for('createProfile') )
      else:
        fname = str(uid) + '.pdf'
        fpath = 'static/' + fname
        if os.path.isfile(fpath):
          return render_template('viewProfile.html', profile=profile, role = roleCheck,
          src=url_for('resume',fname=fname))
        else:
          return render_template('viewProfile.html', profile=profile, role = roleCheck, src='')
    else:
      flash('You are not logged in. Please login or join')
      return redirect( url_for('index') )
  except Exception as e:
    flash(e)
  return redirect( url_for('index') )
示例#10
0
def index():
  conn = dbconn2.connect(dsn)
  roleCheck = updateDB.getRole(conn, session)
  return render_template('main.html',
                           title='Main Page',
                           role = roleCheck)