-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWelcome.py
47 lines (41 loc) · 1.7 KB
/
Welcome.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import flask
import os
import shutil
import logging
import smtplib
import threading
import subprocess
import werkzeug
from flask.ext.restful import reqparse, MethodView
from mail_handler import *
stuff = {'user':'password'}
class Welcome(MethodView):
def get(self):
return flask.render_template('welcome.html')
def post(self):
if 'logout' in flask.request.form:
logging.info('User requested to log out.')
flask.session.pop('username', None)
return flask.redirect(flask.url_for('welcome'))
logging.info('User requested to log in.')
required = ['usuario', 'clave']
for i in required:
if i not in flask.request.form:
flask.flash("Error: {0} is a required field.".format(i))
logging.info('User did not send complete login data.')
return flask.redirect(flask.url_for('welcome'))
logging.info('User sent everything.')
parser = reqparse.RequestParser()
parser.add_argument('usuario',type=str)
parser.add_argument('clave',type=str)
args = parser.parse_args()
self.user = args['usuario']
self.passw = args['clave']
if self.user in stuff and stuff[self.user] == self.passw:
logging.info('User ' + self.user + ' is in!')
flask.session['username'] = self.user
else:
logging.info('User tried with incorrect info: username - ' + self.user + ' password - ' + self.passw)
flask.flash(flask.Markup("The username or password you entered is <b>incorrect</b>."))
return flask.redirect(flask.url_for('welcome'))
return flask.render_template('welcome.html')