Beispiel #1
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('/')
Beispiel #2
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
Beispiel #3
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
Beispiel #4
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)
Beispiel #5
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')
Beispiel #6
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('/')
Beispiel #7
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('/')