def enable(): username = request.args.get('username') to_enable = request.args.get('to_enable') token = request.args.get('token') try: with transaction() as db: if not verify_basic_auth(request) or not is_admin(db, token): return create_respond(error=UserAuthErrors.NOT_AUTHORIZED) return update_respond(USER_NOT_FOUND) if not enable_user(db, username, to_enable == '1') else update_respond() except IntegrityError as e: return update_respond('Internal Error')
def create(): user: User = str_to_user(request.args.get('user')) token = request.args.get('token') try: with transaction() as db: if not verify_basic_auth(request) or not is_admin(db, token): return create_respond(error=UserAuthErrors.NOT_AUTHORIZED) msg = validate(user, get_settings(db), user.password, db) return create_respond(insert_user(db, user)) if msg == VALID else create_respond(error=msg) except IntegrityError: return create_respond(error='the username is already in used, choose other')
def post(self): user = str_to_user(self.get_argument('user')) token = self.get_argument('token') try: with transaction() as db: if not verify_basic_auth(self) or not is_admin(db, token): return respond(NOT_AUTHORIZED) # self.res(verify_basic_auth(self, create_user_service, db, token, user)) except IntegrityError: self.error('the username is already in used, choose other')
def post(self): if not self.is_authenticated(): return token = self.get_argument('token') auth_settings = str_to_auth_settings(self.get_argument('auth_settings')) with transaction() as db: if is_admin(db, token): db.add(auth_settings) db.commit() self.res(dict(success=True)) else: self.error(NOT_AUTHORIZED)
def post(self): if not self.is_authenticated(): return token = self.get_argument('token') with transaction() as db: if is_admin(db, token): auth = get_settings(db) response = dict(auth.__dict__) response.pop('_sa_instance_state', None) response.pop('creation_datetime', None) response.pop('id', None) self.res(response) else: self.error(NOT_AUTHORIZED)
def post(self): username = self.get_argument('username') to_enable = self.get_argument('to_enable') token = self.get_argument('token') try: with transaction() as db: if is_admin(db, token): success = enable_user(db, username, to_enable == '1') if not success: self.error(USER_NOT_FOUND) else: self.res(res()) else: self.error(NOT_AUTHORIZED) except IntegrityError as e: self.error('Internal Error')
def reset(): if not self.is_authenticated(): return username = self.get_argument('username') new_password = self.get_argument('new_password') token = self.get_argument('token') try: with transaction() as db: if is_admin(db, token): user = get_user_by_username(db, username) response = validate(user, get_settings(db), new_password, db) if response['success']: change_password(db, user, new_password, get_settings(db)) self.res(response) else: self.error(NOT_AUTHORIZED) except IntegrityError as e: self.error('Internal Error')