def post(self): try: args = self.parser.parse_args() password = args['password'] verifPassword = args['verifPassword'] last_user = get_jwt_identity() if sha256_crypt.verify(verifPassword, last_user['password']): user = User.query.filter_by(id=last_user['id']).first() user.email = args['email'] user.username = args['username'] user.language = args['language'] user.firstname = args['firstname'] user.lastname = args['lastname'] if password != '': user.password = sha256_crypt.hash(args['password']) db.session.add(user) db.session.commit() access_token = create_access_token(identity=to_dict(user)) refresh_token = create_refresh_token(identity=to_dict(user)) return jsonify(status="success", access_token=access_token, refresh_token=refresh_token) else: return jsonify(status="error", message="onyx.auth.password_mismatch") except Exception as e: return jsonify(status="error", message="onyx.global.error")
def post(self): try: args = self.parser.parse_args() email = args['email'] password = args['password'] user = User.query.filter_by(email=email).first() if user: if sha256_crypt.verify(password, user.password): access_token = create_access_token(identity=to_dict(user)) refresh_token = create_refresh_token( identity=to_dict(user)) return jsonify(status="success", access_token=access_token, refresh_token=refresh_token, user=to_dict(user)) else: return jsonify(status="error", message="onyx.auth.login_error") else: return jsonify(status="error", message="onyx.auth.login_error") except Exception as e: return jsonify(status="error", message="onyx.global.error"), 500
def get(self): try: tokens = [to_dict(token) for token in TokenModel.query.all()] return jsonify(status="success", tokens=tokens) except Exception as e: return jsonify(status="error", message="{}".format(e))
def get(self): try: user = get_jwt_identity() notifications = [to_dict(notification) for notification in NotifModel.query.filter_by(user=user['id']).limit(50)] return jsonify(status="success", notifications=notifications) except Exception as e: return jsonify(status="error", message="{}".format(e))
def get(self): try: users = [to_dict(user) for user in User.query.all()] if len(users) > 0: return jsonify(status="success", isInstalled="true") return jsonify(status="success", isInstalled="false") except Exception as e: return jsonify(status="error", message="{}".format(e))
def post(self): try: args = self.parser.parse_args() _id = args['id'] return jsonify(to_dict(User.query.filter_by(id=_id).first())) except Exception as e: return jsonify(status="error", message="{}".format(e)), 500
def get(self): try: user = get_jwt_identity() nav = [] with open('onyx/utils/colors.json') as json_file: colors = json.load(json_file) for i in range(1, 6): for k in range(1, 8): nav.append({ 'buttonNumber': str(i), 'position': str(k), 'url': "", 'color': colors[user['color']]['secondary_color'], 'icon': "fa fa-plus" }) nav_all = [ to_dict(nav) for nav in NavModel.query.filter_by(user=user['id']).limit(50) ] buttons = [ to_dict(button) for button in ButtonsModel.query.filter_by( user=user['id']).limit(50) ] for i in range(len(nav_all)): for k in range(len(nav)): if nav[k]['buttonNumber'] == nav_all[i][ 'buttonNumber'] and nav[k]['position'] == nav_all[ i]['position']: nav[k] = nav_all[i] return jsonify(status="success", nav=nav, buttons=buttons) except Exception as e: return jsonify(status="error", message="{}".format(e))
def get(self): try: user = get_jwt_identity() events = [ to_dict(event) for event in CalendarModel.query.filter( CalendarModel.user.endswith(str(user['id']))).all() ] return jsonify(status="success", events=events) except Exception as e: return jsonify(status="error", message="{}".format(e)), 500
def connected_app(app): """A Webtest app with connected user.""" test_app = TestApp(app) user = User(username='******', color='blue', mode='light', email='*****@*****.**', password=sha256_crypt.hash("123456"), firstname="User", lastname="Name", language="en-US") _db.session.add(user) _db.session.commit() access_token = create_access_token(identity=to_dict(user)) refresh_token = create_refresh_token(identity=to_dict(user)) test_app.authorization = ('Bearer', access_token) yield test_app
def get(self): try: user = get_jwt_identity() all_widgets = [ to_dict(widget) for widget in WidgetModel.query.filter_by( user=user['id']).limit(100) ] return jsonify(status="success", widgets=all_widgets) except Exception as e: print(e) return jsonify(status="error", message="{}".format(e))
def get(self): try: user = get_jwt_identity() id = user['id'] new_user = User.query.filter_by(id=id).first() return jsonify( status="success", access_token=create_access_token(identity=to_dict(new_user))) except Exception as e: return jsonify(status="error", message="{}".format(e)), 500
def get(self): try: user = get_jwt_identity() today_events = [] today = str(datetime.now()).split(" ")[0] all_events = [ to_dict(event) for event in CalendarModel.query.filter( CalendarModel.user.endswith(str(user['id']))).all() ] for event in all_events: event_date = event['start'].split("T")[0] if (today == event_date): today_events.append(event) return jsonify(status="success", events=today_events) except Exception as e: return jsonify(status="error", message="{}".format(e)), 500
def post(self): try: args = self.parser.parse_args() system = {"id": 0, "name": "onyx"} name = args['name'] token = create_access_token(identity=to_dict(system), expires_delta=False) try: query = TokenModel(name=name, token=token) db.session.add(query) db.session.commit() return jsonify(status="success") except Exception as e: print(e) return jsonify(status="error") except Exception as e: print(e) return jsonify(status="error", message="{}".format(e)), 500
def get(self): try: user = get_jwt_identity() all_screen = [ to_dict(screen) for screen in ScreenModel.query.filter_by( user=user['id']).limit(100) ] layouts_query = ScreenLayoutsModel.query.filter_by( user=user['id']).first() if layouts_query is None: layouts = "[]" else: layouts = layouts_query.layouts return jsonify(status="success", screen=all_screen, layouts=layouts) except Exception as e: print(e) return jsonify(status="error", message="{}".format(e))
def get(self): try: return jsonify([to_dict(user) for user in User.query.all()]) except Exception as e: return jsonify(status="error", message="{}".format(e)), 500