-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
128 lines (75 loc) · 2.91 KB
/
app.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from flask import Flask, render_template, redirect, url_for
from wtforms import StringField, SubmitField, PasswordField
from wtforms.validators import InputRequired, Length
from flask_wtf import FlaskForm
from flask_bootstrap import Bootstrap
from flask_sqlalchemy import SQLAlchemy
import os
from datetime import datetime
from flask_migrate import Migrate
import smtplib
from email.message import EmailMessage
from send import send_sys
app = Flask(__name__)
Bootstrap(app)
SECRET_KEY = os.urandom(32)
app.config.from_object(os.environ['APP_SETTINGS'])
app.config['SECRET_KEY'] = SECRET_KEY
db = SQLAlchemy(app)
class User(db.Model):
__tablename__= 'SYSTEM'
id=db.Column( db.Integer, primary_key = True)
vorname = db.Column( db.String())
nachname = db.Column(db.String())
email = db.Column(db.String())
password = db.Column(db.String())
create_data = db.Column(db.DateTime, default=datetime.utcnow)
def __init__(self, vorname, nachname, email, password):
self.vorname = vorname
self.nachname = nachname
self.email = email
self.password = password
class Regester(FlaskForm):
vorname = StringField('Vorname', validators=[InputRequired(), Length(max=10)])
nachname = StringField('Nachname', validators=[InputRequired(), Length(max=10)])
email = StringField('Email', validators=[InputRequired(), Length(max=200)])
password = PasswordField('Password', validators=[InputRequired(), Length(max=200)])
class Login(FlaskForm):
email = StringField('Email', validators=[InputRequired(), Length(max=200)])
password = PasswordField('Password', validators=[InputRequired(), Length(max=200)])
submit = SubmitField('Regester')
migrate = Migrate(app, db)
db.create_all()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/dashboard', methods=['POST', 'GET'])
def office():
return render_template('office.html')
@app.route('/log', methods=['POST', 'GET'])
def user():
form = Login()
if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
password = User.query.filter_by(password=form.password.data).first()
if user:
if password:
return redirect(url_for('office'))
else:
return '<h1> The user is not exested<h1>'
return render_template('log.html', form=form)
@app.route('/regester', methods=['POST', 'GET'])
def regist():
form = Regester()
if form.validate_on_submit():
user = User(
vorname = form.vorname.data,
nachname = form.nachname.data,
email= form.email.data,
password = form.password.data
)
db.session.add(user)
db.session.commit()
send_sys(form.vorname.data, form.email.data)
return redirect(url_for('user'))
return render_template('regester.html', form=form)