login and register
This commit is contained in:
parent
c97e3e8d4e
commit
88a00e3a4b
16 changed files with 243 additions and 12 deletions
|
|
@ -1 +1,2 @@
|
|||
# Pilzno
|
||||
Building out the pilzno crm
|
||||
BIN
app/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
app/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/__pycache__/config.cpython-310.pyc
Normal file
BIN
app/__pycache__/config.cpython-310.pyc
Normal file
Binary file not shown.
|
|
@ -4,7 +4,8 @@ import json
|
|||
# with open('/etc/config.json') as config_file:
|
||||
# config = json.load(config_file)
|
||||
config = {
|
||||
'SQLALCHEMY_DATABASE_URI_SQLITE': 'sqlite:///site.db'
|
||||
'SQLALCHEMY_DATABASE_URI_SQLITE': 'sqlite:///site.db',
|
||||
'SECRET_KEY': '1234567890'
|
||||
}
|
||||
|
||||
class Config():
|
||||
|
|
|
|||
BIN
app/main/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
app/main/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/main/__pycache__/routes.cpython-310.pyc
Normal file
BIN
app/main/__pycache__/routes.cpython-310.pyc
Normal file
Binary file not shown.
|
|
@ -12,17 +12,18 @@
|
|||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<a href="{{url_for('main.homepage')}}" style="text-decoration: none; margin-right: 10px;"></a>
|
||||
<a href="#" style="text-decoration: none;"><span class="navbar-brand">User Page</span></a>
|
||||
<a href="{{url_for('main.homepage')}}" style="text-decoration: none; margin-right: 10px;"><p>Pilzno</p></a>
|
||||
{% if current_user.is_authenticated %}
|
||||
<a href="{{url_for('users.user_page', user_id=current_user.id)}}" style="text-decoration: none;"><span class="navbar-brand">User Page</span></a>
|
||||
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
|
||||
<div class="navbar-nav">
|
||||
<a class="nav-item nav-link active" href="#">Logout</a>
|
||||
<a class="nav-item nav-link active" href="{{url_for('users.logout')}}">Logout</a>
|
||||
</div>
|
||||
<!-- <div class="navbar-nav ms-auto" id="navbar-user-details">
|
||||
<p>Account Name: {{current_user.first_name}} {{current_user.last_name}}</p>
|
||||
<p>User Type: {{current_user.user_type}}</p>
|
||||
</div> -->
|
||||
</div>
|
||||
{% else %}
|
||||
<a href="{{url_for('users.login')}}" style="text-decoration: none;"><span class="navbar-brand">Login</span></a>
|
||||
<a href="{{url_for('users.register_user')}}" style="text-decoration: none;"><span class="navbar-brand">Register</span></a>
|
||||
{% endif %}
|
||||
</nav>
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
|
|
|
|||
BIN
app/users/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
app/users/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/users/__pycache__/forms.cpython-310.pyc
Normal file
BIN
app/users/__pycache__/forms.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/users/__pycache__/models.cpython-310.pyc
Normal file
BIN
app/users/__pycache__/models.cpython-310.pyc
Normal file
Binary file not shown.
BIN
app/users/__pycache__/routes.cpython-310.pyc
Normal file
BIN
app/users/__pycache__/routes.cpython-310.pyc
Normal file
Binary file not shown.
|
|
@ -0,0 +1,28 @@
|
|||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, \
|
||||
EmailField, \
|
||||
PasswordField, \
|
||||
SubmitField, \
|
||||
SelectField, \
|
||||
BooleanField,\
|
||||
DateField
|
||||
from flask_wtf.file import FileField, FileRequired, FileAllowed
|
||||
from wtforms.validators import DataRequired, ValidationError, NumberRange, EqualTo, Email
|
||||
from app.users.models import User
|
||||
from flask_login import current_user
|
||||
# import logging
|
||||
# logging.basicConfig(filename='logs.log', encoding='utf-8', level=logging.DEBUG)
|
||||
|
||||
class LoginForm(FlaskForm):
|
||||
email = EmailField('Email', validators=[DataRequired()])
|
||||
password = PasswordField('Password', validators=[DataRequired()])
|
||||
remember = BooleanField('Remember me')
|
||||
submit = SubmitField('Login')
|
||||
|
||||
class RegisterUserForm(FlaskForm):
|
||||
email = StringField('Email', validators=[DataRequired(), Email()])
|
||||
first_name = StringField('First Name', validators=[DataRequired()])
|
||||
last_name = StringField('Last Name', validators=[DataRequired()])
|
||||
password = StringField('Password', validators=[DataRequired()])
|
||||
confirm_password = StringField('Confirm Password', validators=[DataRequired(), EqualTo('password', message='Passwords must match')])
|
||||
submit = SubmitField('Register')
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
from app import db
|
||||
from app.users import users
|
||||
from app.users.models import User
|
||||
# from forms import LoginForm, RequestResetForm, ResetPasswordForm, EditUserForm, AddUserForm
|
||||
from app.users.forms import LoginForm, RegisterUserForm#, RequestResetForm, ResetPasswordForm, EditUserForm, AddUserForm
|
||||
from flask import render_template, redirect, url_for, flash, request
|
||||
from flask_login import login_required, login_user, current_user, logout_user
|
||||
from werkzeug.security import check_password_hash, generate_password_hash
|
||||
|
|
@ -13,6 +13,52 @@ import os
|
|||
|
||||
@users.route('/user_page/<user_id>')
|
||||
@login_required
|
||||
def user_page(user_id):
|
||||
|
||||
return render_template('user_page.html')
|
||||
def user_page(user_id):
|
||||
if not int(current_user.id) == int(user_id):
|
||||
return redirect(url_for('main.dashboard'))
|
||||
user = User.query.filter_by(id=user_id).first()
|
||||
return render_template('user_page.html',
|
||||
user=user)
|
||||
|
||||
|
||||
@users.route('/')
|
||||
@users.route('/login', methods=('GET', 'POST'))
|
||||
def login():
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for('main.dashboard'))
|
||||
form = LoginForm()
|
||||
if form.validate_on_submit():
|
||||
user = User.query.filter_by(email=form.email.data).first()
|
||||
if not user or not check_password_hash(user.password, form.password.data):
|
||||
flash('Please check your login details and try again.', 'bad')
|
||||
return redirect(url_for('users.login'))
|
||||
login_user(user, remember=form.remember.data)
|
||||
flash("You've been logged in successfully!", 'good')
|
||||
next_page = request.args.get('next')
|
||||
return redirect(next_page) if next_page else redirect(url_for('main.homepage'))
|
||||
return render_template('login.html',
|
||||
form=form)
|
||||
|
||||
@users.route('/logout')
|
||||
@login_required
|
||||
def logout():
|
||||
logout_user()
|
||||
flash('You\'ve been successfully logged out!')
|
||||
return redirect(url_for('main.homepage'))
|
||||
|
||||
@users.route('/register_user', methods=('GET', 'POST'))
|
||||
def register_user():
|
||||
form = RegisterUserForm()
|
||||
if form.validate_on_submit():
|
||||
user = User(
|
||||
first_name=form.first_name.data,
|
||||
last_name=form.last_name.data,
|
||||
email=form.email.data,
|
||||
password=generate_password_hash(form.password.data),
|
||||
user_type="User",
|
||||
)
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
flash('Succesfully Registered!')
|
||||
return redirect(url_for('main.homepage'))
|
||||
return render_template('register_user.html', form=form)
|
||||
35
app/users/templates/login.html
Normal file
35
app/users/templates/login.html
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block title %}Login{% endblock title %}
|
||||
{% block content %}
|
||||
<main class="container-lg mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h3 class="card-title">Login User</h3>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{{ form.hidden_tag() }}
|
||||
|
||||
<div class="mb-3">
|
||||
{{ form.email.label(class="form-label") }}
|
||||
{{ form.email(class="form-control") }}
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
{{ form.password.label(class="form-label") }}
|
||||
{{ form.password(class="form-control") }}
|
||||
</div>
|
||||
|
||||
<div class="mb-3 form-check">
|
||||
{{ form.remember(class="form-check-input") }}
|
||||
<label class="form-check-label" for="remember">Remember me</label>
|
||||
</div>
|
||||
|
||||
{{ form.submit(class='btn btn-primary') }}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
{% endblock %}
|
||||
81
app/users/templates/register_user.html
Normal file
81
app/users/templates/register_user.html
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block title %}User Access{% endblock title %}
|
||||
{% block content %}
|
||||
<main class="container-lg mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h3 class="card-title">Register</h3>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{{ form.hidden_tag() }}
|
||||
|
||||
<div class="mb-3">
|
||||
{{ form.first_name.label(class="form-label") }}
|
||||
{{ form.first_name(class="form-control") }}
|
||||
{% if form.first_name.errors %}
|
||||
<ul class="errors">
|
||||
{% for error in form.first_name.errors %}
|
||||
<li>{{ error }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
{{ form.last_name.label(class="form-label") }}
|
||||
{{ form.last_name(class="form-control") }}
|
||||
{% if form.last_name.errors %}
|
||||
<ul class="errors">
|
||||
{% for error in form.last_name.errors %}
|
||||
<li>{{ error }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
{{ form.email.label(class="form-label") }}
|
||||
{{ form.email(class="form-control") }}
|
||||
{% if form.email.errors %}
|
||||
<ul class="errors">
|
||||
{% for error in form.email.errors %}
|
||||
<li>{{ error }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
{{ form.password.label(class="form-label") }}
|
||||
{{ form.password(class="form-control") }}
|
||||
{% if form.password.errors %}
|
||||
<ul class="errors">
|
||||
{% for error in form.password.errors %}
|
||||
<li>{{ error }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
{{ form.confirm_password.label(class="form-label") }}
|
||||
{{ form.confirm_password(class="form-control") }}
|
||||
{% if form.confirm_password.errors %}
|
||||
<ul class="errors">
|
||||
{% for error in form.confirm_password.errors %}
|
||||
<li>{{ error }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
{{ form.submit(class='btn btn-primary') }}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
{% endblock %}
|
||||
38
app/users/templates/user_page.html
Normal file
38
app/users/templates/user_page.html
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block title %}User Page{% endblock title %}
|
||||
{% block content %}
|
||||
<main class="container">
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-6 offset-md-3">
|
||||
<h1>Welcome, {{ user.first_name }} {{ user.last_name }}</h1>
|
||||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-10 offset-md-1">
|
||||
{% if user_reports %}
|
||||
<h2>Downloadable Files:</h2>
|
||||
<table class="table mt-3">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Report Type</th>
|
||||
<th>Number of Rows</th>
|
||||
<th>Time Created</th>
|
||||
<th>Range Start</th>
|
||||
<th>Range End</th>
|
||||
<th>Download</th>
|
||||
<th>Delete</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p>No reports available.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue