This repository has been archived by the owner on Feb 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding all files for login management
- Loading branch information
cduhn17
committed
Jan 21, 2022
1 parent
09de10e
commit 15c0272
Showing
29 changed files
with
1,194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
|
||
from pe_reports.data.configOriginal import config1 | ||
import psycopg2 | ||
import psycopg2.extras | ||
from flask_sqlalchemy import SQLAlchemy | ||
from pe_reports import app | ||
from sqlalchemy import create_engine | ||
|
||
# basedir = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
params = config1() | ||
|
||
# conn = psycopg2.connect(**params) | ||
DATABASE_URL = f'postgresql+psycopg2://{params["user"]}:{params["password"]}@{params["host"]}:{params["port"]}/{params["database"]}' | ||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | ||
app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URL | ||
db = SQLAlchemy(app) | ||
engine = create_engine(DATABASE_URL) | ||
try: | ||
|
||
result = engine.execute('select * from organizations') | ||
|
||
for x in result: | ||
print(x) | ||
|
||
except: | ||
print('Something is wrong') | ||
|
||
|
||
|
||
# class Config(object): | ||
# DATABASE_URL = DB_URL = 'postgresql+psycopg2://{user}:{pw}@{url}/{db}' | ||
# SQLALCHEMY_DATABASE_URI = os.environ['DATABASE_URL'] | ||
# DEBUG = True | ||
# CSRF_ENABLED = True | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
#All command in this file are to be run where the app.py file is located. | ||
#Run this first in the same dir as app.py. | ||
#flask db init | ||
|
||
##Modify /migrations/env.py add | ||
|
||
#def include_object(object, name, type_, reflected, compare_to): | ||
# if type_ == "table" and reflected and compare_to is None: | ||
# return False | ||
# else: | ||
# return True | ||
# Change from | ||
#context.configure(connection=connection, | ||
# target_metadata=target_metadata, | ||
# process_revision_directives=process_revision_directives, | ||
# **current_app.extensions['migrate'].configure_args) | ||
# Change to | ||
#context.configure(connection=connection, | ||
# target_metadata=target_metadata, | ||
# process_revision_directives=process_revision_directives, | ||
# include_object=include_object,<-------------Here is the added line | ||
# **current_app.extensions['migrate'].configure_args) | ||
|
||
|
||
|
||
##Run the next two commands only after the /migrations/env.py has been modified/ | ||
#flask db migrate -m "Create users table." | ||
# | ||
#flask db upgrade | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""This file is required to pass testing.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Create all forms related to login system.""" | ||
#Module level imports | ||
from pe_reports.manage_login.models import User | ||
#Third party imports | ||
from flask_wtf import FlaskForm | ||
from wtforms import StringField, PasswordField, SubmitField | ||
from wtforms.validators import DataRequired, Email, EqualTo | ||
from wtforms import ValidationError | ||
|
||
|
||
class LoginForm(FlaskForm): | ||
email = StringField('Email', validators=[DataRequired()]) | ||
password = PasswordField('Password', validators=[DataRequired()]) | ||
submit = SubmitField('Login') | ||
|
||
|
||
class RegistrationForm(FlaskForm): | ||
|
||
email = StringField('Email', validators=[DataRequired(), Email()]) | ||
username = StringField('Username', validators=[DataRequired()]) | ||
password = PasswordField('Password', validators=[DataRequired(), | ||
EqualTo('pass_confirm', | ||
message='Passwords do not match.')]) | ||
pass_confirm = PasswordField('Confirm Password', | ||
validators=[DataRequired()]) | ||
submit = SubmitField('Register') | ||
|
||
def check_email(self, field): | ||
if User.query.filter_by(email=field.data).first(): | ||
raise ValidationError('Your email has been already registered.') | ||
|
||
def check_username(self, field): | ||
if User.query.filter_by(username=field.data).first(): | ||
raise ValidationError('Your username is already taken.') | ||
|
||
class RequestRestForm(FlaskForm): | ||
email = StringField('Email', validators=[DataRequired(), Email()]) | ||
submit = SubmitField('Request Password Reset') | ||
|
||
def validate_email(self, field): | ||
if User.query.filter_by(email=field.data).first() is None: | ||
raise ValidationError('There is no account associated' | ||
' with that email. Please register.') | ||
|
||
class ResetPasswordForm(FlaskForm): | ||
password = PasswordField('Password', validators=[DataRequired(), | ||
EqualTo('pass_confirm', | ||
message='Passwords do not match.')]) | ||
pass_confirm = PasswordField('Confirm Password', | ||
validators=[DataRequired()]) | ||
submit = SubmitField('Reset Password') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from pe_reports import db, login_manager, app | ||
|
||
#Third party packages | ||
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer | ||
from sqlalchemy.dialects.postgresql import UUID | ||
import uuid | ||
from flask_bcrypt import Bcrypt | ||
from flask_login import UserMixin | ||
|
||
|
||
bcrypt = Bcrypt() | ||
|
||
|
||
@login_manager.user_loader | ||
def load_user(user_id): | ||
|
||
return User.query.get(user_id) | ||
|
||
|
||
class User(db.Model, UserMixin): | ||
"""Create User table in db.""" | ||
|
||
__tablename__ = 'Users' | ||
|
||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | ||
email = db.Column(db.String(64), unique=True, index = True) | ||
username = db.Column(db.String(64), unique=True, index=True) | ||
admin = db.Column(db.Integer) | ||
role = db.Column(db.Integer) | ||
password_hash = db.Column(db.String(128)) | ||
api_key = db.Column(db.String(128), unique=True) | ||
|
||
def __init__(self, email, username, password): | ||
|
||
self.email = email | ||
self.username = username | ||
self.admin = 0 | ||
self.role = 0 | ||
self.password_hash = bcrypt.generate_password_hash(password).decode('utf-8') | ||
|
||
def check_password(self, password): | ||
return bcrypt.check_password_hash(self.password_hash, password) | ||
|
||
|
||
|
49 changes: 49 additions & 0 deletions
49
src/pe_reports/manage_login/templates/manage_login/login.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{% extends 'base.html' %} | ||
{% block content %} | ||
|
||
|
||
|
||
|
||
|
||
<section class="vh-100"> | ||
<div class="container-fluid h-custom"> | ||
<div class="row d-flex justify-content-center align-items-center h-100"> | ||
|
||
<div class="col-md-8 col-lg-6 col-xl-4 offset-xl-1"> | ||
<form method="post"> | ||
{{ form.hidden_tag() }} | ||
<!-- Email input --> | ||
<div class="form-outline mb-4"> | ||
{{ form.email(class="form-control form-control-lg", placeholder='Enter a valid email address') }}{{ form.email.label }} | ||
|
||
</div> | ||
|
||
<!-- Password input --> | ||
<div class="form-outline mb-3"> | ||
{{ form.password(class="form-control form-control-lg", placeholder="Enter password") }}{{ form.password.label }} | ||
|
||
</div> | ||
|
||
<div class="d-flex justify-content-between align-items-center"> | ||
<!-- Checkbox --> | ||
|
||
<a href="{{ url_for('manage_login.reset_request') }}" class="text-body">Forgot password?</a> | ||
</div> | ||
|
||
<div class="text-center text-lg-start mt-4 pt-2"> | ||
{{ form.submit(class="btn btn-primary btn-lg", style="padding-left: 2.5rem; padding-right: 2.5rem;" ) }} | ||
|
||
<p class="small fw-bold mt-2 pt-1 mb-0">Don't have an account? | ||
<a href="{{ url_for('manage_login.register') }}" | ||
class="link-danger">Register</a></p> | ||
</div> | ||
|
||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</section> | ||
|
||
{% endblock %} | ||
|
63 changes: 63 additions & 0 deletions
63
src/pe_reports/manage_login/templates/manage_login/register.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{% extends 'base.html' %} | ||
{% block content %} | ||
|
||
{# <form method="post">#} | ||
{##} | ||
{# {{ form.hidden_tag() }}#} | ||
{# <br>#} | ||
{# {{ form.username.label }}{{ form.username() }}<br>#} | ||
{# {{ form.password.label }}{{ form.password() }}<br>#} | ||
{# {{ form.pass_confirm.label }}{{ form.pass_confirm }}<br>#} | ||
{# {{ form.submit() }}#} | ||
{##} | ||
{# </form>#} | ||
|
||
<section class="vh-100"> | ||
<div class="container-fluid h-custom"> | ||
<div class="row d-flex justify-content-center align-items-center h-100"> | ||
|
||
<div class="col-md-8 col-lg-6 col-xl-4 offset-xl-1"> | ||
<form method="post"> | ||
{{ form.hidden_tag() }} | ||
<!-- Email input --> | ||
<div class="form-outline mb-4"> | ||
{{ form.email.label }}{{ form.email(class="form-control form-control-lg", placeholder='Enter a valid email address') }} | ||
{# {{ form.email(class="form-control form-control-lg", placeholder='Enter a valid email address') }}{{ form.email.label }}#} | ||
|
||
</div> | ||
<div class="form-outline mb-4"> | ||
{{ form.username.label }}{{ form.username(class="form-control form-control-lg", placeholder='Enter a username') }} | ||
</div> | ||
|
||
<!-- Password input --> | ||
<div class="form-outline mb-3"> | ||
{{ form.password.label }}{{ form.password(class="form-control form-control-lg", placeholder="Enter password") }} | ||
|
||
</div> | ||
|
||
<div class="form-outline mb-3"> | ||
{{ form.pass_confirm.label }}{{ form.pass_confirm(class="form-control form-control-lg", placeholder="Confirm password") }} | ||
</div> | ||
|
||
{# <div class="d-flex justify-content-between align-items-center">#} | ||
{# <!-- Checkbox -->#} | ||
{##} | ||
{# <a href="#!" class="text-body">Forgot password?</a>#} | ||
{# </div>#} | ||
|
||
<div class="text-center text-lg-start mt-4 pt-2"> | ||
{{ form.submit(class="btn btn-primary btn-lg", style="padding-left: 2.5rem; padding-right: 2.5rem;" ) }} | ||
|
||
{# <p class="small fw-bold mt-2 pt-1 mb-0">Don't have an account?#} | ||
{# <a href="{{ url_for('manage_login.register') }}"#} | ||
{# class="link-danger">Register</a></p>#} | ||
</div> | ||
|
||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</section> | ||
|
||
{% endblock %} |
35 changes: 35 additions & 0 deletions
35
src/pe_reports/manage_login/templates/manage_login/reset_request.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{% extends 'base.html' %} | ||
{% block content %} | ||
|
||
<section class="vh-100"> | ||
<div class="container-fluid h-custom"> | ||
<div class="row d-flex justify-content-center align-items-center h-100"> | ||
|
||
<div class="col-md-8 col-lg-6 col-xl-4 offset-xl-1"> | ||
<form method="post"> | ||
{{ form.hidden_tag() }} | ||
<!-- Email input --> | ||
<div class="form-outline mb-4"> | ||
{{ form.email(class="form-control form-control-lg", | ||
placeholder='Enter a valid email address') }}{{ form.email.label }} | ||
|
||
</div> | ||
|
||
<div class="text-center text-lg-start mt-4 pt-2"> | ||
{{ form.submit(class="btn btn-primary btn-lg", | ||
style="padding-left: 2.5rem; padding-right: 2.5rem;" ) }} | ||
|
||
<p class="small fw-bold mt-2 pt-1 mb-0">Don't have an account? | ||
<a href="{{ url_for('manage_login.register') }}" | ||
class="link-danger">Register</a></p> | ||
</div> | ||
|
||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</section> | ||
|
||
{% endblock %} | ||
|
38 changes: 38 additions & 0 deletions
38
src/pe_reports/manage_login/templates/manage_login/reset_token.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{% extends 'base.html' %} | ||
{% block content %} | ||
|
||
<section class="vh-100"> | ||
<div class="container-fluid h-custom"> | ||
<div class="row d-flex justify-content-center align-items-center h-100"> | ||
|
||
<div class="col-md-8 col-lg-6 col-xl-4 offset-xl-1"> | ||
<form method="post"> | ||
{{ form.hidden_tag() }} | ||
<!-- Email input --> | ||
<div class="form-outline mb-4"> | ||
{{ form.password(class="form-control form-control-lg", | ||
placeholder='Enter a valid password address') }}{{ form.password.label }} | ||
|
||
</div> | ||
<div class="form-outline mb-4"> | ||
{{ form.pass_conf(class="form-control form-control-lg", | ||
placeholder='Enter a valid pass_conf address') }}{{ form.pass_conf.label }} | ||
|
||
</div> | ||
|
||
<div class="text-center text-lg-start mt-4 pt-2"> | ||
{{ form.submit(class="btn btn-primary btn-lg", | ||
style="padding-left: 2.5rem; padding-right: 2.5rem;" ) }} | ||
|
||
|
||
</div> | ||
|
||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</section> | ||
|
||
{% endblock %} | ||
|
Oops, something went wrong.