예제 #1
0
def core_before_request():
    """
    - To run before each request
    - It's save variable db in the global variable "g"
    """
    g.db = db
    g.my = None
    g.languages_object = Languages()
    # Get all the available languages
    # e.g. {u'en': u'English', u'it': u'Italiano'}
    g.available_languages = g.languages_object.get_languages(0)
    get_headers()

    # Check that user has login
    if "user_id" in session:
        # get user_id from session
        user_id = session["user_id"]
        # get the user's personal data.
        my = g.db.users.find_one({"_id": ObjectId(user_id)})

        # If user_id not exist in the user list g.my is None
        if my:
            g.my = my
            if not "token" in g.my:
                g.my["token"] = get_token(CLIENT_ID, CLIENT_SECRET, user["username"], user["password"])
                g.db.users.update({"_id": g.my["_id"]}, user)
            # get user language
            g.lan = g.my["lan"]
            g.language = g.available_languages[g.lan]
            if my["rank"] < 80:
                get_hash_admin()
예제 #2
0
파일: before.py 프로젝트: echwa/bombolone
def core_before_request():
    """
    - To run before each request
    - It's save variable db in the global variable "g"
    """
    g.db = db
    g.my = None
    g.languages_object = Languages()
    # Get all the available languages
    # e.g. {u'en': u'English', u'it': u'Italiano'}
    g.available_languages = g.languages_object.get_languages(0)
    get_headers()
    
    # Check that user has login
    if 'user_id' in session:
        # get user_id from session
        user_id = session['user_id']
        # get the user's personal data.
        my = g.db.users.find_one({ '_id' : ObjectId(user_id) })
        
        # If user_id not exist in the user list g.my is None
        if my:
            g.my = my
            # generate token if 
            # - you don't have a token field
            # - you have None as value
            # - you have everything is not 72 characters
            if not "token" in g.my or g.my["token"] is None or len(g.my["token"]) != 72:
                generate_token()
            # get user language
            g.lan = g.my['lan']
            g.language = g.available_languages[g.lan]
            if my['rank'] < 80:
                get_hash_admin()
예제 #3
0
def core_before_request():
    """
    - To run before each request
    - It's save variable db in the global variable "g"
    """
    g.db = db
    g.my = None
    g.languages_object = Languages()
    # Get all the available languages
    # e.g. {u'en': u'English', u'it': u'Italiano'}
    g.available_languages = g.languages_object.get_languages(0)
    get_headers()

    # Check that user has login
    if 'user_id' in session:
        # get user_id from session
        user_id = session['user_id']
        # get the user's personal data.
        my = g.db.users.find_one({'_id': ObjectId(user_id)})

        # If user_id not exist in the user list g.my is None
        if my:
            g.my = my
            if not "token" in g.my:
                g.my['token'] = get_token(CLIENT_ID, CLIENT_SECRET,
                                          user['username'], user['password'])
                g.db.users.update({"_id": g.my["_id"]}, user)
            # get user language
            g.lan = g.my['lan']
            g.language = g.available_languages[g.lan]
            if my['rank'] < 80:
                get_hash_admin()
예제 #4
0
def core_before_request():
    """ To run before each request"""
    my = None
    g.db = db
    languages_object = Languages()
    g.languages = languages_object.get_languages(0)
    
    get_headers()
    
    # Check that user has login
    if 'user_id' in session:
        # get user_id from session
        user_id = session['user_id']
        # get the user's personal data.
        my = g.db.users.find_one({ '_id' : ObjectId(user_id) })
        
        # If user_id not exist in the user list g.my is None
        if my:
            g.my = my
            # get user language
            g.lan = g.my['lan']
            g.language = g.languages[g.lan]
    
    get_hash_admin()