-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
141 lines (122 loc) · 4.43 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from flask import Flask, render_template, request, redirect, session, url_for
import firebase_admin
from firebase_admin import db,auth
from firebase_admin import credentials
import pyrebase
import json
import uuid
app = Flask(__name__)
app.secret_key = "kjdsd32423r3r@#@#@(!jbdsfwef)"
firebaseConfig = json.load(open('/Users/ripunjaysingh/learn/GOOGLE_SOLUTIONS/cred.json'))
firebass = pyrebase.initialize_app(firebaseConfig)
sb = firebass.database()
username=None
cred = credentials.Certificate("/Users/ripunjaysingh/learn/GOOGLE_SOLUTIONS/cred.json")
firebase=firebase_admin.initialize_app(cred,{
'databaseURL': 'https://urbanworkers-21f47-default-rtdb.firebaseio.com/'
})
pb = pyrebase.initialize_app(json.load(open('/Users/ripunjaysingh/learn/GOOGLE_SOLUTIONS/cred.json')))
user_id = None
@app.route('/', methods=['GET', 'POST'])
def home():
return render_template("index.html")
@app.route('/register', methods=['GET', 'POST'])
def register():
return render_template('registrationform.html')
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
email = request.form['email']
password = request.form['password']
global username
username=email.split('@')[0]
print(email,password)
try:
user = firebass.auth().sign_in_with_email_and_password(email, password)
session['user'] = user
print("success")
jwt = user['idToken']
global user_id
user_id = user['localId']
print(user_id)
user_type = sb.child("users").child(username).get().val()['user_type']
print(user_type)
if user_type.lower() == 'get-hired':
return redirect(url_for('worker_interface'))
elif user_type.lower() == 'hire':
return redirect(url_for('index'))
except Exception as e:
return f"{e}"
return render_template("index.html")
@app.route('/submit', methods=['GET', 'POST'])
def submit():
if request.method == 'POST':
name=request.form.get("name")
email=request.form.get("email")
phone_no=request.form.get("phone")
address=request.form.get("address")
password=request.form.get("password")
dob=request.form.get("dob")
adhar=request.form.get("adhar")
select_option = request.form['selectOption']
username=email.split('@')[0]
id=str(uuid.uuid4())
user=auth.create_user(
email=email,
password=password
)
sb.child('users').child(username).set({
'name': name,
'email': email,
'phone_no': phone_no,
'address': address,
'password': password,
'dob': dob,
'adhar': adhar,
'user_type': select_option
})
return render_template('submit.html')
@app.route('/worker_interface', methods=['GET', 'POST'])
def worker_interface():
rows = [
{
"work_type": "Web Development",
"amount": "$1000",
"start_date": "April 15, 2023",
"working_hours": "9am-5pm",
"email": "[email protected]",
"phone": "123-456-780"
},
{
"work_type": "Graphic Design",
"amount": "$500",
"start_date": "May 1, 2023",
"working_hours": "10am-2pm",
"email": "[email protected]",
"phone": "555-555-5555"
}
]
return render_template("workers.html", rows=rows)
@app.route('/hirer_interface', methods=['GET', 'POST'])
def hirer_interface():
if request.method == 'POST':
work_type = request.form['work_type']
amount = request.form['amount']
start_date = request.form['start_date']
working_hours = request.form['working_hours']
email = request.form['email']
phone = request.form['phone']
sb.child('users').child(username).child('jobs_posted').child(work_type).set({
'work_type': work_type,
'amount': amount,
'start_date': start_date,
'working_hours': working_hours,
'email': email,
'phone': phone
})
return render_template('jobs_form.html')
@app.route('/hire', methods=['GET', 'POST'])
def index():
return render_template('hirer.html')
if __name__ == '__main__':
app.run(debug=True)