Skip to content

Commit

Permalink
Merge pull request #2 from jcharistech/develop
Browse files Browse the repository at this point in the history
Update Login with Base
  • Loading branch information
Jcharis authored Jul 11, 2022
2 parents 60b2343 + 00d4932 commit 91a472d
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 47 deletions.
11 changes: 9 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@ def create_app():
def load_user(user_id):
# using the user id as primary key as id for session
return User.query.get(int(user_id))


@login_required
@app.route("/")
def index():
passwordlist = PasswordManager.query.all()
return render_template('index.html', passwordlist=passwordlist)

@app.route("/Home")
def home_page():
passwordlist = PasswordManager.query.all()
return render_template('home.html', passwordlist=passwordlist)

@login_required
@app.route("/add",methods=["GET","POST"])
def add_password():
if request.method == 'POST':
Expand All @@ -41,7 +48,7 @@ def add_password():
flash("Password Added")
return redirect('/')


@login_required
@app.route('/delete/<int:id>')
def delete(id):
new_password_to_delete = PasswordManager.query.get_or_404(id)
Expand Down
16 changes: 12 additions & 4 deletions auth.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from flask import Blueprint,render_template,url_for,redirect,request
from flask import Blueprint,render_template,url_for,redirect,request,flash
from .models import User
from .extensions import db

# Essentials For Login Creation
from werkzeug.security import generate_password_hash,check_password_hash
from flask_login import login_user
from flask_login import login_user, login_required, logout_user

auth = Blueprint("auth",__name__)

Expand All @@ -15,10 +17,12 @@ def login():
@auth.route("/login",methods=["POST"])
def login_post():
if request.method == "POST":
# Get values from Form
email = request.form.get("email")
name = request.form.get("name")
password = request.form.get("password")
remember = request.form.get("remember")

# if it returns a user then email already exist and user exist hence check for password
user = User.query.filter_by(email=email).first()

Expand All @@ -37,9 +41,11 @@ def signup():

@auth.route("/signup",methods=["POST"])
def signup_post():
# Get values from form
email = request.form.get("email")
name = request.form.get("name")
password = request.form.get("password")

# if it returns a user then email already exist hence redirect
user = User.query.filter_by(email=email).first()
if user:
Expand All @@ -56,9 +62,11 @@ def signup_post():
return redirect(url_for("auth.login"))


@auth.route("/logout")
@auth.route('/logout')
@login_required
def logout():
return "Login"
logout_user()
return redirect(url_for('home_page'))



Expand Down
Binary file modified data2.db
Binary file not shown.
54 changes: 54 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Password Master</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
</head>

<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="{{url_for('home_page')}}">Password Manager</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav">
{% if not current_user.is_authenticated %}
<li class="nav-item active">
<a class="nav-link" href="{{url_for('home_page')}}">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{url_for('auth.login')}}">Login</a>
</li>

<li class="nav-item">
<a class="nav-link" href="{{url_for('auth.signup')}}">SignUp</a>
</li>
{% endif %}

{% if current_user.is_authenticated %}
<li class="nav-item active">
<a class="nav-link" href="{{url_for('index')}}">Manager</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{url_for('auth.logout')}}">Logout</a>
</li>
{% endif %}
</ul>
</div>
</nav>

<div class="container">
{% block content %}
{% endblock %}
</div>


<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>

</body>

</html>
33 changes: 33 additions & 0 deletions templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% extends "base.html" %}

{% block content %}
<div>
<h3 class="display-3 text-center my-3">Password Manager</h3>
</div>

<div class="container">
<!-- RESPONSIVE CLASSES -->
<div class="row">
<!-- stacks the columns on small screen sizes -->
<div class="col-md-6">
<h3></h3>
<p></p>
</div>
<!--FORMS HERE-->
<div class="col-md-4">
<ul>
<li>
<a class="" href="{{url_for('auth.login')}}">Login</a>
</li>

<li>
<a class="" href="{{url_for('auth.signup')}}">SignUp</a>
</li>
</ul>


</div>

</div>

{% endblock %}
18 changes: 3 additions & 15 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Password Master</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
{% extends "base.html" %}

</head>

<body>
{% block content %}
<div>
<h3 class="display-3 text-center my-3">Password Manager</h3>
</div>
Expand Down Expand Up @@ -97,7 +88,4 @@ <h3>Password Register</h3>
}
}
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>

</body>
</html>
{% endblock %}
35 changes: 17 additions & 18 deletions templates/login.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Password Manager</title>
</head>
<body>
{% extends "base.html" %}

{% block content %}

<div class="container">
<!-- RESPONSIVE CLASSES -->
<div class="row">
Expand All @@ -14,13 +10,17 @@
<h3></h3>
<p></p>
</div>
<!--FOR FLASH MESSAGES-->
{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="notification is-danger">
{{ messages[0] }}
</div>
{% endif %}
{% endwith %}
{% if messages %}
<div class="notification is-danger">
{{ messages[0] }}
</div>
{% endif %}
{% endwith %}

<!--FOR FLASH MESSAGES-->

<!--FORMS HERE-->
<div class="col-md-4">
<h3>Login</h3>
Expand All @@ -40,16 +40,15 @@ <h3>Login</h3>
</div>
<label for="profile_remember">Remember</label>
<div class="input-group">
<input type="checkbox" class="form-control" name="remember" id="profile-password" value="True">
<input type="checkbox" name="remember" id="profile-password" value="True">
</div>
<br>
<button type="submit" class="btn btn-primary mb-3">Sign Up</button>
<button type="submit" class="btn btn-primary mb-3">Login</button>
</form>
<!--FORMS HERE-->

</div>

</div>

</body>
</html>
{% endblock %}
103 changes: 103 additions & 0 deletions templates/old_files/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Password Master</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">

</head>

<body>
<div>
<h3 class="display-3 text-center my-3">Password Manager</h3>
</div>

<div class="container">
<!-- RESPONSIVE CLASSES -->
<div class="row">
<!-- stacks the columns on small screen sizes -->
<div class="col-md-6">
<h3></h3>
<p></p>
</div>
<!--FORMS HERE-->
<div class="col-md-4">
<h3>Password Register</h3>
<!--FORMS HERE-->
<form method="POST" action="/add">
<label for="profile-url">Email</label>
<div class="input-group">
<input type="email" class="form-control" name="email" placeholder="Email">
</div>
<label for="profile-url">Site URL</label>
<div class="input-group">
<input type="text" class="form-control" name="site_url" placeholder="Site URL">
</div>
<label for="site_password">Password</label>
<div class="input-group">
<input type="password" class="form-control" name="site_password" id="profile-url">
</div>
<br>
<button type="submit" class="btn btn-primary mb-3">Add Password</button>
</form>
<!--FORMS HERE-->

</div>

</div>



<div class="container">
<table class="table">
<!-- gives only the heading a black background -->
<thead class="thead-inverse">
<tr>
<th>Email</th>
<th>Site Address</th>
<th>Site Password</th>
<th>Actions</th>
<th>Visibility</th>

</tr>
</thead>
<tbody>
{% for task in passwordlist %}
<tr>
<td>{{ task.email }}</td>
<td>{{ task.site_url }}</td>
<td><input type="password" value="{{ task.site_password }}" id="{{ task.id}}"></td>
<td>
<a class="btn btn-outline-danger btn-sm" role="button" href="/delete/{{task.id}}">Delete</a>
<br>
<a class="btn btn-outline-success btn-sm" role="button" href="/update/{{task.id}}">Update</a>
</td>
<td>
<input type="checkbox" onclick="myFunction({{ task.id}})">Show Password
</td>
</tr>
</tbody>
{% endfor %}
</table>
</div>
<div class="container">
<a href="{{url_for('export_data')}}" type="button" class="btn btn-primary mb-3">Export as CSV</a>
</div>
</div>

<script>
function myFunction(pid) {
var x = document.getElementById(pid);
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>

</body>
</html>
Loading

0 comments on commit 91a472d

Please sign in to comment.