diff --git a/app.py b/app.py index d1680e7..f7c43ce 100644 --- a/app.py +++ b/app.py @@ -2,6 +2,7 @@ from flask import Flask, render_template, request, session import logging from mysql import connector +from passlib.hash import sha256_crypt app = Flask(__name__) @@ -31,7 +32,7 @@ def connect_db(host, user, password, database): @app.route('/') def home(): - return render_template('home.html') + return render_template('/home.html') @app.route('/contact_us') @@ -39,6 +40,36 @@ def contact_us(): return render_template('/contact_us.html') +@app.route('/send_message', methods=['GET', 'POST']) +def send_message(): + if request.method == 'POST': + userDetails = request.form + username = userDetails['username'] + msg = userDetails['content'] + mycursor = conn.cursor() + sql = "INSERT INTO messages (username, content) VALUES (%s, %s)" + val = (username, msg) + mycursor.execute(sql, val) + conn.commit() + return render_template('/send_message.html') + + +def authenticate_user(username, password): + if check_username(username): + if check_password(username, password): + return True + else: + # TODO: flash a message about incorrect password + return False + # TODO: flash a message about incorrect username + return False + + +def check_password(username, password): + # TODO: check password against the db + pass + + @app.route('/messages_view') def messages_view(): message = conn.cursor() @@ -62,9 +93,10 @@ def log_in(): req = request.form email = req.get("email") password = req.get("password") + # if authenticate_user(username, password): session["EMAIL"] = email session["PASSWORD"] = password - return render_template('Home.html', email=session["EMAIL"]) + return render_template('home.html', email=session["EMAIL"]) return render_template('/sign_up.html') @@ -88,3 +120,16 @@ def check_username(username): else: # the user exists return True + + +def check_password(username, password): + maulers = conn.cursor() + Fender = "SELECT password FROM users WHERE username =" + username + maulers.execute(Fender) + result = maulers.fetchall() + if sha256_crypt.verify(password, result): + return True + else: + return False + + diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index c5e5b59..a2153c2 100644 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -38,6 +38,7 @@ pip3 install -r /vagrant/requirements.txt create table users(username VARCHAR(25) NOT NULL, password VARCHAR(100) NOT NULL, create_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY(username)); create table messages(message_id int NOT NULL AUTO_INCREMENT, username VARCHAR(25) NOT NULL, content text, create_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, primary key(message_id), foreign key(username) references users(username)); + INSERT into users(username,password) VALUES('dummy','1234'); DESCRIBE users; DESCRIBE messages; MYSQL_SCRIPT diff --git a/static/css/cssHome.css b/static/css/cssHome.css index 2a31db4..774c38a 100644 --- a/static/css/cssHome.css +++ b/static/css/cssHome.css @@ -1,3 +1,5 @@ +* {background-color: lightgrey;} + img { height: 200px; width: 250px; @@ -7,16 +9,12 @@ main { padding: inherit; text-align: center; color: black; - background-color: lightgrey; font-family: arial; } -header { - background-color: lightgrey; -} - nav { clear: both; + background-color: red; } ul { @@ -25,7 +23,7 @@ ul { padding: 0; overflow: hidden; background-color: red; - color: whitesmoke; + color: black; float: none; } @@ -53,8 +51,13 @@ li a:hover { .footer { background-color: red; - color: #ffffff; + color: black; text-align: center; font-size: 12px; padding: 15px; } + + +a.one:link {color:white; background-color:red;} +a.one:visited {color:white; background-color:red;} +a.one:hover {color:white; background-color:red;} \ No newline at end of file diff --git a/templates/Home.html b/static/templates/Home.html similarity index 100% rename from templates/Home.html rename to static/templates/Home.html diff --git a/templates/messages_view.html b/static/templates/messages_view.html similarity index 100% rename from templates/messages_view.html rename to static/templates/messages_view.html diff --git a/templates/sign_up.html b/static/templates/sign_up.html similarity index 100% rename from templates/sign_up.html rename to static/templates/sign_up.html diff --git a/templates/home.html b/templates/home.html new file mode 100644 index 0000000..6577769 --- /dev/null +++ b/templates/home.html @@ -0,0 +1,16 @@ +{% extends "layout.html" %} +{% block title %} homePage {% endblock %} +{% block content %} + +

+

Welcome to The Academic College of Tel Aviv-Yaffo chat-App!!!

+

This app will allow you to send a message and view it.

+

You can view our app's messages whenever you want!

+

If you would like to use our app, you need to follow these steps:

+

1. Register / Log in

+

2. Send a message

+

If you would like to read about +us and our collaboration with the RedHat team, you can click on this +link.

+

Have Fun!

+{% endblock %} \ No newline at end of file diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 0000000..29c4719 --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,38 @@ + + + + + + {% block head %} + {% block title %}{% endblock %} - ChatApp + {% endblock %} + + + + +
+ + + +
+ + +
+ {% block content %}{% endblock %} +
+ + + + + + diff --git a/templates/send_message.html b/templates/send_message.html new file mode 100644 index 0000000..08ba052 --- /dev/null +++ b/templates/send_message.html @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + Tiger + + + + + + + {% extends "layout.html" %} + {% block content %} + +

Send Message

+

+ Enter your email
+ Enter your message
+
+

+
+

+ +

+ + + + {% endblock %} + + + +