def device_delete(device_id):
    # GET THE DEVICE REQUESTED
    device = db_session.query(Device).get(device_id)
    # CHECK IF CURRENT USER IS OWNER
    if device == None or device.user != current_user:
        return abort(401)
    # DELETE THE DEVICE
    db_session.delete(device)
    db_session.commit()
    return redirect(url_for('management.gen_panel'))
def trigger_delete(trigger_id):
    # GET THE TRIGGER REQUESTED
    trigger = db_session.query(Trigger).get(trigger_id)
    # CHECK IF THE CURRENT USER IS THE OWNER OF THE TRIGGER/DEVICE
    if trigger == None or trigger.device.user != current_user:
        return abort(401)
    # DELETE THE TRIGGER
    db_session.delete(trigger)
    db_session.commit()
    return redirect(url_for('management.device_panel', device_id=trigger.device.id))
Exemplo n.º 3
0
 def test_signup(self):
     credentials = {
         'email': self.user_email,
         'password': self.user_password
     }
     resp = self.app.post('/signup',
                          follow_redirects=True,
                          data=credentials)
     self.assertEqual(resp.status_code, 200)
     self.assertIsNotNone(
         db_session.query(User).filter_by(
             email=credentials['email']).first())
Exemplo n.º 4
0
 def test_create_device(self):
     self.create_user()
     self.login()
     data = {
         'device_code': 'sadfkasdkjasldfjla',
         'name': self.device_name,
         'desc': 'fsadfsa dfs alkdjfsajdfkjaslkdfjlasdj kfaj kasdjfk'
     }
     resp = self.app.post('/management/panel',
                          follow_redirects=True,
                          data=data)
     self.assertEqual(resp.status_code, 200)
     self.assertIsNotNone(
         db_session.query(Device).filter_by(name=self.device_name).first())
Exemplo n.º 5
0
 def test_create_trigger(self):
     user = self.create_user()
     self.login()
     device = self.create_device(user)
     credentials = {
         'trigger_type': '0',
         'name': self.trigger_name,
         'desc': 'fsadfsa dfs alkdjfsajdfkjaslkdfjlasdj kfaj kasdjfk'
     }
     resp = self.app.post('/management/panel/{0}'.format(device.id),
                          follow_redirects=True,
                          data=credentials)
     self.assertEqual(resp.status_code, 200)
     self.assertIsNotNone(
         db_session.query(Trigger).filter_by(
             name=credentials['name']).first())
def login():
    form = LoginForm()
    # redirect if alread authenticated
    if current_user.is_authenticated:
        return redirect(url_for('management.gen_panel'))

    # Check if post request and if form is filled
    if request.method == 'POST' and form.validate_on_submit():
        user = db_session.query(User).filter_by(email=form.email.data).first()
        # check hash
        if user and user.check_password(form.password.data):
            # create new session
            login_user(user)
            return redirect(url_for('management.gen_panel'))
        else:
            flash("Invalid login details")

    return render_template('login.html', form=form)
def device_panel(device_id):
    # GET THE DEVICE REQUESTED
    device = db_session.query(Device).get(device_id)
    # CHECK IF CURRENT USER IS OWNER
    if device == None or device.user != current_user:
        return abort(401)
    # CREATE FORM FOR CREATING TRIGGER
    form = CreateTriggerForm()
    # CHECK IF VALID TIRGGER CREATION REQUEST
    if request.method == 'POST' and form.validate_on_submit():
        # CREATE NEW TRIGGER
        new_trigger = Trigger(
            device=device,
            trigger_type=Trigger_Types(int(form.trigger_type.data)).name,
            name=form.name.data,
            desc=form.desc.data
        )
        db_session.add(new_trigger)
        db_session.commit()
        return redirect(url_for('management.device_panel', device_id=device_id))
    return render_template('device_panel.html', form=form, device=device)
Exemplo n.º 8
0
 def validate_email(self, email):
     user = db_session.query(User).filter_by(email=self.email.data).first()
     if user:
         raise ValidationError(
             'That email is already in use by a different account.')