-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from hoangsonww/deployment-branch
Updated Personal Portfolio
- Loading branch information
Showing
17 changed files
with
11,358 additions
and
16,126 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -10,14 +10,14 @@ | |
# Initialize Flask App | ||
app = Flask(__name__) | ||
|
||
# Database Configuration | ||
# Database Configuration (Replace with your own database URI if you want to use my project) | ||
app.config['SECRET_KEY'] = 'your_secret_key' | ||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///portfolio.db' | ||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | ||
db = SQLAlchemy(app) | ||
migrate = Migrate(app, db) | ||
|
||
# Mail Configuration | ||
# Mail Configuration (Replace with your own mail server details if you want to use my project) | ||
app.config['MAIL_SERVER']='smtp.yourmailserver.com' | ||
app.config['MAIL_PORT'] = 587 | ||
app.config['MAIL_USERNAME'] = '[email protected]' | ||
|
@@ -46,6 +46,7 @@ def set_password(self, password): | |
def check_password(self, password): | ||
return check_password_hash(self.password_hash, password) | ||
|
||
|
||
# Database models | ||
class Contact(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
|
@@ -54,21 +55,25 @@ class Contact(db.Model): | |
subject = db.Column(db.String(150)) | ||
message = db.Column(db.Text) | ||
|
||
|
||
class Project(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
title = db.Column(db.String(100), nullable=False) | ||
description = db.Column(db.Text) | ||
link = db.Column(db.String(200)) | ||
|
||
|
||
class Skill(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
name = db.Column(db.String(80), nullable=False) | ||
proficiency = db.Column(db.Integer) | ||
|
||
|
||
@login_manager.user_loader | ||
def load_user(user_id): | ||
return User.query.get(int(user_id)) | ||
|
||
|
||
@app.route('/register', methods=['POST']) | ||
def register(): | ||
data = request.form | ||
|
@@ -78,6 +83,7 @@ def register(): | |
db.session.commit() | ||
return jsonify({"status": "User registered successfully"}), 201 | ||
|
||
|
||
@app.route('/login', methods=['POST']) | ||
def login(): | ||
data = request.form | ||
|
@@ -87,12 +93,14 @@ def login(): | |
return jsonify({"status": "Logged in successfully"}), 200 | ||
return jsonify({"status": "Invalid username or password"}), 401 | ||
|
||
|
||
@app.route('/logout') | ||
@login_required | ||
def logout(): | ||
logout_user() | ||
return jsonify({"status": "Logged out successfully"}), 200 | ||
|
||
|
||
# Routes | ||
@app.route('/contact', methods=['POST']) | ||
def contact(): | ||
|
@@ -102,26 +110,26 @@ def contact(): | |
db.session.commit() | ||
return jsonify({"status": "success"}), 201 | ||
|
||
|
||
@app.route('/projects', methods=['GET']) | ||
def get_projects(): | ||
projects = Project.query.all() | ||
project_data = [{"title": project.title, "description": project.description, "link": project.link} for project in projects] | ||
return jsonify(project_data) | ||
|
||
|
||
@app.route('/skills', methods=['GET']) | ||
def get_skills(): | ||
skills = Skill.query.all() | ||
skill_data = [{"name": skill.name, "proficiency": skill.proficiency} for skill in skills] | ||
return jsonify(skill_data) | ||
|
||
|
||
# Error handling | ||
@app.errorhandler(404) | ||
def not_found(error): | ||
return make_response(jsonify({'error': 'Not found'}), 404) | ||
|
||
if __name__ == '__main__': | ||
db.create_all() | ||
app.run(debug=True) | ||
|
||
@app.route('/send_mail', methods=['POST']) | ||
def send_mail(): | ||
|
@@ -131,6 +139,7 @@ def send_mail(): | |
mail.send(msg) | ||
return jsonify({"status": "Email sent successfully"}), 200 | ||
|
||
|
||
if __name__ == '__main__': | ||
db.create_all() | ||
app.run(debug=True) |
Oops, something went wrong.