diff --git a/backend/main.py b/backend/main.py new file mode 100644 index 0000000..f4fa3a5 --- /dev/null +++ b/backend/main.py @@ -0,0 +1,108 @@ +import pyrebase +from flask import Flask, flash, redirect, render_template, request, session, abort, url_for + + +app = Flask(__name__) + +config = { + "apiKey": "", + "authDomain": "", + "databaseURL": "", + "storageBucket": "", + "projectId": "", + "messagingSenderId": "", + "appId": "", + "measurementId": "" +} + +firebase = pyrebase.initialize_app(config) +auth = firebase.auth() +db = firebase.database() + + +person = {"is_logged_in": False, "name": "", "email": "", "uid": ""} + + +#----------Home page +@app.route("/") +@app.route("/home") +def home(): + return render_template("home.html") + + +#----------Login +@app.route("/login", methods = ["POST", "GET"]) +def login(): + if request.method == "POST": + result = request.form + email = result["email"] + password = result["pass"] + try: + user = auth.sign_in_with_email_and_password(email, password) + global person + person["is_logged_in"] = True + person["email"] = user["email"] + person["uid"] = user["localId"] + + data = db.child("users").get() + person["name"] = data.val()[person["uid"]]["name"] + + flash(f'You have been logged in.', 'success') + return redirect(url_for('home')) + except: + flash(f'Login unsuccessful.', 'danger') + return redirect(url_for('login')) + else: + if person["is_logged_in"] == True: + flash(f'You have been logged in.', 'success') + return redirect(url_for('home')) + else: + flash(f'Login unsuccessful.', 'danger') + return redirect(url_for('login')) + + return render_template("login.html") + +#Sign up/ Register +@app.route("/signup", methods = ["POST", "GET"]) +def signup(): + if request.method == "POST": + result = request.form + email = result["email"] + password = result["pass"] + confirmpassword = result["confirmpass"] + name = result["name"] + try: + if person["pass"] == person["confirmpass"] + auth.create_user_with_email_and_password(email, password) + + user = auth.sign_in_with_email_and_password(email, password) + + global person + person["is_logged_in"] = True + person["email"] = user["email"] + person["uid"] = user["localId"] + person["name"] = name + + data = {"name": name, "email": email} + db.child("users").child(person["uid"]).set(data) + + flash(f'Acccount successfully created!', 'success') + return redirect(url_for('home')) + except: + + return redirect(url_for('signup')) + + + else: + if person["is_logged_in"] == True: + flash(f'You have been logged in.', 'success') + return redirect(url_for('home')) + else: + return redirect(url_for('signup')) + + return render_template("signup.html") + + +if __name__ == "__main__": + app.run() + diff --git a/backend/static/signupstyle.css b/backend/static/signupstyle.css new file mode 100644 index 0000000..a174cc7 --- /dev/null +++ b/backend/static/signupstyle.css @@ -0,0 +1,61 @@ + body{ + margin: 0; + padding:0; + background: #fab1a0; + } + .signup form{ + width: 350px; + padding:40px; + text-align:center; + + position:absolute; + top:50%; + left:50%; + transform:translate(-50%,-50%); + overflow:hidden; + } + .signup form h1{ + margin-top:150px; + font-family: 'Permanent Marker' , cursive; + color: #fff; + font-size:40px; + } + .signup form input{ + display:block; + width:100%; + padding: 0 16px; + height: 44px; + text-align:center; + box-sizing:border-box; + outline:none; + border:none; + } + .text{ + margin:20px 0; + background:rgba(255,255,255,.5); + border-radius:6px; + } + .signup-btn{ + margin-top: 60px; + margin-bottom: 20px; + background: #e17055; + color:#fff; + border-radius:60px; + cursor:pointer; + transition:0.8s; + } + .signup-btn:hover{ + transform:scale(0.96); + } + .signup form a{ + text-decoration:none; + color:#fff; + font-family:"montserrat" ,sans-serif; + font-size:14px; + padding:10px; + transition: 0.8s; + display: block; + } + .signup form a:hover{ + background:rgba(0,0,0,.3); + } \ No newline at end of file diff --git a/backend/static/styles.css b/backend/static/styles.css new file mode 100644 index 0000000..c95542d --- /dev/null +++ b/backend/static/styles.css @@ -0,0 +1,83 @@ +body{ + margin: 0; + padding: 0; + background-size: cover; +} +.login-form{ + width: 300px; + padding: 20px; + text-align: center; + background-color:whitesmoke; + background-size: cover ; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + overflow:hidden; + box-shadow: 0 5px 15px #193047; +} +.login-form h1{ + margin-top: 100px; + font-family: 'Fondamento', cursive; + color: rgb(8, 8, 8); + font-size: 40px; +} +.login-form input{ + display: block; + width: 100%; + padding: o 16px; + height: 50px; + text-align: center; + box-sizing: border-box; + outline: none; + border: none; + font-family: 'Fondamento', cursive; +} +.txtb{ + margin: 20px 0; + background: rgba(255,255,255,.5); + border-radius: 6px; + background-color:white; + box-shadow: 0 5px 15px #517599; + font-weight: bold; +} +.login-btn{ + margin-top: 60px; + margin-bottom: 20px; + background:black; + color:white; + border-radius: 44px; + cursor: pointer; + transition: 0.8s; + box-shadow: 0 5px 15px #517599; + position: relative; + border: none; + font-size: 20px; + padding-top: 10px; + padding-bottom: 10px; + width: 200px; + text-align: center; + -webkit-transition-duration: 0.4s; + transition-duration: 0.4s; + text-decoration: none; + overflow: hidden; +} + +.login-btn:hover{ + transform: scale(0.96); +} +.login-form a{ + text-decoration: none; + color: #0a0a0a; + font-size: 14px; + font-family: 'Fondamento', cursive; + padding: 10 px; + transition: 0.8s; + display: block; +} +.login-form a:hover{ + background: rgba(0,0,0,.3); +} +p{ + font-size: larger; +} diff --git a/backend/templates/login.html b/backend/templates/login.html new file mode 100644 index 0000000..fa5fcf3 --- /dev/null +++ b/backend/templates/login.html @@ -0,0 +1,38 @@ + + + + + + + LOGIN + + + +
+ {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + {% for category, message in messages %} +
+ {{ message }} +
+ {% endfor %} + {% endif %} + {% endwith %} + {% block content %} + +
+
+

LOGIN

+ + +

password?

+ + New User? +
+
+ + {% endblock %} +
+ + + \ No newline at end of file diff --git a/backend/templates/signup.html b/backend/templates/signup.html new file mode 100644 index 0000000..676aa6c --- /dev/null +++ b/backend/templates/signup.html @@ -0,0 +1,68 @@ + + + +sign + + + + + + + + + + + + + +
+ {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + {% for category, message in messages %} +
+ {{ message }} +
+ {% endfor %} + {% endif %} + {% endwith %} + {% block content %} + +
+
+ +
+
+ + {% endblock %} +
+