diff --git a/README.md b/README.md index 9f7986b..109643d 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ # Pilzno +Building out the pilzno crm \ No newline at end of file diff --git a/app/__pycache__/__init__.cpython-310.pyc b/app/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..3c0c9a4 Binary files /dev/null and b/app/__pycache__/__init__.cpython-310.pyc differ diff --git a/app/__pycache__/config.cpython-310.pyc b/app/__pycache__/config.cpython-310.pyc new file mode 100644 index 0000000..0ea1947 Binary files /dev/null and b/app/__pycache__/config.cpython-310.pyc differ diff --git a/app/config.py b/app/config.py index a50fa7c..90aeeb6 100644 --- a/app/config.py +++ b/app/config.py @@ -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(): diff --git a/app/main/__pycache__/__init__.cpython-310.pyc b/app/main/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..dc72af7 Binary files /dev/null and b/app/main/__pycache__/__init__.cpython-310.pyc differ diff --git a/app/main/__pycache__/routes.cpython-310.pyc b/app/main/__pycache__/routes.cpython-310.pyc new file mode 100644 index 0000000..be8b20e Binary files /dev/null and b/app/main/__pycache__/routes.cpython-310.pyc differ diff --git a/app/main/templates/base.html b/app/main/templates/base.html index 22262c1..b4070e6 100644 --- a/app/main/templates/base.html +++ b/app/main/templates/base.html @@ -12,17 +12,18 @@ {% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} diff --git a/app/users/__pycache__/__init__.cpython-310.pyc b/app/users/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..9125a02 Binary files /dev/null and b/app/users/__pycache__/__init__.cpython-310.pyc differ diff --git a/app/users/__pycache__/forms.cpython-310.pyc b/app/users/__pycache__/forms.cpython-310.pyc new file mode 100644 index 0000000..f320745 Binary files /dev/null and b/app/users/__pycache__/forms.cpython-310.pyc differ diff --git a/app/users/__pycache__/models.cpython-310.pyc b/app/users/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..8568868 Binary files /dev/null and b/app/users/__pycache__/models.cpython-310.pyc differ diff --git a/app/users/__pycache__/routes.cpython-310.pyc b/app/users/__pycache__/routes.cpython-310.pyc new file mode 100644 index 0000000..0bae6da Binary files /dev/null and b/app/users/__pycache__/routes.cpython-310.pyc differ diff --git a/app/users/forms.py b/app/users/forms.py index e69de29..b7139ca 100644 --- a/app/users/forms.py +++ b/app/users/forms.py @@ -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') \ No newline at end of file diff --git a/app/users/routes.py b/app/users/routes.py index 80205b7..2ba8714 100644 --- a/app/users/routes.py +++ b/app/users/routes.py @@ -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/') @login_required -def user_page(user_id): - - return render_template('user_page.html') \ No newline at end of file +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) \ No newline at end of file diff --git a/app/users/templates/login.html b/app/users/templates/login.html new file mode 100644 index 0000000..68bf1f0 --- /dev/null +++ b/app/users/templates/login.html @@ -0,0 +1,35 @@ +{% extends 'base.html' %} +{% block title %}Login{% endblock title %} +{% block content %} +
+
+
+
+
+

Login User

+
+ {{ form.hidden_tag() }} + +
+ {{ form.email.label(class="form-label") }} + {{ form.email(class="form-control") }} +
+ +
+ {{ form.password.label(class="form-label") }} + {{ form.password(class="form-control") }} +
+ +
+ {{ form.remember(class="form-check-input") }} + +
+ + {{ form.submit(class='btn btn-primary') }} +
+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/app/users/templates/register_user.html b/app/users/templates/register_user.html new file mode 100644 index 0000000..3a006f6 --- /dev/null +++ b/app/users/templates/register_user.html @@ -0,0 +1,81 @@ +{% extends 'base.html' %} +{% block title %}User Access{% endblock title %} +{% block content %} +
+
+
+
+
+

Register

+
+ {{ form.hidden_tag() }} + +
+ {{ form.first_name.label(class="form-label") }} + {{ form.first_name(class="form-control") }} + {% if form.first_name.errors %} +
    + {% for error in form.first_name.errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
+ +
+ {{ form.last_name.label(class="form-label") }} + {{ form.last_name(class="form-control") }} + {% if form.last_name.errors %} +
    + {% for error in form.last_name.errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
+ +
+ {{ form.email.label(class="form-label") }} + {{ form.email(class="form-control") }} + {% if form.email.errors %} +
    + {% for error in form.email.errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
+ +
+ {{ form.password.label(class="form-label") }} + {{ form.password(class="form-control") }} + {% if form.password.errors %} +
    + {% for error in form.password.errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
+ +
+ {{ form.confirm_password.label(class="form-label") }} + {{ form.confirm_password(class="form-control") }} + {% if form.confirm_password.errors %} +
    + {% for error in form.confirm_password.errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
+ + + {{ form.submit(class='btn btn-primary') }} +
+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/app/users/templates/user_page.html b/app/users/templates/user_page.html new file mode 100644 index 0000000..384348b --- /dev/null +++ b/app/users/templates/user_page.html @@ -0,0 +1,38 @@ +{% extends 'base.html' %} +{% block title %}User Page{% endblock title %} +{% block content %} +
+
+
+

Welcome, {{ user.first_name }} {{ user.last_name }}

+
+
+
+ +
+
+ {% if user_reports %} +

Downloadable Files:

+ + + + + + + + + + + + + + +
Report TypeNumber of RowsTime CreatedRange StartRange EndDownloadDelete
+ {% else %} +

No reports available.

+ {% endif %} +
+
+
+ +{% endblock %} \ No newline at end of file