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'}
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'}
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'] }