Skip to content

Commit

Permalink
Merge branch 'master' into fix_after_refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
SaarCohen93 authored Jan 16, 2020
2 parents 0e183c4 + c762602 commit b5c8a16
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 84 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ Instruction for spin VM and destroy:
- All the static files such as: CSS, Images need to be locate in:
tiger/static
- Html files need to be locate in:
tiger/templates
40 changes: 23 additions & 17 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/env python3
from flask import Flask, render_template, request
from flask import Flask, render_template, request, session
import mysql
import logging
from mysql import connector

app = Flask(__name__)

app.config["SECRET_KEY"] = "OCML3BRawWEUeaxcuKHLpw"


def definedlog(fileHandler):
logger = logging.getLogger(__name__)
Expand All @@ -18,38 +21,41 @@ def definedlog(fileHandler):
return logger


def connect_db():
connection = mysql.connector.connect(
user='root', password='LoginPass@@11223344',
host='localhost', database='tiger')
def connect_db(host, user, password, database):
connection = connector.connect(
user=user, password=password, host=host, database=database)
return connection


def view_messages():
connection = connect_db()
message = connection.cursor()
message.execute("SELECT * FROM tiger.messages")
view = message.fetchall()
for row in view:
print(row)
return view
conn = connect_db('localhost', 'root', 'LoginPass@@11223344', 'tiger')


@app.route('/')
def home():
return render_template('/home.html')


@app.route('/messages_view')
def messages_view():
message = conn.cursor()
message.execute("SELECT * FROM tiger.messages ORDER BY create_date DESC")
view = message.fetchall()
return render_template('/messages_view.html', view=view)


@app.route('/log_in', methods=['GET', 'POST'])
# TODO write logic to this function
def log_in():
if request.method == 'POST':
return render_template('home.html')
if request.method == "POST":
req = request.form
email = req.get("email")
password = req.get("password")
session["EMAIL"] = email
session["PASSWORD"] = password
return render_template('Home.html', email=session["EMAIL"])
return render_template('/sign_up.html')


@app.route('/log_out')
# TODO after seesion will be merge write this function
def log_out():
return render_template('home.html')

Expand Down
19 changes: 11 additions & 8 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
#!/usr/bin/env bash
os=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
echo $os

set_mysql () {
systemctl enable $1
systemctl start $1
}

if [ $os == '"Ubuntu"' ]
then
echo "im ubuntu"
apt-get update
# !----------! Setting MySQL root user password root/root !----------!
debconf-set-selections <<< 'mysql-server mysql-server/root_password password LoginPass@@11223344'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password LoginPass@@11223344'
# !----------! install python and mysql !----------!
apt-get -y install python3-pip mysql-server mysql-client

set_mysql "mysql"


else
echo "im fedora"
cp /vagrant/mysql-community.repo /etc/yum.repos.d/
dnf -y update
dnf -y install python3-pip mysql-community-server

set_mysql "mysqld.service"

old_pw=$(grep 'temporary password' /var/log/mysqld.log | awk '{print $NF}')
new_pw='LoginPass@@11223344'
mysqladmin -u root -p"$old_pw" password "$new_pw"


fi
pip3 install -r /vagrant/requirements.txt
systemctl enable mysql
systemctl start mysql

new_pw='LoginPass@@11223344'
mysql -u root -p"$new_pw" <<MYSQL_SCRIPT
CREATE DATABASE tiger;
Expand All @@ -40,4 +43,4 @@ pip3 install -r /vagrant/requirements.txt
MYSQL_SCRIPT

chmod 755 /vagrant/app.py
nohup python3 /vagrant/app.py > /dev/null 2>&1 &
nohup python3 /vagrant/app.py > /dev/null 2>&1 &
4 changes: 1 addition & 3 deletions templates/Home.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

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


</head>

<body>
<header>
<header>
<a href="{{ url_for('home') }}" target=_self>
<img src="{{ url_for('static', filename='pic/logo_1.png') }}" id="homeLogo" alt="RedHat&MTA">
</a>
Expand Down
24 changes: 0 additions & 24 deletions templates/layout.html

This file was deleted.

35 changes: 4 additions & 31 deletions templates/messages_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,16 @@

<h1>View Messages</h1>

<!-- Example to delete -->

<p> This is an example </p>
{% for row in view %}
<div class="wholeMessage">
<div class="bullet">
<img src="{{ url_for('static', filename='logo.jpg') }}" height="20" width="30">
</div>
<div class="message">
<p><b><u>Sapir Hen</u></b></p>
<p>Hi everyone, this is where we are goning to see our messages! </p>
<p><i>Sun Dec 22 16:00:00 2019</i></p>
</div>
</div>
<div class="wholeMessage">
<div class="bullet">
<img src="{{ url_for('static', filename='logo.jpg') }}" height="20" width="30">
</div>

<div>
<div class="message">
<p><b><u>Tomer Cohen</u></b></p>
<p>Wow Sapir it looks amazing </p>
<p><i>Sun Dec 22 16:31:19 2019</i></p>
</div>
</div>
</div>
<br><br><br>

{% for message in messages %}
<div class="wholeMessage">
<div class="bullet">
<img src="{{ url_for('static', filename='logo.jpg') }}" height="20" width="30">
</div>
<div class="message">
<p><b><u>{{message['tital']}}</u></b></p>
<p>{{message['content']}} </p>
<p><i>{{message['username']}}, {{['create_date']}}</i></p>
<p><b><u>{{row[1]}}</u></b></p>
<p>{{row[2]}} </p>
<p><i>{{row[3]}}</i></p>
</div>
</div>
{% endfor %}
Expand Down

0 comments on commit b5c8a16

Please sign in to comment.