コード例 #1
0
    def create(self, params, meta, **kwargs):
        kwargs['consumer_id'] = kwargs['validated']['consumer_id']
        project = self.db.get(Project, _id=kwargs['project_id'])

        if not project:
            raise (HTTPNotFound(description="There is no such project  !"))
        if not project.is_user_limit_available():
            raise HTTPPaymentRequired(
                description="Please check your project user limit")
        consumer_exist = self.db.exists(
            model=Consumer,
            _id=kwargs['consumer_id'],
            account_id=kwargs['token']['account_id'])
        if not consumer_exist:
            raise (HTTPNotFound(description="There is  no such consumer !"))
        attached_consumer = self.db.get_attached_consumer(
            kwargs['consumer_id'], kwargs['project_id'])
        if attached_consumer:
            raise (HTTPConflict(
                description="These consumer already attached this project"))

        project.user_used = Project.user_used + 1
        project_consumer = ProjectConsumer(consumer_id=kwargs['consumer_id'],
                                           project_id=kwargs['project_id'])
        self.db.session.add(project_consumer)
        return {"consumer_id": kwargs['consumer_id']}
コード例 #2
0
ファイル: __init__.py プロジェクト: osmontrouge/addok-getbyid
 def on_get(self, req, resp, doc_id):
     try:
          result = core.Result.from_id(doc_id)
          resp.body = json.dumps(result.format())
          resp.content_type = 'application/json; charset=utf-8'
     except ValueError:
          raise HTTPNotFound()
コード例 #3
0
 def on_get(self, req, resp, test_id):
     time.sleep(MAX_SLEEP_TIME)
     try:
         resource = get_resource(test_id)
     except StopIteration:
         raise HTTPNotFound()
     resp.body = json.dumps(resource)
コード例 #4
0
    def update(self, params, meta, **kwargs):
        registration_id = kwargs['registration_id']
        validated = kwargs['validated']
        hashed_password = data_hashing(validated['password'])

        account = self.db.get(Account, is_active=False, _id=registration_id)
        if account is None:
            raise HTTPNotFound(
                description=
                "The account does not exist by given registration_id or already activated."
            )

        if account.approve_code == validated['approve_code']:
            admin = User(email=validated['email'],
                         password=hashed_password,
                         role=ERoles.admin,
                         first_name=validated['first_name'],
                         last_name=validated['last_name'],
                         account_id=account.id)

            account.is_active = True
            self.db.session.add(admin)
            token_payload = create_auth_token_payload(
                admin.id, role=admin.role, account_id=admin.account_id)
            token = encode_jwt_token(token_payload)
            add_user_token(admin.id, token)
            return {
                "token": token,
                "id": admin.id,
                "email": admin.email,
                "first_name": admin.first_name,
                "last_name": admin.last_name
            }
        else:
            raise HTTPConflict(description="Approve code does not match.")
コード例 #5
0
 def on_put(self, req, resp, test_id):
     resp.status = falcon.HTTP_204
     payload = json.loads(req.stream.read())
     if '_id' not in payload or not isinstance(payload.get('_id'), str):
         raise HTTPBadRequest()
     try:
         update_resource(test_id, payload)
     except StopIteration:
         raise HTTPNotFound()
コード例 #6
0
ファイル: login.py プロジェクト: snowsky/zops-platform
    def update(self, params, meta, **kwargs):
        reset_token = kwargs['validated']['reset_token']
        password = kwargs['validated']['password']
        if not remove_reset_password_token(reset_token):
            raise HTTPNotFound(description="Invalid reset token")

        payload = decode_jwt_token(reset_token, "resetToken")
        user = self.db.get_object(User, email=payload['email'])
        hashed_password = data_hashing(password)
        user.password = hashed_password
コード例 #7
0
    def delete(self, params, meta, **kwargs):
        project = self.db.get(Project, _id=kwargs['project_id'])

        if not project:
            raise HTTPNotFound(description="There is no such project  !")

        consumer_exist = self.db.exists(
            model=Consumer,
            _id=kwargs['consumer_id'],
            account_id=kwargs['token']['account_id'])
        if not consumer_exist:
            raise HTTPNotFound(description="There is no such consumer !")

        attached_consumer = self.db.get_attached_consumer(
            kwargs['consumer_id'], kwargs['project_id'])
        if not attached_consumer:
            raise HTTPNotFound(description="There is no such attachment")

        self.db.session.delete(attached_consumer)
        project.user_used = Project.user_used - 1
コード例 #8
0
    def __call__(self, req, resp, product_id):
        db_session = req.context["db_session"]
        try:
            product = db_session.query(Product).filter_by(id=int(product_id)).one()
        except NoResultFound:
            raise HTTPNotFound()
        else:
            products = db_session.query(Product).order_by(Product.order, Product.id).all()

            return self.render_template(
                req, resp, "downloads/index.html",
                product=product,
                products=products
            )
コード例 #9
0
    def delete_admin(self, user_id, account_id, role):
        """
        Delete admin user. If account has only one admin user then deletion rejected. Because of every account
        must have at least one admin user

        :param user_id: want to delete user's id
        :param account_id: user's account id
        :param role:User role : admin
        """
        admins = self.filter(model=User, account_id=account_id, role=role)
        if len(admins) > 1:
            self.delete_user(user_id, account_id)
        else:
            raise HTTPNotFound(description="Deletion not completed.Your account only have 1 admin user.")
コード例 #10
0
    def __call__(self, req, resp, post_id):
        db_session = req.context["db_session"]
        news_posts = db_session.query(NewsPost).filter_by(published=True).order_by(NewsPost.posted.desc())[0:3]

        try:
            news_post = db_session.query(NewsPost).filter_by(id=post_id, published=True).one()
        except NoResultFound:
            raise HTTPNotFound()

        if news_post.summary is None:
            markdown = Markdown(news_post.markdown)
            news_post.summary = markdown.summary

        self.render_template(
            req, resp, "news_view.html",
            post=news_post,
            news_posts=news_posts
        )
コード例 #11
0
 def create(self, params, meta, **kwargs):
     email = kwargs['validated']['email']
     testing = params.get('testing')
     account = self.db.get_account_with_email(email)
     if account:
         new_approve_code = generate_token()
         account.approve_code = new_approve_code
         mail_response = send_account_approve_mail(new_approve_code, email,
                                                   account.id, testing)
         email_object = Email(provider_mail_id=mail_response['id'],
                              account_id=account.id,
                              text=mail_response['text'],
                              subject=mail_response['subject'],
                              receiver=email,
                              provider="MAILGUN",
                              category="approve")
         self.db.session.add(email_object)
     else:
         raise HTTPNotFound(
             description="These email address does not exist")
コード例 #12
0
ファイル: responders.py プロジェクト: lumberj/falcon
def path_not_found(req, resp, **kwargs):
    """Raise 404 HTTPNotFound error"""
    raise HTTPNotFound()
コード例 #13
0
ファイル: errors.py プロジェクト: RamuSannanagari/GUIDE_API
 def error_method_not_supported(allowed_methods, error = ERR_NOT_SUPPORTED , description=None):
     raise HTTPNotFound(allowed_methods,title=error.get('title'),description = description , code = error.get('code'))
コード例 #14
0
    def get_object(self, model, **kwargs):
        obj = self.get(model=model, **kwargs)
        if obj:
            return obj

        raise HTTPNotFound(description="Resource object does not exist.")
コード例 #15
0
 def on_delete(self, req, resp, test_id):
     resp.status = falcon.HTTP_204
     try:
         delete_resource(test_id)
     except StopIteration:
         raise HTTPNotFound()