-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
111 lines (95 loc) · 3.79 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
from flask import Flask, render_template, request, redirect, url_for, flash
from flask import session as login_session
import pyrebase
config = {
'apiKey': "AIzaSyC8obPXaGjAEb2L9z3SQlsl0ayJLGcB8do",
'authDomain': "nefashot-5fc6a.firebaseapp.com",
'projectId': "nefashot-5fc6a",
'storageBucket': "nefashot-5fc6a.appspot.com",
'messagingSenderId': "509898866148",
'appId': "1:509898866148:web:eed68f5761886822269bf1",
'measurementId': "G-ZZ8X71R5J8",
'databaseURL': 'https://nefashot-5fc6a-default-rtdb.europe-west1.firebasedatabase.app/'}
firebase = pyrebase.initialize_app(config)
auth = firebase.auth()
db = firebase.database()
app = Flask(__name__, template_folder='templates', static_folder='static')
app.config['SECRET_KEY'] = 'super-secret-key'
#Code goes below here
@app.route('/')
def index():
return render_template("index.html")
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/contact', methods = ['POST','GET'])
def contact():
if request.method == "POST":
phone = request.form['phone']
email = request.form['email']
message = request.form['message']
try:
UID = login_session['user']['localId']
messages = {'phone': phone , 'email': email, 'message': message}
db.child("Users").child(UID).child("Messages").push(messages)
return redirect(url_for('index'))
except:
return render_template('contact.html')
return render_template('contact.html')
#Code goes above here
@app.route('/sign_in', methods = ['POST','GET'])
def sign_in():
erorr = ""
if request.method == "POST":
password = request.form['password']
email = request.form['email']
try:
login_session['user'] = auth.sign_in_with_email_and_password(email, password)
UID = login_session['user']['localId']
user = {'password':password, 'email':email}
db.child("Users").child(UID).set(user)
return redirect(url_for('index'))
except:
error = "Authentication failed "
return render_template("signin.html")
@app.route('/sign_up', methods = ['POST','GET'])
def sign_up():
erorr = ""
if request.method == "POST":
email = request.form['email']
password = request.form['password']
name = request.form['name']
try:
login_session['user'] = auth.create_user_with_email_and_password(email, password)
UID = login_session['user']['localId']
user = {'name':name, 'name': name, 'email':email}
db.child("Users").child(UID).set(user)
return redirect(url_for('index'))
except:
error = "Authentication failed "
return render_template("signup.html")
@app.route('/post', methods = ['GET', 'POST'])
def post():
UID = login_session['user']['localId']
post = db.child("Users").get().val()
return render_template('post.html', post = post)
@app.route('/discuss', methods = ['GET', "POST"])
def discuss():
if request.method == 'POST':
try:
name = request.form['name']
upload = request.form['upload']
about = request.form['about']
contact = request.form['contact']
UID = login_session['user']['localId']
post = {'name':name, 'upload': upload, 'about': about, 'contact': contact}
db.child("Users").child(UID).child("posts").push(post)
return redirect(url_for('post'))
except:
return render_template('discuss.html')
return render_template('discuss.html')
@app.route('/events')
def events():
return render_template('events.html')
if __name__ == '__main__':
app.run(debug=True)