def join_events(): req_data = request.get_json() # { # "secret_key" : "QR123", # "username" : "test12345" # } DB.joinEvent(data=req_data) DB.attend(data=req_data) return jsonify({"msg": "xd"}), 200
def create_app(settings): """ Flask App""" app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = settings['database']['mySqlDsn'] app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False DB.init_app(app) @app.route("/", methods=['GET']) def index(): payload = {'baseUrl': 'ArdavanSassani.net', 'python version': '3.7'} return jsonify(payload) return app
def check_username(self): user = DB.findOne(collection='users', data=self.json()) if user: self.password = user['password'] self.admin = user['admin'] return True else: return False
def get_event(): event = [] req_data = request.get_json() response = DB.findOne(collection='users', data=req_data) if response == None: return jsonify({"msg": "no record"}), 201 for document in response["attend"]: document['event_id'] = str(document['event_id']) document['event_name'] = document['event_name'] document['type'] = document['type'] event.append(document) return jsonify(event), 200
class Login(DB.Model): """ User Client Model """ id = DB.Column(DB.Integer, primary_key=True) client_id = DB.Column(DB.Integer) user_id = DB.Column(DB.Integer) refresh_token = DB.Column(DB.String(50)) platform = DB.Column(DB.String(25)) browser = DB.Column(DB.String(40)) ip_add = DB.Column(DB.String(15)) def add(self, client: Client = None, refresh: str = None, user_id: int = None): """ insert user's to login table client has device info """ if client is not None: self.client_id = client.id_ self.platform = client.platform self.browser = client.browser self.ip_add = client.ip_ self.refresh_token = refresh self.user_id = user_id DB.session.add(self) DB.session.commit() def logout_by_login_id(self, login_id: int): """ revoke login revoke user's refresh token """ num_rows = Login.query.filter_by(id=login_id).delete() if num_rows == 0: raise EH('User Already Logged Out', 'No user from this machine is existed in our Data') DB.session.commit() def logout_by_user_id(self, user_id: int, client_id: int = None): """ revoke all if client_id is not null -> revoke user from all spesified application if client_id is null -> revoke user completely (all application) """ if client_id is not None: num_rows = Login.query.filter_by(user_id=user_id, client_id=client_id).delete() if num_rows == 0: raise EH('User Already Logged Out', 'No user from this app is existed in our Data') else: num_rows = Login.query.filter_by(user_id=user_id).delete() if num_rows == 0: raise EH('User Already Logged Out', 'No user is existed in our Data') DB.session.commit()
class User(DB.Model): """ User Model """ id = DB.Column(DB.Integer, primary_key=True) public_id = DB.Column(DB.String(13)) first_name = DB.Column(DB.String(80), unique=False, nullable=False) last_name = DB.Column(DB.String(80), unique=False, nullable=False) email = DB.Column(DB.String(120), unique=True, nullable=False) password = DB.Column(DB.String(120), unique=False, nullable=False) is_email_verified = DB.Column(DB.Boolean(1)) is_active = DB.Column(DB.Boolean(1)) roles = DB.Column(DB.JSON)
def insert(self): DB.insertName(collection='names', data=self.json())
def signin(username,password): auth = DB.find_one('Auths',{"username": username}) if auth != None and bcrypt.checkpw(password.encode('utf8'), auth['password']): return auth return None
def insert(self): data = { "username": self.username, "password": self.password } DB.insert(collection='Auths', data=data)
from flask import Flask, jsonify from flask_cors import CORS from src.database import DB from src.routes import mobile_route UPLOAD_FOLDER = r'C:\Users\ACER_NEW\Desktop\FLASK_SERVER\src\images' SECRET_KEY = 'shambala' project_root = os.path.dirname(__file__) app = Flask(__name__) CORS(app, resources={r'/*': {'origins': '*'}}) app.config['SECRET_KEY'] = SECRET_KEY app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER DB.init() app.debug = True app.register_blueprint(mobile_route.get_blueprint(), url_prefix="/mobile") @app.route('/') def bing(): return jsonify({"msg": "bong"}), 200 if __name__ == "__main__": app.run()
def get_event(self): user = DB.findOne(collection='users', data=self.json()) if user: return user
def insert(self): DB.insert(collection='users', data=self.json())
def __Check_DB(self, href): db = DB(href) return db.Check_DB()