def account_manage_id(id): if request.method == 'GET': user.id = id manage_user = user.get_user() json.json = manage_user user_decoded = json.decode() return render_template('account/change.html', username=user_decoded['username'], email=user_decoded['email']) elif request.method == 'POST': try: user.id = id manage_user = user.get_user() json.json = manage_user user_decoded = json.decode() if not request.form['username']: user.username = user_decoded['username'] else: user.username = request.form['username'] if not request.form['email']: user.email = user_decoded['email'] else: user.email = request.form['email'] if not request.form['password']: user.password = user_decoded['password'] else: user.password = hashlib.sha1(request.form['password'].encode('utf-8')).hexdigest() user.manage_user() flash(gettext('Account changed !') , 'success') return redirect(url_for('auth.account_manage')) except UserException: flash(gettext('An error has occured !') , 'error') return redirect(url_for('auth.account_manage'))
def calendars(): if request.method == 'GET': events.user = current_user.id json.json = events.get() events_list = json.decode() return render_template('calendar/index.html', events=events_list) elif request.method == 'POST': try: events.user = current_user.id events.title = request.form['title'] events.notes = request.form['notes'] events.lieu = request.form['lieu'] events.color = request.form['color'] events.startdate = request.form['start'] events.enddate = request.form['end'] events.add() return redirect(url_for('core.calendars')) except CalendarException: flash(gettext('An error has occured'),'error') return redirect(url_for('core.calendars')) elif request.method == 'PUT': try: events.user = current_user.id events.id = request.form['id'] events.startdate = request.form['start'] events.enddate = request.form['end'] events.update_date() return redirect(url_for('core.calendars')) except CalendarException: flash(gettext('An error has occured'),'error') return redirect(url_for('core.calendars'))
def change_account(): if request.method == 'GET': return render_template('account/manage_account.html') elif request.method == 'POST': try: user.id = current_user.id user.lastpassword = request.form['lastpassword'] if not request.form['username']: user.username = current_user.username else: user.username = request.form['username'] if not request.form['email']: user.email = current_user.email else: user.email = request.form['email'] if not request.form['password']: user.password = current_user.password else: user.password = hashlib.sha1(request.form['password'].encode('utf-8')).hexdigest() change = user.change_user() if change == 0: flash(gettext('Passwords are not same !' ), 'error') return redirect(url_for('auth.change_account')) flash(gettext('Account changed successfully' ), 'success') return redirect(url_for('auth.change_account')) except UserException: flash(gettext('An error has occured !') , 'error') return redirect(url_for('auth.account_manage'))
def calendars(): if request.method == 'GET': events.user = current_user.id json.json = events.get() events_list = json.decode() return render_template('calendar/index.html', events=events_list) elif request.method == 'POST': try: events.user = current_user.id events.title = request.form['title'] events.notes = request.form['notes'] events.lieu = request.form['lieu'] events.color = request.form['color'] events.startdate = request.form['start'] events.enddate = request.form['end'] events.add() return redirect(url_for('core.calendars')) except CalendarException: flash(gettext('An error has occured'), 'error') return redirect(url_for('core.calendars')) elif request.method == 'PUT': try: events.user = current_user.id events.id = request.form['id'] events.startdate = request.form['start'] events.enddate = request.form['end'] events.update_date() return redirect(url_for('core.calendars')) except CalendarException: flash(gettext('An error has occured'), 'error') return redirect(url_for('core.calendars'))
def delete_house(id): try: house.id = id house.delete() flash(gettext('House Deleted'), 'success') return redirect(url_for('core.options')) except HouseException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.options'))
def delete_device(id): try: devices.id = id devices.delete() flash(gettext('Devices Deleted'), 'success') return redirect(url_for('mi_light.index')) except DevicesException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('mi_light.index'))
def delete_room(id): try: room.id = id room.delete() flash(gettext('Room Deleted'), 'success') return redirect(url_for('core.options')) except RoomException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.options'))
def widget_delete(id): try: box.id = id box.delete() flash(gettext('Deleted with success !'), 'success') return redirect(url_for('core.widgets')) except WidgetException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.widgets'))
def logout(): try: user.logout() logger.info('User Logout successfully') flash(gettext('You are now log out' ), 'info') return redirect(url_for('auth.hello')) except UserException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('auth.hello'))
def delete_room(id): try: room.id = id room.delete() flash(gettext('Room Deleted'), 'success') return redirect(url_for('core.options')) except RoomException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.options'))
def delete_machine(id): try: machine.id = id machine.delete() flash(gettext('Machine Deleted'), 'success') return redirect(url_for('core.options')) except MachineException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.options'))
def delete_scenario(id): try: launcher.id = id launcher.delete() flash(gettext('Scenario deleted successfully !'),'success') return redirect(url_for('core.scenario')) except: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.scenario'))
def train_kernel(): try: bot = kernel_function.set() kernel_function.train(bot) flash(gettext('Kernel was train successfully'), "success") return redirect(url_for('core.index')) except Exception as e: flash(gettext('An error has occured !'), "error") return redirect(url_for('core.index'))
def update_data_git(): try: install.update_data() flash(gettext('Data Modified'), 'success') return redirect(url_for('core.options')) except DataException: flash(gettext('An error has occured'), 'error') return redirect(url_for('core.options'))
def reboot(): try: server.reboot() flash(gettext('Onyx is now rebooted !'),'success') return redirect(url_for('core.index')) except: flash(gettext('An error has occured !'),'error') return redirect(url_for('core.index'))
def update_skill(name): try: skill.name = name skill.update() flash(gettext('Skill Updated !'), 'success') return redirect(url_for('core.reboot_skill')) except SkillException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.reboot_skill'))
def delete_scenario(id): try: launcher.id = id launcher.delete() flash(gettext('Scenario deleted successfully !'), 'success') return redirect(url_for('core.scenario')) except: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.scenario'))
def maj(): try: server.update() flash(gettext("Onyx is now upgrade !"),'success') return redirect(url_for('core.options')) except ServerException: flash(gettext("An error has occured !"), 'error') return redirect(url_for('core.options'))
def update_skill(name): try: skill.name = name skill.update() flash(gettext('Skill Updated !'), 'success') return redirect(url_for('core.skills')) except Exception as e: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.skills'))
def delete_account(id_delete): try: user.id = id_delete user.delete() flash(gettext('Account deleted !') , 'success') return redirect(url_for('auth.account_manage')) except UserException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('auth.hello'))
def delete_house(id): try: house.id = id house.delete() flash(gettext('House Deleted'), 'success') return redirect(url_for('core.options')) except HouseException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.options'))
def change_lang(): try: options.lang = request.form.get('lang') options.change_lang() flash(gettext('The lang was changed ! If not please reboot Onyx') , 'success') return redirect(url_for('install.reboot', url='install.index', error_url='install.index')) except: flash(gettext('An error has occured !') , 'error') return redirect(url_for("install.index"))
def update_navbar(): try: navbar.last = request.form['last'] navbar.new = request.form['new'] navbar.set_navbar() flash(gettext('Modified'), 'success') return redirect(url_for('core.options')) except NavbarException: flash(gettext('An error has occured'), 'error') return redirect(url_for('core.options'))
def change_lang(): try: option.lang = request.form.get('lang') option.change_lang() flash(gettext('Please reboot Onyx to change language' ), 'success') return redirect(url_for('core.options')) except OptionsException: flash(gettext("An error has occured"), 'error') return redirect(url_for('core.options'))
def change_lang(): try: options.lang = request.form.get('lang') options.change_lang() refresh() flash(gettext('The lang was changed ! Please reboot Onyx now') , 'success') return redirect(url_for('install.reboot', url='install.index', error_url='install.index')) except: flash(gettext('An error has occured !') , 'error') return redirect(url_for("install.index"))
def add_room(): try: room.name = request.form['name'] room.house = request.form.get('house') room.add() flash(gettext('Room Add'), 'success') return redirect(url_for('core.options')) except RoomException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.options'))
def update_navbar(): try: navbar.last = request.form['last'] navbar.new = request.form['new'] navbar.set_navbar() flash(gettext('Modified'), 'success') return redirect(url_for('core.options')) except NavbarException: flash(gettext('An error has occured'), 'error') return redirect(url_for('core.options'))
def update_skill(name): try: skill.name = name skill.update() flash(gettext('Skill Updated !'), 'success') return redirect(url_for('reload', next='core.skills')) except Exception as e: flash(gettext('An error has occured !'), 'error') return redirect(url_for('reload', next='core.skills'))
def install_skill_url(): try: skill.name = request.form['name'] skill.url = request.form['url'] skill.install() flash(gettext('Skill Installed !'), 'success') return redirect(url_for('core.reboot_skill')) except SkillException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.reboot_skill'))
def add_room(): try: room.name = request.form['name'] room.house = request.form.get('house') room.add() flash(gettext('Room Add'), 'success') return redirect(url_for('core.options')) except RoomException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.options'))
def change_color(): try: devices.id = request.form['id'] devices.color = request.form['color_' + request.form['id']] devices.change_color() flash(gettext('Devices Modified'), 'success') return redirect(url_for('mi_light.index')) except DevicesException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('mi_light.index'))
def change_background(): try: option.user = current_user.id option.background = request.form.get('background') option.change_background_color() flash(gettext('Account changed successfully' ), 'success') return redirect(url_for('core.options')) except OptionsException: flash(gettext("An error has occured"), 'error') return redirect(url_for('core.options'))
def add_machine(): try: machine.name = request.form['name'] machine.house = request.form.get('house') machine.room = request.form.get('room') machine.host = request.form['host'] machine.add() flash(gettext('Machine Add'), 'success') return redirect(url_for('core.options')) except MachineException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.options'))
def redirect_to_onyx(): try: install = ConfigModel.Config.query.filter_by(config='install').first() install.value = 'True' db.session.add(install) db.session.commit() flash(gettext('Onyx is installed !'), 'success') return redirect(url_for('core.index')) except: flash(gettext('An error has occured !'), 'error') return redirect(url_for('install.index'))
def redirect_to_onyx(): try: install = ConfigModel.Config.query.filter_by(config='install').first() install.value = 'True' db.session.add(install) db.session.commit() flash(gettext('Onyx is installed !'), 'success') return redirect(url_for('core.index')) except: flash(gettext('An error has occured !'), 'error') return redirect(url_for('install.index'))
def add_house(): try: house.name = request.form['name'] house.address = request.form['address'] house.city = request.form['city'] house.postal = request.form['postal'] house.country = request.form['country'] house.latitude = request.form['latitude'] house.longitude = request.form['longitude'] house.add() flash(gettext('House Add'), 'success') return redirect(url_for('core.options')) except HouseException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.options'))
def uninstall_skill(name): try: skill.name = name result = skill.uninstall() json.json = result decoded = json.decode() if decoded['status'] == "success": flash(gettext('Skill Uninstalled !'), 'success') return redirect(url_for('core.skills')) else: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.skills')) except Exception as e: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.skills'))
def add_house(): try: house.name = request.form['name'] house.address = request.form['address'] house.city = request.form['city'] house.postal = request.form['postal'] house.country = request.form['country'] house.latitude = request.form['latitude'] house.longitude = request.form['longitude'] house.add() flash(gettext('House Add'), 'success') return redirect(url_for('core.options')) except HouseException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.options'))
def install_skill_url(): try: skill.name = request.form['name'] skill.url = request.form['url'] result = skill.install() json.json = result decoded = json.decode() if decoded['status'] == "success": flash(gettext('Skill Installed !'), 'success') return redirect(url_for('core.skills')) else: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.skills')) except Exception as e: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.skills'))
def index(): if request.method == 'GET': return render_template('install/index.html') elif request.method == 'POST': try: installation.username = request.form['username'] installation.password = request.form['password'] installation.email = request.form['email'] installation.set() house.name = request.form['name'] house.address = request.form['address'] house.city = request.form['city'] house.postal = request.form['postal'] house.country = request.form['country'] house.latitude = request.form['latitude'] house.longitude = request.form['longitude'] house.add() weather.token = request.form['weather_api'] weather.set_token() return redirect(url_for("install.redirect_to_onyx")) except Exception as e: flash(gettext('An error has occured !'), 'error') return redirect(url_for("install.index"))
def wiki(): if request.method == 'GET': return render_template('wiki/index.html', lang=lang[0]) elif request.method == 'POST': """ @api {post} /wiki Request Wiki Article @apiName getArticle @apiGroup Wiki @apiPermission authenticated @apiParam {String} search Search Input @apiSuccess (200) {Object[]} article List @apiSuccess (200) {String} article.head Header of Article @apiSuccess (200) {String} article.url Url of Article @apiSuccess (200) {String} article.summary Article Content @apiError NoExist No Article Exist """ try: wikipedia.lang = lang[0] wikipedia.search = request.form['search'] article = wikipedia.get_article() summary = wikipedia.get_summary() return render_template('wiki/result.html', head=article.title, url=article.url, summary=summary, lang=lang[0]) except WikiException: return render_template('wiki/result.html', head=gettext("Error"), summary=gettext("This is not an article"), lang=lang[0])
def finish_tutorial(): try: user.id = current_user.id return user.finish_tutorial() except: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.index'))
def wiki(): if request.method == 'POST': """ @api {post} /wiki Request Wiki Article @apiName getArticle @apiGroup Wiki @apiPermission authenticated @apiParam {String} search Search Input @apiSuccess (200) {Object[]} article List @apiSuccess (200) {String} article.head Header of Article @apiSuccess (200) {String} article.url Url of Article @apiSuccess (200) {String} article.summary Article Content @apiError NoExist No Article Exist """ try: wikipedia.lang = g.lang wikipedia.search = request.form['search'] article = wikipedia.get_article() summary = wikipedia.get_summary() return article except WikiException: return gettext("An error has occured !")
def add_scenario(): try: list = request.form.getlist(request.form.get('event_code') + '_param') template = " && ".join(list) launcher.template = template launcher.name = request.form.get('scenario') launcher.user = current_user.id launcher.event = request.form.get('event_code') launcher.action = request.form.get(request.form.get('action')) launcher.action_param = json.encode(request.form.getlist(request.form.get('action') + '_param')) launcher.add() flash(gettext('Scenario added successfully !'), 'success') return redirect(url_for('core.scenario')) except: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.scenario'))
def login(): if request.method == 'GET': return render_template('account/login.html') elif request.method == 'POST': try: user.email = request.form['email'] user.password = request.form['password'] login = user.login() if login == 0: flash(gettext('Incorrect email or password !'), 'error') return redirect(url_for('auth.login')) else: flash(gettext('You are now connected'), 'success') return redirect(request.args.get('next') or url_for('core.index')) except UserException: flash(gettext('An error has occured !'), 'error') return redirect(url_for('auth.hello'))
def register(): if request.method == 'GET': return render_template('account/register.html') elif request.method == 'POST': try: user.password = request.form['password'] user.verifpassword = request.form['verifpassword'] user.username = request.form['username'] user.email = request.form['email'] register = user.add() if register == 0: flash(gettext('Passwords are not same !' ), 'error') return redirect(url_for('auth.register')) elif register == 1: flash(gettext('Account Added !') , 'success') return redirect(url_for('auth.hello')) except UserException: flash(gettext('A Account with this informations already exist !'), 'error') return redirect(url_for('auth.hello'))
def wiki(): if request.method == 'POST': try: wikipedia.lang = g.lang wikipedia.search = request.form['search'] article = wikipedia.get_article() summary = wikipedia.get_summary() return article except WikiException: return gettext("An error has occured !")
def get_str(self): try: geoloc = Geolocalisation() self.latitude = geoloc.get_latitude() self.longitude = geoloc.get_longitude() json.url = "http://api.openweathermap.org/data/2.5/forecast/daily?lat=" + str(self.latitude) + "&lon=" + str(self.longitude) + "&cnt=14&mode=json&units=metric&lang=fr&appid=184b6f0b48a04263c59b93aee56c4d69" result = json.decode_url() return gettext('It is ') + str(round(result["list"][0]["temp"]["day"])) + gettext(" ° in ") + str(result["city"]["name"]) + " !" except Exception as e: logger.error('Getting weather error : ' + str(e)) raise WeatherException(str(e))
def kernel(): if request.method == 'POST': try: kernel_function.text = request.form['text'] result = kernel_function.get() json.json = result data = json.decode() return data['text'] except Exception as e: raise return gettext('An error has occured !')
def scenario(): try: json.json = events.get() events_decoded = json.decode() json.json = actions.get() actions_decoded = json.decode() return render_template('scenario/index.html', events=events_decoded, actions=actions_decoded) except: flash(gettext('An error has occured !'), 'error') return redirect(url_for('core.index'))
def wiki(): if request.method == 'GET': return render_template('wiki/index.html', lang=lang[0]) elif request.method == 'POST': try: wikipedia.lang = lang[0] wikipedia.search = request.form['search'] article = wikipedia.get_article() summary = wikipedia.get_summary() return render_template('wiki/result.html', head=article.title, url=article.url, summary=summary, lang=lang[0]) except WikiException: return render_template('wiki/result.html', head=gettext("Error"), summary=gettext("This is not an article"), lang=lang[0])
def index(): if request.method == 'GET': return render_template('install/index.html') elif request.method == 'POST': try: installation.username = request.form['username'] installation.password = request.form['password'] installation.email = request.form['email'] installation.set() return redirect(url_for("install.redirect_to_onyx")) except Exception as e: flash(gettext('An error has occured !') , 'error') return redirect(url_for("install.index"))
def calendar(id): if request.method == 'POST': try: checked = 'delete' in request.form if checked == True: events.user = current_user.id events.id = request.form['id'] events.delete() else: events.user = current_user.id events.id = request.form['id'] events.title = request.form['title'] events.notes = request.form['notes'] events.lieu = request.form['lieu'] events.color = request.form['color'] events.update_event() return redirect(url_for('core.calendars')) except CalendarException: flash(gettext('An error has occured'),'error') return redirect(url_for('core.calendars'))
def get_str(self): return gettext('He is actually ') + time.strftime("%H : %M")
def decorated(*args, **kwargs): if g.user.admin == 0: flash(gettext("You're not admin"), 'error') return redirect(url_for('core.index')) return f(*args, **kwargs)