diff --git a/database/migrations/versions/3b829a27bc337.py b/database/migrations/versions/3b829a27bc337.py deleted file mode 100644 index f204fe3..0000000 --- a/database/migrations/versions/3b829a27bc337.py +++ /dev/null @@ -1,23 +0,0 @@ -"""empty message - -Revision ID: 3b829a27bc337 -Revises: 1e8205594ac1 -Create Date: 2020-05-27 19:30:54.384047 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '3b829a27bc337' -down_revision = '1e8205594ac1' -branch_labels = None -depends_on = None - - -def upgrade(): - op.alter_column('User', 'google_credentials', existing_type=sa.Relationship(), new_column_name='google_token') - -def downgrade(): - op.alter_column('User', 'google_token', existing_type=sa.Relationship(), new_column_name='google_credentials') diff --git a/database/migrations/versions/e5ef5e4a807b_.py b/database/migrations/versions/e5ef5e4a807b_.py new file mode 100644 index 0000000..2f161bc --- /dev/null +++ b/database/migrations/versions/e5ef5e4a807b_.py @@ -0,0 +1,28 @@ +"""empty message + +Revision ID: e5ef5e4a807b +Revises: 1e8205594ac1 +Create Date: 2020-05-28 09:01:09.268270 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'e5ef5e4a807b' +down_revision = '1e8205594ac1' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('device', sa.Column('connection', sa.Boolean(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('device', 'connection') + # ### end Alembic commands ### diff --git a/database/models.py b/database/models.py index 35bbbd3..316cae5 100644 --- a/database/models.py +++ b/database/models.py @@ -60,6 +60,7 @@ class Device(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) deviceName = db.Column(db.String(64), unique=True) + connection = db.Column(db.Boolean) class Calendar(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) diff --git a/server/forms.py b/server/forms.py index 8d818c2..6ac20f1 100644 --- a/server/forms.py +++ b/server/forms.py @@ -10,8 +10,6 @@ class LoginForm(FlaskForm): remember_me = BooleanField('Remember Me') submit = SubmitField('Sign In') - - class RegistrationForm(FlaskForm): username = StringField('Username', validators=[DataRequired()]) email = StringField('Email', validators=[DataRequired(), Email()]) @@ -31,5 +29,5 @@ class RegistrationForm(FlaskForm): raise ValidationError('Please use a different email address.') class DeviceForm(FlaskForm): - deviceId=StringField('New Device ID', validators=[DataRequired()]) + deviceName=StringField('New Device ID', validators=[DataRequired()]) submit = SubmitField('Add New Device') diff --git a/server/routes.py b/server/routes.py index 97030bd..ac518d7 100644 --- a/server/routes.py +++ b/server/routes.py @@ -51,16 +51,30 @@ def view(): def devices(): if not current_user.is_authenticated: return flask.render_template('login.html') - - device = Device() - device.deviceId="Anthon-Mouse-Car" - devices = [device] + + # if this is a post request from the 'unlink' submittion form + # delete this device from the list + if request.method == 'POST': + if request.form.get("submit") == "Unlink": + device = db.session.query(Device).filter(Device.deviceName==request.form.get("device")).first() + db.session.delete(device) + db.session.commit() + + # if this is part of the device form + # TODO add this device to the user - do not create new device form = DeviceForm() if form.validate_on_submit(): - print(form.deviceId.data, flush=True) + print(form.deviceName.data, flush=True) + device = Device() + device.deviceName = form.deviceName.data + device.connection = False + db.session.add(device) + current_user.devices.append(device) # TODO add device to database here - - return flask.render_template('devices.html', devices=devices, form=form) + db.session.commit() + return flask.render_template('devices.html', + devices=current_user.devices, + form=form) @app.route("/calendar") @@ -89,6 +103,9 @@ def emaillogin(): def register(): if current_user.is_authenticated: return redirect(url_for('account')) + + + form = RegistrationForm() if form.validate_on_submit(): user = User(userid=form.username.data, @@ -105,16 +122,9 @@ def register(): def deleteAccount(): if not current_user.is_authenticated: return redirect(url_for('account')) - # TODO fix google delete account if current_user.google_token != None: google.deleteAccount(current_user) - ''' - for cal in current_user.calendars: - db.session.delete(cal) - for dev in current_user.devices: - db.session.delete(dev) - db.session.delete(current_user.google_token) - ''' + db.session.delete(current_user) db.session.commit() logout_user() @@ -199,7 +209,7 @@ def generateDeviceFingerprint(): # check not in Device Database # Save as new Device # Send to User - return jsonify(deviceId="Carrot-Enamel-Storm") + return jsonify(deviceName="Carrot-Enamel-Storm") # POST diff --git a/server/template/devices.html b/server/template/devices.html index a9249aa..fcfd7d4 100644 --- a/server/template/devices.html +++ b/server/template/devices.html @@ -10,16 +10,23 @@ {% for item in devices %}
-
{{ item.deviceId }}
+
{{ item.deviceName }}
- Connected + {% if item.connection %} + Connected + {% else %} + Not Connected + {% endif %}
- +
+ + +
@@ -27,8 +34,8 @@
{{ form.hidden_tag() }}
-
{{ form.deviceId.label }}
-
{{ form.deviceId(size=24) }}
+
{{ form.deviceName.label }}
+
{{ form.deviceName(size=24) }}
{{ form.submit() }}