Exemple #1
0
    def post(self):
        vSchema = VendorSchema()
        try:
            vendor = vSchema.load(api.payload)
            check = Vendor.query.filter_by(Email=vendor["Email"]).first()
            if not check:
                try:
                    new_vendor = Vendor(
                        name=vendor["name"],
                        password=vendor["password"],
                        location=vendor["location"],
                        Email=vendor["Email"],
                        company_number=vendor["company_number"])

                    db.session.add(new_vendor)
                    db.commit(new_vendor)
                    return ({"message": f"Account created"}, 201)
                except IntegrityError:
                    db.session.rollback()
                    return {
                        "message":
                        "phone number already exists select a different one"
                    }
            else:
                return {
                    "message": "Email already exists select a different one"
                }
        except ValidationError as err:
            return {"message": err.message}
Exemple #2
0
    def register():
        email = request.form['email']
        email2 = request.form['email2']

        if email != email2:
            flash('Emails do not match')
            return redirect(request.path)

        password = request.form['password']
        password2 = request.form['password2']

        if password != password2:
            flash('Passwords do not match')
            return redirect(request.path)

        users = db.query(User.id).filter(User.email == email).all()
        if len(users) > 0:
            flash('Email already registered')
            return redirect(request.path)

        user = User(email, password)
        db.add(user)
        db.commit()

        g.session['user'] = user

        return redirect('/')
Exemple #3
0
    def api_device(method, id, payload=None):
        """Retrieve device info, update its attributes, or delete a device for
        the current user."""
        device = Device.load(id)
        app.logger.debug(device)
        if (device is None or
            device.uid != g.user.id
           ):
            abort(404)

        if method == 'GET':
            return device

        elif method == 'POST':
            if 'name' in payload:
                device.name = payload['name']
            if 'push_id' in payload:
                device.push_id = payload['push_id']

            try:
                db.add(device)
                db.commit()
            except IntegrityError:
                abort(400, 'Device name already exists')

            return device

        elif method == 'DELETE':
            db.delete(device)
            db.commit()
            return True
Exemple #4
0
def delete_instance(app_id, instance_id):
    app = db.query(App).get(app_id)
    instance = app.instance(instance_id)

    if instance and instance.status != 'Running' and not instance.is_live:
        docker.rm(instance.container_id)
        db.delete(instance)
        db.commit()

    return redirect_to_app_page(app)
Exemple #5
0
    def api_user_register(method, email, password):
        users = db.query(User.id).filter(User.email == email).all()
        if len(users) > 0:
            abort(400, 'Email already registered')

        user = User(email, password)
        db.add(user)
        db.commit()

        return user
Exemple #6
0
def go_live(app_id, instance_id):
    app = db.query(App).get(app_id)
    instance = app.instance(instance_id)

    if instance and instance.status == 'Running':
        for i in app.instances:
            i.is_live = False
        instance.is_live = True

        f = app.app_type()
        f.create_front_end(instance.container_id, app.url[7:])

        db.commit()        

    return redirect_to_app_page(app)
Exemple #7
0
def create_image(app_id):
    app = db.query(App).get(app_id)
    form = create_new_image_form(app, request.form)

    if form.validate():
        app_image = AppImage(name=form.image_name.data, status='Pending build since %s' % datetime.now().strftime('%Y-%m-%d %H:%M:%S'), app=app)
        db.add(app_image)
        db.flush()
        params = extract_build_params(app, app_image, form)
        app_image.params_json = json.dumps(params)
        db.commit()

        tasks.build_image.delay(app_image.id)

        return redirect_to_app_page(app)
    else:
        return render_template('createImage.html', app=app, current_tab='apps', form=form)
Exemple #8
0
    def api_devices_register(method, payload):
        """Register a new device."""

        if 'name' in payload:
            try:
                device = Device(g.user, payload['name'])
                if 'push_id' in payload:
                    device.push_id = payload['push_id']

                db.add(device)
                db.commit()

                return {
                    'api_key': device.api_key,
                    'device': device,
                }
            except IntegrityError:
                abort(400, 'Device name already exists')

        abort(400, 'Missing payload parameters')
Exemple #9
0
def google_login_landing():
    flow = get_flow()
    code = request.args.get('code')
    credentials = flow.step2_exchange(code)

    profile = get_api(credentials).userinfo().get().execute()

    email, name = profile['email'], profile['name']

    user = db.query(User).get(email)

    if user is None:
        user = User(email=email, name=name)
        db.add(user)
        db.commit()

    session = request.environ['beaker.session']
    session['username'] = user.email
    session.save()

    return redirect('/')
Exemple #10
0
def create_app():
    app_id = slugify(request.form['newAppName'])
    app = App(id=app_id, name=request.form['newAppName'], app_type_id=request.form['appType'], owner=current_user)
    db.add(app)
    db.commit()
    return redirect('/')