|
@@ -0,0 +1,99 @@
|
|
|
+# Simple forum
|
|
|
+
|
|
|
+This is a simple forum built-in Flask framework in Python. The main code is less than 100 lines to be as lightweight as possible.
|
|
|
+For the moment the forum is very basic.
|
|
|
+
|
|
|
+## Features
|
|
|
+
|
|
|
+* Manage accounts
|
|
|
+* Order the topics by most active, new and categories
|
|
|
+* Like the topics and answers
|
|
|
+* Integrate HTML formating (need to change this for security purposes)
|
|
|
+* Bumb the posts by reply (the posts are ordered by the last actives)
|
|
|
+
|
|
|
+In the future I want to integrate the following ones as well
|
|
|
+
|
|
|
+* Trust system and badges
|
|
|
+* Notifications
|
|
|
+* Private msgs
|
|
|
+* Change the password and manage the account
|
|
|
+* Manage categories and limit them
|
|
|
+* Create a search bar to search through, topics and replies
|
|
|
+
|
|
|
+## Why I made it
|
|
|
+
|
|
|
+I made this forum because I want to make a serie of basic lightweight web apps that can be
|
|
|
+used to make other projects as well. I challenged myself to make apps with the following lines limits:
|
|
|
+
|
|
|
+* 100 lines for the main *logic* code (app.py)
|
|
|
+* 100 lines for the *non-logic* code (helper.py)
|
|
|
+* Not really a limit, but trying to keep it small anyway for the templates. But **not** using external imports. Raw CSS only.
|
|
|
+* Other modules are allowed, **only** if they can be used for a various projects (login.py)
|
|
|
+
|
|
|
+So these are the advantages:
|
|
|
+
|
|
|
+* You got a full control over the code because it's simple and basic. You can make it more complex if you want to, but it remmains under your control
|
|
|
+* You can use it for education purposes by understanding the code
|
|
|
+* You can kickstart your project by integrating this one as a base
|
|
|
+* Less lines, less bugs, less troubleshooting :p
|
|
|
+* The code is durable, there are less chances that the code becomes obsolete
|
|
|
+* Peer to peer friendly, you can adapt the code to make a peer to peer app
|
|
|
+* Low-end servers and clients friendly.
|
|
|
+* Fast websites. Because the code is limited and no more unneccessary CSS and JS is included the website is much faster
|
|
|
+
|
|
|
+In bonus you can also uses the 'login.py' script to speed up the devloppement of the account management in your own Flask apps.
|
|
|
+
|
|
|
+## How to use this?
|
|
|
+
|
|
|
+1. Download the project
|
|
|
+2. Change the code in the templates to fits your needs (you can also do it along the way)
|
|
|
+3. Run the script 'app.py'
|
|
|
+
|
|
|
+*Note: to change the style of the website I highly recommend you to use the 'Style inspector' built-in in Firefox.*
|
|
|
+
|
|
|
+## How to use the login.py
|
|
|
+
|
|
|
+1. Add login.py file into the root folder of your project
|
|
|
+2. Into your main app file you can add the following snippet:
|
|
|
+
|
|
|
+```python
|
|
|
+# Import the login library
|
|
|
+from login import *
|
|
|
+
|
|
|
+# Create a class User and a variable db containing the database from sqlalchemy
|
|
|
+
|
|
|
+# In the login page back end:
|
|
|
+@app.route('/login')
|
|
|
+def login():
|
|
|
+ try:
|
|
|
+ loginUser(request.form['username'], request.form['password'], User)
|
|
|
+ return 'You are now logged in. as ' + current_user.username
|
|
|
+ except:
|
|
|
+ return 'Username or password invalid.'
|
|
|
+
|
|
|
+@app.route('/register')
|
|
|
+def register():
|
|
|
+ try:
|
|
|
+ createUser(request.form['username'], request.form['password'], db, User)
|
|
|
+ return 'New account created, you are logged in.'
|
|
|
+ except:
|
|
|
+ return 'An error occurs, probably because this username is already taken.'
|
|
|
+
|
|
|
+@app.route('/logout')
|
|
|
+def logout():
|
|
|
+ logout_user()
|
|
|
+ return 'You are logged out.'
|
|
|
+```
|
|
|
+
|
|
|
+This is the class User:
|
|
|
+
|
|
|
+```python
|
|
|
+class User(UserMixin, db.Model):
|
|
|
+ id = db.Column(db.Integer, primary_key=True)
|
|
|
+ username = db.Column(db.Text, unique=True)
|
|
|
+ password = db.Column(db.Text)
|
|
|
+ def __init__(self, username, password):
|
|
|
+ self.username = username
|
|
|
+ self.password = password
|
|
|
+```
|
|
|
+
|