예제 #1
0
def makeThread():
  global current_user
  global privilages
  information = ""
  if privilages < 2 :
    information = "Information: Husk at disse tråde skal hovedsagtligt blive anvendt til klargørelse af symptomer af vores professionelle eller spørge ind til processer"
  else:
    information = "Annonceringer vil altid så i toppen af forummet, for at angive retningslinjer eller nyheder"
  if request.method == 'POST':
    if current_user == []:
      return redirect(url_for('startPage'))
    header = tostring(request.form.get('header'))
    body = tostring(request.form.get('content'))
    open = tostring(request.form.get('open'))
    if header == "" or body == "":
      return render_template('createThread.html', current_user=current_user, privilages=privilages, information=information, postColor="red", error="Begge felter skal være udfyldte")
    conn, stateConn = postgresql.createConnection("prototype")
    if stateConn:
      rowcount, success = postgresql.execute(conn,
        "INSERT INTO threads (CPR, header, content, is_open) " +
        "VALUES ('" + current_user[0] + "', '" + tostring(header) + "', '" + tostring(body) + "', " + ("TRUE" if open == "on" else "FALSE") + ")")
      if success:
        postgresql.closeConnection(conn)
        return redirect(url_for('startPage'))
      else:
        postgresql.closeConnection(conn)
        return redirect(url_for('errorDisplay', error="Kunne ikke indsætte ny besked i databasen"))
    else:
      return redirect(url_for('errorDisplay', error="Kunne ikke forbinde til databasen"))
  elif request.method == 'GET':
    return render_template('createThread.html', current_user=current_user, privilages=privilages, information=information, postColor="lightgray", error="")
예제 #2
0
def deleteThread():
  global current_user
  global privilages
  if current_user != [] and privilages >= 0:
    tid = request.args['threadid']
    conn, state = postgresql.createConnection("prototype")
    if state:
      prownum, stateposts = postgresql.execute(conn, "DELETE FROM posts WHERE tid=" + tid)
      trownum, statethread = postgresql.execute(conn, "DELETE FROM threads WHERE id=" + tid)
      if not statethread or not stateposts:
        postgresql.closeConnection(conn)
        return redirect(url_for('errorDisplay', error="Kunne ikke slette tråd fra databasen"))
      if trownum < 1:
        print("No rows affected by delete")
      print("Deleted " + prownum + " posts from thread " + tid)
      postgresql.closeConnection(conn)
      return redirect(url_for('startPage'))
    else:
      return redirect(url_for('errorDisplay', error="Kunne ikke forbinde til databasen"))
  else:
    return redirect(url_for('startPage'))
예제 #3
0
def deletePost():
  global current_user
  global privilages
  if current_user != [] and privilages >= 0:
    pid = request.args['postid']
    tid = request.args['threadid']
    query = "DELETE FROM posts WHERE id=" + pid
    conn, state = postgresql.createConnection("prototype")
    if state:
      rownum, statequery = postgresql.execute(conn, "DELETE FROM posts WHERE id=" + pid)
      if not statequery:
        postgresql.closeConnection(conn)
        return redirect(url_for('errorDisplay', error="Kunne ikke slette tråd fra databasen"))
      if rownum < 1:
        print("No rows affected by delete")
      postgresql.closeConnection(conn)
      return redirect(url_for('enterThread', threadid=tid))
    else:
      return redirect(url_for('errorDisplay', error="Kunne ikke forbinde til databasen"))
  else:
    return redirect(url_for('startPage'))
예제 #4
0
def loginPage():
  global current_user
  global patient
  global privilages
  usercolor = "#000000"
  pswdcolor = "#000000"
  error = ""
  try:
    if request.method == 'POST':
      changebutton = False
      try:
        if (request.form.get('changeType') == "Ansat?" or request.form.get('changeType') == "Patient?"):
          patient = not patient
          changebutton = True
      except:
        print("Not changing type")
      if (not changebutton):
        try:
          username = request.form.get('username')
          password = request.form.get('password')
          if (username != ""):
            conn, state = postgresql.createConnection("prototype")
            print("Attempt to log in on user: "******"patients" if patient else "employees"
            user, rowcount, state = postgresql.query(conn,
              "SELECT * FROM users INNER JOIN " + usertype + " ON users.CPR=" + usertype + ".CPR " +
              "AND users.CPR='" + str(username) + "'")
            #Check in database if CPR exists
            if (rowcount == 1):
              print("Found user in DB: " + user[0][1] + " " + user[0][2] + " with password: "******"UPDATE users SET last_online_date='" + str(now) + "' WHERE CPR='" + user[0][0] + "'")
                user[0][6] = now
                current_user=user[0]
                if (not patient):
                  privilages = int(user[0][10])
                else:
                  privilages = -1
                print("Login success, privilages: " + str(privilages))
                return redirect(url_for('startPage'))
              else:
                print("Password missmatch, wrote " + password + " but expected " + user[0][3])
                pswdcolor = "#ff0000"
                error = "Password matcher ikke"
            else:
              usercolor = "#ff0000"
              error = "Ingen bruger med denne CPR"
        except Exception as e:
          print("Not submitting: " + str(e))
    elif request.method == 'GET':
      print("Login: GET request")
  except Exception as e:
    print(e)
  return render_template('login.html',
                         current_user=current_user,
                         privilages=privilages,
                         usertype="Patient" if patient else "Ansat",
                         notUsertype="Ansat?" if patient else "Patient?",
                         usercolor=usercolor,
                         pswdcolor=pswdcolor,
                         error=error)
예제 #5
0
def enterThread():
  global current_user
  global privilages
  if request.method == 'POST':
    if current_user == []:
      return redirect(url_for('startPage'))
    postText = request.form.get('postInput')
    if postText != "":
      conn, state = postgresql.createConnection("prototype")
      if state:
        threadid = request.args['threadid']
        success = postgresql.execute(conn,
          "INSERT INTO posts (tid, CPR, content) " +
          "VALUES (" + threadid + ", '" + current_user[0] + "', '" + tostring(postText) + "')")
        if success:
          postgresql.closeConnection(conn)
          return redirect(url_for('enterThread', threadid=threadid))
        else:
          postgresql.closeConnection(conn)
          return redirect(url_for('errorDisplay', error="Kunne ikke indsætte ny besked i databasen"))
      else:
        return redirect(url_for('errorDisplay', error="Kunne ikke forbinde til databasen"))
    else:
      return redirect(url_for('enterThread', threadid=request.args['threadid'], error="Skriv dog noget mand!", border="border: 2px solid red"))

  elif request.method == 'GET':
    threadid = request.args['threadid']
    conn, stateConn = postgresql.createConnection("prototype")
    if stateConn:
      #THREAD INFO
      #[0]: tid, [1]: firstname, [2]: lastname, [3]: header, [4]: content, [5]: created_date
      #[6]: processID, [7]: journalID, [8]: specialization, [9]: works_at, [10]: CPR
      threadDat, rowcount, stateThread = postgresql.query(conn,
        "SELECT threads.id, users.firstname, users.lastname, threads.header, threads.content, threads.created_date, " +
          "patients.process_id, patients.journal, " +
          "employees.specialization, employees.works_at, " +
          "users.CPR, threads.is_open " +
          "FROM threads " +
            "INNER JOIN users ON threads.CPR=users.CPR " +
            "LEFT JOIN patients ON users.CPR=patients.CPR " +
            "LEFT JOIN employees ON users.CPR=employees.CPR " +
            "WHERE threads.id=" + tostring(threadid))
      if stateThread and rowcount > 0:
        thread = threadDat[0]
        #POST INFO
        #[0]: firstname, [1]: lastname, [2]: content, [3]: created_date, [4]: modified_date
        #[5]: processID, [6]: journalID, [7]: specialization, [8]: works_at
        postsDat, _, statePosts = postgresql.query(conn,
          "SELECT users.firstname, users.lastname, posts.content, posts.created_date, posts.modified_date, " +
            "patients.process_id, patients.journal, " +
            "employees.specialization, employees.works_at, posts.id " +
            "FROM posts " +
              "INNER JOIN users ON posts.CPR=users.CPR " +
              "LEFT JOIN patients ON users.CPR=patients.CPR " +
              "LEFT JOIN employees ON users.CPR=employees.CPR " +
              "WHERE posts.tid=" + tostring(thread[0]) + " ORDER BY posts.created_date DESC")
        if statePosts:
          posts = []
          for post in postsDat:
            posts.append(forum.post(str(post[9]), post[0] + " " + post[1], post[2], formatDate(str(post[3])), formatDate(str(post[4])), post[5], post[6], post[7], post[8]))
          thread = forum.thread(thread[10], thread[1] + " " + thread[2], thread[3], thread[4], formatDate(str(thread[5])), thread[6], thread[7], thread[8], thread[9], posts, thread[11])
          postgresql.closeConnection(conn)
          error=""
          border=""
          try:
            error = request.args['error']
          except:
            print("No error")
          try:
            border = request.args['border']
          except:
            print("No border")
          return render_template('thread.html', current_user=current_user, privilages=privilages, thread=thread, error=error, border=border)
        else:
          postgresql.closeConnection(conn)
          return redirect(url_for('errorDisplay', error="Kunne ikke udtrække svarene fra databasen"))
      else:
        postgresql.closeConnection(conn)
        return redirect(url_for('errorDisplay', error="Kunne ikke udtrække trådene fra databasen eller ingen tråd fundet med id: " + str(threadid)))
    else:
      return redirect(url_for('errorDisplay', error="Kunne ikke forbinde til databasen"))