Update
This commit is contained in:
parent
f8d91da0ef
commit
2e9fbf14e9
5 changed files with 97 additions and 31 deletions
10
app.py
10
app.py
|
|
@ -1,7 +1,15 @@
|
|||
import os
|
||||
from flask_route import *
|
||||
from flask import Flask
|
||||
from config import Config, DevelopmentConfig, TestingConfig, ProductionConfig
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = Flask(__name__)
|
||||
|
||||
PORT = int(os.environ.get('PORT', 33507))
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'secret_key')
|
||||
app.config.from_object(os.environ['APP_SETTINGS'])
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
app.run(host='0.0.0.0', port=PORT, debug=False)
|
||||
22
config.py
Normal file
22
config.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import os
|
||||
|
||||
|
||||
class Config(object):
|
||||
DEBUG = False
|
||||
TESTING = False
|
||||
CSRF_ENABLED = True
|
||||
SECRET_KEY = os.environ.get('SECRET_KEY', None)
|
||||
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL', None)
|
||||
|
||||
|
||||
class ProductionConfig(Config):
|
||||
DEBUG = False
|
||||
|
||||
|
||||
class TestingConfig(Config):
|
||||
TESTING = True
|
||||
|
||||
|
||||
class DevelopmentConfig(Config):
|
||||
DEVELOPMENT = True
|
||||
DEBUG = True
|
||||
26
models.py
Normal file
26
models.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
from app import db
|
||||
|
||||
|
||||
class Users(db.Model):
|
||||
__tablename__ = 'users'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
email = db.Column(db.String())
|
||||
login = db.Column(db.String())
|
||||
hashPass = db.Column(db.String())
|
||||
role = db.Column(db.String())
|
||||
|
||||
def __init__(self, email, login, hash_pass, role):
|
||||
self.email = email
|
||||
self.login = login
|
||||
self.hashPass = hash_pass
|
||||
self.role = role
|
||||
|
||||
def __repr__(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
'email': self.email,
|
||||
'login': self.login,
|
||||
'hashPass': self.hashPass,
|
||||
'role': self.role
|
||||
}
|
||||
31
responses.py
Normal file
31
responses.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from app import app
|
||||
import json
|
||||
|
||||
|
||||
def send_error(status_code, message):
|
||||
data_json = {
|
||||
'status': 'error',
|
||||
'message': message
|
||||
}
|
||||
res = app.response_class(
|
||||
response=json.dumps(data_json, sort_keys=True),
|
||||
status=status_code,
|
||||
mimetype='application/json'
|
||||
)
|
||||
res.headers['Access-Control-Allow-Origin'] = '*'
|
||||
return res
|
||||
|
||||
|
||||
def send_message(message, data):
|
||||
data_json = {
|
||||
'status': 'success',
|
||||
'message': message,
|
||||
'data': data
|
||||
}
|
||||
res = app.response_class(
|
||||
response=json.dumps(data_json, sort_keys=True),
|
||||
status=200,
|
||||
mimetype='application/json'
|
||||
)
|
||||
res.headers['Access-Control-Allow-Origin'] = '*'
|
||||
return res
|
||||
|
|
@ -1,34 +1,6 @@
|
|||
from flask import Flask, request
|
||||
import json
|
||||
from app import app
|
||||
from responses import send_message, send_error
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
def send_error(status_code, message):
|
||||
data_json = {
|
||||
'status': 'error',
|
||||
'message': message
|
||||
}
|
||||
res = app.response_class(
|
||||
response=json.dumps(data_json, sort_keys=True),
|
||||
status=status_code,
|
||||
mimetype='application/json'
|
||||
)
|
||||
res.headers['Access-Control-Allow-Origin'] = '*'
|
||||
return res
|
||||
|
||||
def send_message(message, data):
|
||||
data_json = {
|
||||
'status': 'success',
|
||||
'message': message,
|
||||
'data': data
|
||||
}
|
||||
res = app.response_class(
|
||||
response=json.dumps(data_json, sort_keys=True),
|
||||
status=200,
|
||||
mimetype='application/json'
|
||||
)
|
||||
res.headers['Access-Control-Allow-Origin'] = '*'
|
||||
return res
|
||||
|
||||
# Login
|
||||
@app.route('/api/login', methods=['POST'])
|
||||
|
|
@ -47,26 +19,31 @@ def register():
|
|||
def logout():
|
||||
return send_message('Logout not implemented', None)
|
||||
|
||||
|
||||
# Update User
|
||||
@app.route('/api/user/update', methods=['PUT'])
|
||||
def user_update():
|
||||
return send_message('User.update not implemented', None)
|
||||
|
||||
|
||||
# Delete User
|
||||
@app.route('/api/user/delete', methods=['DELETE'])
|
||||
def user_delete():
|
||||
return send_message('User.delete not implemented', None)
|
||||
|
||||
|
||||
# Admin : Create User
|
||||
@app.route('/api/user/create', methods=['POST'])
|
||||
def user_create():
|
||||
return send_message('User.create not implemented', None)
|
||||
|
||||
|
||||
# Admin : Change User password
|
||||
@app.route('/api/admin/update/user/password', methods=['PUT'])
|
||||
def admin_update_user_pwd():
|
||||
return send_message('Admin.update.user.password not implemented', None)
|
||||
|
||||
|
||||
# Admin : Change User role
|
||||
@app.route('/api/admin/update/user/role', methods=['PUT'])
|
||||
def admin_update_user_role():
|
||||
|
|
@ -78,11 +55,13 @@ def admin_update_user_role():
|
|||
def admin_delete_user():
|
||||
return send_message('Admin.delete.user not implemented', None)
|
||||
|
||||
|
||||
# List of User (must be authenticated)
|
||||
@app.route('/api/users', methods=['GET'])
|
||||
def users():
|
||||
return send_message('Users not implemented', None)
|
||||
|
||||
|
||||
# Search User
|
||||
@app.route('/api/users/search', methods=['POST'])
|
||||
def users_search():
|
||||
Loading…
Add table
Add a link
Reference in a new issue