コード例 #1
0
ファイル: items.py プロジェクト: fpischedda/lsystem
def use_magic_bottle(parameters):

    u = parameters['session'].user

    result = u.use_magic_bottle(parameters['plant_name'])

    if result == 0:
        timeline.write_to_timeline('admin', "User %s has used a magic bottle on the plant %s..." % (u.username,parameters['plant_name']))
        return {'result':'OK', 'plant':u.plants[parameters['plant_name']].serialize()}

    return {'result': 'KO', 'reason':result}
コード例 #2
0
ファイル: user.py プロジェクト: fpischedda/lsystem
def logout(parameters):
    """
    close the specified session
    """

    u = parameters['session'].user

    user_manager.get_instance().logout(u.username)
    
    session_manager.get_instance().close_session(parameters['session'].id)

    timeline.write_to_timeline('admin', "L'utente %s si e' scollegato, ciao..." % user.username)
    return {'result':'OK'}
コード例 #3
0
ファイル: user.py プロジェクト: fpischedda/lsystem
def login(parameters):
    """
    try to login a user, provided its username and password
    if successful return the OK result and the session_id
    otherwhise KO will be returned
    """

    user = user_manager.get_instance().login(parameters['email'], parameters['password'])

    if user:
        s = session_manager.get_instance().new_session(user)
        timeline.write_to_timeline('admin', "L'utente %s si e' collegato..." % user.username)
        return {'result':'OK', 'session_id':s.id, 'username':user.username}
    else:
        return {'result':'KO', 'reason':'wrong login'}
コード例 #4
0
ファイル: user.py プロジェクト: fpischedda/lsystem
def environments(parameters):
    """
    returns the list of alla available environments of the user who has made
    the request
    """

    try:
        username = parameters['username']
        u = user_manager.get_instance().get_user(username)
    except KeyError:
        u = parameters['session'].user

    if u != None:
        env = [e.serialize() for e in u.environments.values()]
        timeline.write_to_timeline('admin', "L'utente %s sta controllando le sue serre..." % u.username)
        return {'result':'OK', 'environments':env}

    return {'result':'KO', 'reason':'user %s not found' % parameters['username']}
コード例 #5
0
ファイル: user.py プロジェクト: fpischedda/lsystem
def plant(parameters):

    try:
        username = parameters['username']
        u = user_manager.get_instance().get_user(username)
    except KeyError:
        u = parameters['session'].user

    if u != None:

        try:
            p = u.plants[parameters['name']]
            timeline.write_to_timeline('admin', "User %s is looking at the plant %s..." % (u.username,parameters['name']))
            return {'result':'OK', 'plant':p.serialize()}

        except KeyError:
            return {'result':'KO', 'reason':'user\'s plant %s not found' % parameters['name']}

    return {'result':'KO', 'reason':'user %s not found' % parameters['username']}
コード例 #6
0
ファイル: items.py プロジェクト: fpischedda/lsystem
def use_item(parameters):

    u = parameters['session'].user

    result = 3

    item = parameters['item_name']
    if item == 'magic-bottle':
        result = u.use_magic_bottle(parameters['plant_name'])

    if result == 0:
        timeline.write_to_timeline('admin',
            "User %s has used a %s on the plant %s..." %
            (u.username,item, parameters['plant_name']))

        quantity = u.items[item].quantity
        return {'result':'OK', 'item':{'name':item, 'quantity': quantity}, 'plant':u.plants[parameters['plant_name']].serialize()}

    return {'result': 'KO', 'reason':result}
コード例 #7
0
ファイル: user.py プロジェクト: fpischedda/lsystem
def register(parameters):
    """
    try to register a user, provided its username and password
    if successful return the OK result and the session_id
    otherwhise KO will be returned
    """

    user = user_manager.get_instance().register_user(parameters['username'],
                                                    parameters['password'],
                                                    parameters['email'])

    if user:
        s = session_manager.get_instance().new_session(user)
        timeline.write_to_timeline('admin', "Welcome to the new user %s!" % parameters['username'])
        return {'result':'OK', 'session_id':s.id}
    else:
        return {
            'result':'KO',
            'reason':'username %s already registered' % parameters['username']
            }