Sindbad~EG File Manager

Current Path : /home/numerotech/sc.aios-scientificcommittee.org/aios_livenew_app/core/library/
Upload File :
Current File : //home/numerotech/sc.aios-scientificcommittee.org/aios_livenew_app/core/library/route_group.py

from core import app
from flask import url_for, session, redirect,request,flash,jsonify,render_template
from datetime import datetime, date, time, timedelta
from functools import wraps
from .. import Cryptography,Auth
from core.model.UserModel import UserModel

# Flask View decorators
class RouteGroup:

    def login_required(f):
        @wraps(f)
        def wrap(*args, **kwargs):    
            society_id = request.view_args['society_id']
            if Auth.check(society_id):
                return f(*args, **kwargs)
            else:
                return redirect(url_for('user.Login',society_id=society_id,society_key=request.view_args['society_key']))
        return wrap

    def society_required(f):
        @wraps(f)
        def wrap(*args, **kwargs):
            # if user is not logged in, redirect to login page      
            society_id = request.view_args['society_id']
            society_key = request.view_args['society_key']
            society_data = Auth.getSociety(society_id)
            if society_data and society_data["society_key"] == society_key  :
                return f(*args, **kwargs) # redirect to current url
            else:
                society_data  =  UserModel().getSociety(society_id,society_key)
                if society_data:
                    Auth.setSociety(society_data,society_id)
                    return f(*args, **kwargs) # redirect to current url
                else:
                    return ("<html><h1>Invalid URL</h1></html>")
        return wrap
    
    def eventlogin_required(f):
        @wraps(f)
        def wrap(*args, **kwargs):
            
            # if user is not logged in, redirect to login page      
            if Auth.check():
                return f(*args, **kwargs)
            else:
                return redirect(url_for('boevents.EventsLogin'))
        return wrap


    # def logout_required(f):
    # 	@wraps(f)
    # 	def wrap(*args, **kwargs):
    # 		# if user is not logged in, redirect to login page      
    # 		if Auth.check():
    # 			return f(*args, **kwargs)
    # 		else:
    # 			return redirect(url_for('user.Home',conf_id=request.view_args['conf_id'],conf_key=request.view_args['conf_key']))
    # 	return wrap

    def bo_login_required(f):
        @wraps(f)
        def wrap(*args, **kwargs):
            
            # if user is not logged in, redirect to login page      
            if Auth.bocheck():
                return f(*args, **kwargs)
            else:
                return redirect(url_for('backoffice.BOLogin'))
        return wrap

    def profile_required(f):
        @wraps(f)
        def wrap(*args, **kwargs):
            # if user is not logged in, redirect to login page
            society_id = request.view_args['society_id']      
            society_key = request.view_args['society_key']      
            user_uuid = Auth.user(society_id).get('user_uuid')
            user_id  = Auth.user(society_id).get('user_id')
            profile_updated = UserModel().check_if_profileupdated(user_uuid)
            if  profile_updated:
                if Auth.user(society_id).get('full_name'):
                    return f(*args, **kwargs)
                else:
                    Auth.login(profile_updated,society_id)
                    return f(*args, **kwargs)
            else:   
                # flash('Please update your profile and click on the "Update" button to proceed further','warning')
                # return redirect('https://profile.aios-scientificcommittee.org/1/aios/at/app/'+user_uuid)
                user_id = Cryptography.encrypt(int(user_id))
                return redirect(url_for('user.UserProfile',society_id=society_id,society_key=society_key,user_id=user_id))
        return wrap 

    # def profile_required(f):
    # 	@wraps(f)
    # 	def wrap(*args, **kwargs):
    # 		u=User()
    # 		user = session.get('user')
    # 		user_id = user.get('user_id')
    # 		user = User().get_user(user_id)
    # 		is_profile_update = user.get('is_profile_update')
    # 		print(str(is_profile_update))
    # 		# return str(is_profile_update)
    # 		if is_profile_update != 1 :
    # 			return redirect(url_for('user.UserProfile',user_id= user_id))
    # 		else :
    # 			return f(*args, **kwargs)

    # 	return wrap    

    # def payment_required(f):
    # 	@wraps(f)
    # 	def wrap(*args, **kwargs):
    # 		p = Payment()
    # 		user = session.get('user')
    # 		user_id = user.get('user_id')
    # 		checkpayment = p.checkuserinpayment(user_id)
    # 		# return len(checkpayment)
    # 		if (len(checkpayment)) == 1 :
    # 			return f(*args, **kwargs)
    # 		else:
    # 			return redirect(url_for('payupayment.payment'))
    # 	return wrap

    
    # Controller Sample :
    # from flask import request, Blueprint, jsonify, redirect, url_for,flash, render_template
    # from core.library.route_group import RouteGroup


    # @app.route('/home' , methods = ["GET"])
    # @RouteGroup.login_required #check if login else automatically redirect to login page
    # def home():
    #       return "welcome home"

    # @app.route('/payment' , methods = ["GET"])
    # @RouteGroup.login_required #check if login else automatically redirect to login page
    # @RouteGroup.payment_required #check if payment done else  automatically redirect to payment page
    # def payment():
    #       return "payment page here"

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists