Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
maddoxcypher committed Feb 25, 2024
1 parent a16cf13 commit d74c05f
Show file tree
Hide file tree
Showing 557 changed files with 7,315 additions and 32 deletions.
Binary file added task_scheduler/__pycache__/app.cpython-312.pyc
Binary file not shown.
112 changes: 96 additions & 16 deletions task_scheduler/app.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,105 @@
from datetime import datetime, timedelta
from flask import Flask, render_template, request, redirect, url_for
from flask import Flask, render_template, request, redirect, url_for, flash, session
from flask_mysqldb import MySQL
from flask_bcrypt import Bcrypt

app = Flask(__name__)
tasks = []
app.config['SECRET_KEY'] = 'your_secret_key'
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = '12345'
app.config['MYSQL_DB'] = 'tks'
bcrypt = Bcrypt(app)
mysql = MySQL(app)

@app.route('/schedule', methods=['POST'])
def schedule_task():
task = request.form["task"]
reminder = request.form['reminder']
reminder_datetime = datetime.strptime(reminder, '%Y-%m-%dT%H:%M')
tasks.append({'task': task, 'reminder': reminder_datetime})
return redirect(url_for('index'))
with app.app_context():
cur = mysql.connection.cursor()
cur.execute("""
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL
)
""")
cur.execute("""
CREATE TABLE IF NOT EXISTS tasks (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
task_description TEXT,
is_completed BOOLEAN DEFAULT FALSE,
FOREIGN KEY (user_id) REFERENCES users(id)
)
""")
mysql.connection.commit()
cur.close()

@app.route('/')
def index():
datetime_now = datetime.now()
return render_template('index.html', datetime_now=datetime_now)
if 'user_id' in session:
user_id = session['user_id']
cur = mysql.connection.cursor()
cur.execute("SELECT task_description, is_completed FROM tasks WHERE user_id = %s", (user_id,))
tasks = cur.fetchall()
cur.close()
return render_template('index.html', tasks=tasks)
return redirect(url_for('login'))

@app.route('/tasks')
def view_tasks():
return render_template('tasks.html', tasks=tasks)
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']

cur = mysql.connection.cursor()
cur.execute("SELECT id, password FROM users WHERE username = %s", (username,))
user = cur.fetchone()
cur.close()

if user and bcrypt.check_password_hash(user[1], password):
session['user_id'] = user[0]
return redirect(url_for('index'))
else:
flash('Invalid username or password', 'danger')

return render_template('login.html')

@app.route('/register', methods=['GET', 'POST'])
def register():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']

hashed_password = bcrypt.generate_password_hash(password).decode('utf-8')

cur = mysql.connection.cursor()
cur.execute("INSERT INTO users (username, password) VALUES (%s, %s)", (username, hashed_password))
mysql.connection.commit()
cur.close()

flash('Registration successful. You can now log in.', 'success')
return redirect(url_for('login'))

return render_template('register.html')

@app.route('/logout')
def logout():
session.pop('user_id', None)
return redirect(url_for('login'))

@app.route('/add_task', methods=['POST'])
def add_task():
if 'user_id' in session:
user_id = session['user_id']
task_description = request.form['task_description']

cur = mysql.connection.cursor()
cur.execute("INSERT INTO tasks (user_id, task_description) VALUES (%s, %s)", (user_id, task_description))
mysql.connection.commit()
cur.close()

flash('Task added successfully!', 'success')
return redirect(url_for('index'))

return redirect(url_for('login'))

if __name__ == '__main__':
app.run(debug=True)
app.run(debug=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Copyright (c) 2011 by Max Countryman.

Some rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* The names of the contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
Metadata-Version: 2.1
Name: Flask-Bcrypt
Version: 1.0.1
Summary: Brcrypt hashing for Flask.
Home-page: https://github.com/maxcountryman/flask-bcrypt
Author: Max Countryman
Author-email: maxc@me.com
License: BSD
Platform: any
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Description-Content-Type: text/markdown
Requires-Dist: Flask
Requires-Dist: bcrypt (>=3.1.1)

[![Tests](https://img.shields.io/github/workflow/status/maxcountryman/flask-bcrypt/Tests/master?label=tests)](https://github.com/maxcountryman/flask-bcrypt/actions)
[![Version](https://img.shields.io/pypi/v/Flask-Bcrypt.svg)](https://pypi.python.org/pypi/Flask-Bcrypt)
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/Flask-Bcrypt.svg)](https://pypi.python.org/pypi/Flask-Bcrypt)

# Flask-Bcrypt

Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for
your application.

Due to the recent increased prevalence of powerful hardware, such as modern
GPUs, hashes have become increasingly easy to crack. A proactive solution to
this is to use a hash that was designed to be "de-optimized". Bcrypt is such
a hashing facility; unlike hashing algorithms such as MD5 and SHA1, which are
optimized for speed, bcrypt is intentionally structured to be slow.

For sensitive data that must be protected, such as passwords, bcrypt is an
advisable choice.

## Installation

Install the extension with one of the following commands:

$ easy_install flask-bcrypt

or alternatively if you have pip installed:

$ pip install flask-bcrypt

## Usage

To use the extension simply import the class wrapper and pass the Flask app
object back to here. Do so like this:

from flask import Flask
from flask_bcrypt import Bcrypt

app = Flask(__name__)
bcrypt = Bcrypt(app)

Two primary hashing methods are now exposed by way of the bcrypt object. Use
them like so:

pw_hash = bcrypt.generate_password_hash('hunter2')
bcrypt.check_password_hash(pw_hash, 'hunter2') # returns True

## Documentation

The Sphinx-compiled documentation is available here: https://flask-bcrypt.readthedocs.io/


Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Flask_Bcrypt-1.0.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
Flask_Bcrypt-1.0.1.dist-info/LICENSE,sha256=RFRom0T_iGtIZZvvW5_AD14IAYQvR45h2hYe0Xp0Jak,1456
Flask_Bcrypt-1.0.1.dist-info/METADATA,sha256=wO9naenfHK7Lgz41drDpI6BlMg_CpzjwGWsAiko2wsk,2615
Flask_Bcrypt-1.0.1.dist-info/RECORD,,
Flask_Bcrypt-1.0.1.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
Flask_Bcrypt-1.0.1.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
Flask_Bcrypt-1.0.1.dist-info/top_level.txt,sha256=HUgQw7e42Bb9jcMgo5popKpplnimwUQw3cyTi0K1N7o,13
__pycache__/flask_bcrypt.cpython-312.pyc,,
flask_bcrypt.py,sha256=thnztmOYR9M6afp-bTRdSKsPef6R2cOFo4j_DD88-Ls,8856
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Wheel-Version: 1.0
Generator: bdist_wheel (0.37.1)
Root-Is-Purelib: true
Tag: py3-none-any

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask_bcrypt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
==================================
AUTHORS (in chronological order)
==================================

Alexandre Ferland (admiralobvious)
Alex Vishnya (Sp1tF1r3)
Shaun (shaunpud)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2022 Alexandre Ferland

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Metadata-Version: 2.1
Name: Flask-MySQLdb
Version: 2.0.0
Summary: MySQLdb extension for Flask
Home-page: https://github.com/alexferl/flask-mysqldb
Author: Alexandre Ferland
Author-email: me@alexferl.com
License: MIT
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: AUTHORS
Requires-Dist: Flask >=1.0.4
Requires-Dist: mysqlclient >=2.2.0

Flask-MySQLdb [![Build Status](https://app.travis-ci.com/alexferl/flask-mysqldb.svg?branch=master)](https://app.travis-ci.com/alexferl/flask-mysqldb)
================

Flask-MySQLdb provides MySQL connection for Flask.

Quickstart
----------

First, you _may_ need to install some dependencies for [mysqlclient](https://github.com/PyMySQL/mysqlclient)
if you don't already have them, see [here](https://github.com/PyMySQL/mysqlclient#install).

Second, install Flask-MySQLdb:
```shell
pip install flask-mysqldb
```

Flask-MySQLdb depends, and will install for you, recent versions of Flask
(1.0.4 or later) and [mysqlclient](https://github.com/PyMySQL/mysqlclient).
Flask-MySQLdb is compatible with and tested with Python 3.8+.

Next, add a ``MySQL`` instance to your code:

```python
from flask import Flask
from flask_mysqldb import MySQL

app = Flask(__name__)

# Required
app.config["MYSQL_USER"] = "user"
app.config["MYSQL_PASSWORD"] = "password"
app.config["MYSQL_DB"] = "database"
# Extra configs, optional:
app.config["MYSQL_CURSORCLASS"] = "DictCursor"
app.config["MYSQL_CUSTOM_OPTIONS"] = {"ssl": {"ca": "/path/to/ca-file"}} # https://mysqlclient.readthedocs.io/user_guide.html#functions-and-attributes

mysql = MySQL(app)

@app.route("/")
def users():
cur = mysql.connection.cursor()
cur.execute("""SELECT user, host FROM mysql.user""")
rv = cur.fetchall()
return str(rv)

if __name__ == "__main__":
app.run(debug=True)
```

Other configuration directives can be found [here](http://flask-mysqldb.readthedocs.io/en/latest/#configuration).

Why
---
Why would you want to use this extension versus just using MySQLdb by itself?
The only reason is that the extension was made using Flask's best practices in relation
to resources that need caching on the [app context](https://flask.palletsprojects.com/en/2.0.x/appcontext/).
What that means is that the extension will manage creating and teardown the connection to MySQL
for you while with if you were just using MySQLdb you would have to do it yourself.


Resources
---------

- [Documentation](http://flask-mysqldb.readthedocs.org/en/latest/)
- [PyPI](https://pypi.python.org/pypi/Flask-MySQLdb)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Flask_MySQLdb-2.0.0.dist-info/AUTHORS,sha256=N_OAF5uLnsIuKAV4dY4GU92mnGBethgpd5SLAsKJuZw,181
Flask_MySQLdb-2.0.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
Flask_MySQLdb-2.0.0.dist-info/LICENSE,sha256=mA1VKO0sinmNw5rzB6pg8pApx_DnT8MQYRHsvnoq7Ls,1084
Flask_MySQLdb-2.0.0.dist-info/METADATA,sha256=wgVHQn8g_44Vmd_m6APvYJnxC-V0xEaX-G9sPNJ3Xcc,3026
Flask_MySQLdb-2.0.0.dist-info/RECORD,,
Flask_MySQLdb-2.0.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
Flask_MySQLdb-2.0.0.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
Flask_MySQLdb-2.0.0.dist-info/top_level.txt,sha256=G7cQGSsq4VqniHIv9Z7r6OEI-gQHh14xKXrQkSrlgLU,14
flask_mysqldb/VERSION,sha256=wo_MpTY3vIjhJK8XJd8Ty5jGne3v1i-zzb4c22t2BiQ,6
flask_mysqldb/__init__.py,sha256=0mERBDZbJEoE4vQWBo2xSXY9m2LftXdyzrDCGPxatBc,3985
flask_mysqldb/__pycache__/__init__.cpython-312.pyc,,
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Wheel-Version: 1.0
Generator: bdist_wheel (0.41.2)
Root-Is-Purelib: true
Tag: py3-none-any

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask_mysqldb
Loading

0 comments on commit d74c05f

Please sign in to comment.