def change_password(): old = request.POST.get('old_password') new = request.POST.get('new_password') repeat = request.POST.get('repeat_password') user = storage.get_by_id('user', 'admin') sha_password = hashlib.sha256(old).hexdigest() if sha_password != user['password']: return config_edit(err_msg="Bad password") elif new != repeat: return config_edit(err_msg="Password missmatches") user['password'] = hashlib.sha256(new).hexdigest() storage.save_table('user', [user]) return config_edit(err_msg="Password changed successfully")
def command_edit(id_=None): id_ = "" if id_ == "new" else int(id_) data = helpers.Dummy(storage.get_by_id('commands', id_)) return template('edit', data=data)
def check_login(user, password): user = storage.get_by_id('user', user) sha_password = hashlib.sha256(password).hexdigest() return user and user['password'] == sha_password
def alarm_edit(id=None): id = "" if id == "new" else int(id) alarm = helpers.Dummy(storage.get_by_id('alarms', id)) radios = sorted(storage.read('radio').items()) return template('alarms-radio-edit', radios=radios, alarm=alarm)