def alarm_save(): fields = ['id_', 'name', 'volume', 'stream', 'action'] data = dict([ (k, request.POST.get(k)) for k in fields ]) data['volume'] = int(data['volume']) data['type'] = 'radio' try: date = request.POST.get('date') hour = request.POST.get('hour') data['at'] = time.mktime(time.strptime("%s %s" % (date, hour), "%Y-%m-%d %H:%M:%S")) dt = datetime.datetime.fromtimestamp(data['at']) data['date'] = dt.strftime('%Y-%m-%d') data['hour'] = dt.strftime('%H:%M:%S') except: return "Problem with the date... Chek it, please" if data['id_']: data['id_'] = int(data['id_']) alarms_data = storage.replace('alarms', data) storage.save_table('alarms', alarms_data) else: # TODO: All this logic of getting a new ID for the given table should # be handled by the storage lib stored = storage.read() ids = map(lambda x: x['id_'], stored['alarms']) data['id_'] = max(ids)+1 if ids else 1 stored['alarms'].append(data) storage.save(stored) alarms.set_alarms(storage.read('alarms')) redirect('/alarm/edit/%s' % data['id_'])
def alarm_delete(id_): storage.delete('alarms', int(id_)) alarms.set_alarms(storage.read('alarms')) return "ok"
elif req.params.get('username'): username = req.params.get('username') password = req.params.get('password') if check_login(username, password): # Login successfull! Create the session and set the cookie uuid = helpers.session.create() bottle.response.set_cookie('session', uuid) # It would be nice to use a redirect here but since I'm # setting a cookie it is not the best idea ever return index() else: return template('login') # Bad login! # If the IP is whitelisted, let them in elif helpers.in_whitelist(config.AUTH_WHITELIST, bottle.request.remote_addr): return callback(*args, **kwargs) # You are not authenticated yet or don't have a valid session return template('login') return wrapper if __name__ == '__main__': import sys debug = '--debug' in sys.argv alarms.set_alarms(storage.read('alarms')) bottle.debug(debug) bottle.install(authentication_plugin) bottle.run(host='0.0.0.0', port=config.PORT, reloader=debug)