Skip to content

Commit

Permalink
Merge pull request #2 from LetsUpgrade/master
Browse files Browse the repository at this point in the history
update from the original
  • Loading branch information
vaishnavityra712 authored Sep 10, 2020
2 parents f2f381c + 3e6d44c commit 8403b34
Show file tree
Hide file tree
Showing 5 changed files with 358 additions and 0 deletions.
108 changes: 108 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
@@ -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()

61 changes: 61 additions & 0 deletions backend/static/signupstyle.css
Original file line number Diff line number Diff line change
@@ -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);
}
83 changes: 83 additions & 0 deletions backend/static/styles.css
Original file line number Diff line number Diff line change
@@ -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;
}
38 changes: 38 additions & 0 deletions backend/templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name= "viewport" content= "initial-scale=1, maximum-scale=1, user-scalable= no">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>LOGIN</title>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
<div class="container col-12">
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }}">
{{ message }}
</div>
{% endfor %}
{% endif %}
{% endwith %}
{% block content %}

<div class= "login-form">
<form class= "" method= "post">
<h1>LOGIN</h1>
<input type ="username or email" placeholder="Email or Username" class="txtb" name="email">
<input type ="password" placeholder="Password" class="txtb" name="pass">
<p><a href= "#">password?</a></p>
<input type="submit" value="Login" class="login-btn">
<a href= "http://127.0.0.1:5000/signup">New User? </a>
</form>
</div>

{% endblock %}
</div>

</body>
</html>
68 changes: 68 additions & 0 deletions backend/templates/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html>
<head>
<title>sign</title>
<meta charset="utf-8">
<meta name= "viewport" content= "initial-scale=1, maximum-scale=1, user-scalable= no">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="{{ url_for('static', filename='signupstyle.css') }}">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Raleway:300,400,600,700,800&display=swap" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" rel="stylesheet">


</head>
<body>

<div class="container col-12">
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }}">
{{ message }}
</div>
{% endfor %}
{% endif %}
{% endwith %}
{% block content %}

<div class="container">
<div class="form">
<div class="sign-in-section">
<h1>Sign Up</h1>
<ul>
<li><i class="fab fa-facebook-f"></i></li>
<li><i class="fab fa-linkedin-in"></i></li>
<li><i class="fab fa-twitter"></i></li>
</ul>
<p>or use your email</p>
<form>
<div class="form-field">
<label for="username">Username</label>
<input type="text" placeholder="Username" class="text" name="name"/>
<label for="email">Email</label>
<input id="email" type="email" placeholder="Email" name="email" />
</div>
<div class="form-field">
<label for="password">Password</label>
<input id="password" type="password" placeholder="Password" name="pass" />
<label for="confirm password">Confirm Password</label>
<input id="password" type="password" placeholder="Confirm Password" name="confirmpass" />
</div>

<div class="form-field">
<input type="Create account" class="btn btn-signin" value="Create account" />
</div>
</form>
<div class="links">
<a href="#">Privacy Policy</a>
<a href="#">Terms & Conditions</a>
</div>
</div>
</div>
</div>

{% endblock %}
</div>

0 comments on commit 8403b34

Please sign in to comment.