Started with the index page, worked on login & register.

multi-deployment
b3yond 2018-01-08 00:09:25 +01:00
parent b9e1b38963
commit 7689eb25f8
8 changed files with 278 additions and 2 deletions

View File

@ -19,14 +19,14 @@ First you need to install python and virtualenv with your favourite package mana
Create and activate virtualenv:
```shell
sudo apt install python virtualenv
sudo apt install python3 virtualenv uwsgi uwsgi-plugin-python nginx
virtualenv -p python3 .
. bin/activate
```
Install the dependencies:
```shell
pip install tweepy pytoml requests Mastodon.py
pip install tweepy pytoml requests Mastodon.py bottle
```
Configure the bot:

90
frontend/login.py Normal file
View File

@ -0,0 +1,90 @@
#!/usr/bin/env python3
import bottle
import sqlite3
class Datagetter(object):
def __init__(self):
self.db = "../../../ticketfrei.sqlite"
self.conn = self.create_connection(self.db)
self.cur = self.conn.cursor()
def create_connection(self, db_file):
""" create a database connection to the SQLite database
specified by the db_file
:param db_file: database file
:return: Connection object or None
"""
try:
conn = sqlite3.connect(db_file)
return conn
except sqlite3.Error as e:
print(e)
return None
app = application = bottle.Bottle()
@app.route('/login', method="POST")
def login():
"""
Login to the ticketfrei account with credentials from the user table.
:return: bot.py Session Cookie
"""
uname = bottle.request.forms.get('uname')
psw = bottle.request.forms.get('psw')
if psw == db.cur.execute("SELECT pass FROM user WHERE email=?;", (uname, )):
# :todo Generate Session Cookie and give to user
return bottle.static_file("../static/bot.html", root="../static")
else:
return "Wrong Credentials."
@app.route('/register', method="POST")
def register():
"""
Login to the ticketfrei account with credentials from the user table.
:return: bot.py Session Cookie
"""
uname = bottle.request.forms.get('email')
psw = bottle.request.forms.get('psw')
pswrepeat = bottle.request.forms.get('psw-repeat')
if pswrepeat != psw:
return "ERROR: Passwords don't match. Try again."
# :todo send confirmation Mail with encoded email+passphrase to email
return "We Sent you an E-Mail. Please click on the confirmation link."
@app.route('/static/<filename:path>')
def static(filename):
"""
Serve static files
"""
return bottle.static_file(filename, root='../static')
@app.route('/')
def show_index():
"""
The front "index" page
:return: /static/index.html
"""
return bottle.static_file("../static/index.html", root='../static')
class StripPathMiddleware(object):
"""
Get that slash out of the request
"""
def __init__(self, a):
self.a = a
def __call__(self, e, h):
e['PATH_INFO'] = e['PATH_INFO'].rstrip('/')
return self.a(e, h)
if __name__ == "__main__":
global db
db = Datagetter()
bottle.run(app=StripPathMiddleware(app), host='0.0.0.0', port=8080)

15
static/bot.html Normal file
View File

@ -0,0 +1,15 @@
<head>
<title>Ticketfrei</title>
<link rel='stylesheet' href='static/css/style.css'>
</head>
<body>
<!--<div class="background" style="background-image: url(static/img/bg_left.jpg)"></div>-->
<div class="area">
<img src="static/img/ticketfrei_logo.png" alt="Ticketfrei Logo" width="180px" align="left">
<div class=footer>
Contribute on <a href="https://github.com/b3yond/ticketfrei">GitHub!</a>
</div>
</div>
<!--<div class="background" style="background-image: url(static/img/bg_right.jpg)"></div>-->
</body>

64
static/css/style.css Normal file
View File

@ -0,0 +1,64 @@
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 15px;
line-height: 1.5em;
background-position: center top;
margin: 0;
}
.area {
background-color: #FFF;
max-width: 600px;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.text {
padding: 2em;
}
h1, h2 {
text-align: left;
margin-top: 0;
}
p {
text-align: left;
}
/* Set a style for all buttons */
button {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
font-size: 120%;
}
button:hover {
opacity: 0.8;
}
input[type=text], input[type=password] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
.container {
text-align: center;
padding: 4em;
padding-top: 0;
padding-bottom: 0;
float: none;
}
.footer {
padding: 2em;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
static/img/wallpaper.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 MiB

76
static/index.html Normal file
View File

@ -0,0 +1,76 @@
<head>
<title>Ticketfrei</title>
<link rel='stylesheet' href='/static/css/style.css'>
</head>
<body style="background-image: url(static/img/wallpaper.png)">
<div class="area">
<h1><img src="/static/img/ticketfrei_logo.png" alt="Ticketfrei" height="150px" align="center" style="float: none;"></h1>
<form action="../login" method="POST">
<div class="container">
<label><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<span style="float:left;">
<input type="checkbox" checked="checked"> Remember me
</span>
<span style="float:center">
<button type="submit">Login</button>
<span class="psw" style="float: right;">
Forgot <a href="#">password?</a>
</span>
</span>
</div>
</form>
<div class=text>
<h1>Features</h1>
<p>sum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard
dummy text ever since the 1500s, when an unknown printer
took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries,
but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s
with the release of Letraset sheets containing Lorem
Ipsum passages, and more recently with desktop publishing
software like Aldus PageMaker including versions of Lorem
Ipsum.</p>
<h2>How to get Ticketfrei to my city?</h2>
<p>sum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard
dummy text ever since the 1500s, when an unknown printer
took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries,
but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s
with the release of Letraset sheets containing Lorem
Ipsum passages, and more recently with desktop publishing
software like Aldus PageMaker including versions of Lorem
Ipsum.</p>
<a href="static/register.html"><button>Register</button></a>
<h2>Our Mission</h2>
<p>Contrary to popular belief, Lorem Ipsum is not simply random
text. It has roots in a piece of classical Latin literature
from 45 BC, making it over 2000 years old. Richard
McClintock, a Latin professor at Hampden-Sydney College in
Virginia, looked up one of the more obscure Latin words,
consectetur, from a Lorem Ipsum passage, and going through
the cites of the word in classical literature, discovered
the undoubtable source. Lorem Ipsum comes from sections
1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum"
(The Extremes of Good and Evil) by Cicero, written in 45
BC. This book is a treatise on the theory of ethics, very
popular during the Renaissance. The first line of Lorem
Ipsum, "Lorem ipsum dolor sit amet..", comes from a line
in section 1.10.32.</p>
</div>
<div class=footer>
Contribute on <a href="https://github.com/b3yond/ticketfrei">GitHub!</a>
</div>
</div>
</body>

31
static/register.html Normal file
View File

@ -0,0 +1,31 @@
<head>
<title>Ticketfrei</title>
<link rel='stylesheet' href='css/style.css'>
</head>
<body style="background-image: url(img/wallpaper.png)">
<div class="area">
<h1><img src="img/ticketfrei_logo.png" alt="Ticketfrei" height="150px" align="center" style="float: none;"></h1>
<form action="../register" method="post">
<div class="container">
<label><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" required>
<label><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<label><b>Repeat Password</b></label>
<input type="password" placeholder="Repeat Password" name="psw-repeat" required>
<p>By creating an account you agree to our <a href="#">Terms & Privacy</a>.</p>
<div class="clearfix">
<button type="submit" class="signupbtn">Sign Up</button>
</div>
</div>
</form>
<div class=footer>
Contribute on <a href="https://github.com/b3yond/ticketfrei">GitHub!</a>
</div>
</div>
</body>