Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check password function #164

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
49 changes: 47 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -31,14 +32,44 @@ 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')
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()
Expand All @@ -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')


Expand All @@ -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


1 change: 1 addition & 0 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions static/css/cssHome.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* {background-color: lightgrey;}

img {
height: 200px;
width: 250px;
Expand All @@ -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 {
Expand All @@ -25,7 +23,7 @@ ul {
padding: 0;
overflow: hidden;
background-color: red;
color: whitesmoke;
color: black;
float: none;
}

Expand Down Expand Up @@ -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;}
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends "layout.html" %}
{% block title %} homePage {% endblock %}
{% block content %}
<img src="https://media.giphy.com/media/OkJat1YNdoD3W/source.gif">
<p></p><p></p>
<h1>Welcome to The Academic College of Tel Aviv-Yaffo chat-App!!!</h1>
<h2 style="color:red;">This app will allow you to send a message and view it. </h2>
<h2 style="color:purple;"> <b>You can view our app's messages whenever you want! </b></h2>
<h3>If you would like to use our app, you need to follow these steps:</h3>
<h3><b>1. <a href="{{ url_for('log_in') }}">Register </a> / <a href="{{ url_for('log_in') }}">Log in</a></b></h2>
<h3><b>2. Send a message </b></h3>
<h3>If you would like to read about <a href="https://www.int.mta.ac.il/the-student-union" target=_blank>
us</a> and our collaboration with the <a href="https://www.redhat.com/en" target=_blank>RedHat</a> team, you can click on this
<a href="https://www.facebook.com/141518342586502/posts/3159131667491806/" target=_blank>link</a>. </h3>
<h1>Have Fun!</h1>
{% endblock %}
38 changes: 38 additions & 0 deletions templates/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">

<head>
<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/cssHome.css') }}">
{% block head %}
<title>{% block title %}{% endblock %} - ChatApp </title>
{% endblock %}

</head>

<body>
<header>
<a href="{{ url_for('home') }}" target=_self>
<img src="{{ url_for('static', filename='pic/logo_1.png') }}" id="homeLogo" alt="RedHat&MTA">
</a>
</header>
<nav>
<ul>
<li><a class="one" href="{{url_for('home') }}"> Home Page</a></li>
<li><a class="one" href="{{url_for('log_in') }}"> Log-In</a></li>
<li><a class="one" href="{{url_for('messages_view') }}"> View Messages</a></li>
<li><a class="one" href="{{url_for('send_message') }}"> Send Message</a></li>

</ul>
</nav>

<main>
{% block content %}{% endblock %}
</main>

<div class="footer">
<h2>&copy; Copyright 2020 by <a href="https://www.facebook.com/141518342586502/posts/3159131667491806/">MTA Students</a></h2>
</div>

</body>

</html>
46 changes: 46 additions & 0 deletions templates/send_message.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="width=device-width,initial-scale=1" name="viewport">
<meta content="description" name="description">
<meta name="google" content="notranslate" />
<meta content="Mashup templates have been developped by Orson.io team" name="author">

<!-- Disable tap highlight on IE -->
<meta name="msapplication-tap-highlight" content="no">

<title>Tiger</title>

<link rel="stylesheet" type="text/css" href=" {{ url_for('static',filename='style.css') }}">
</head>


<body>
{% extends "layout.html" %}
{% block content %}

<h1>Send Message</h1>
<form method="POST"><br>
Enter your email <input type="text" name="username"/> <br>
Enter your message<br>
<textarea rows="4" cols="40" name="content"> </textarea> <br>
<p id="time">
<script>
document.getElementById("time").innerHTML = Date();

</script><br>
</p>
<input type="submit" value="Send Message"> <input type="Reset" name="reset1" value="Reset">
</form><br>



{% endblock %}

</body>

</html>