adds device handling functionality from the browser
This commit is contained in:
parent
5d1edbc6fc
commit
7b82086ff0
@ -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')
|
28
database/migrations/versions/e5ef5e4a807b_.py
Normal file
28
database/migrations/versions/e5ef5e4a807b_.py
Normal file
@ -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 ###
|
@ -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)
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
|
||||
|
@ -10,16 +10,23 @@
|
||||
{% for item in devices %}
|
||||
<div class="container">
|
||||
<!--device id-->
|
||||
<div style="width: 15rem; margin: 1rem;">{{ item.deviceId }}</div>
|
||||
<div style="width: 15rem; margin: 1rem;">{{ item.deviceName }}</div>
|
||||
|
||||
<!--link status-->
|
||||
<div style="width: 10rem; margin: 1rem; padding-right: 4rem">
|
||||
Connected
|
||||
{% if item.connection %}
|
||||
Connected
|
||||
{% else %}
|
||||
Not Connected
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!--action button-->
|
||||
<div style="width: 4rem; margin: 1rem;">
|
||||
<button type="button">Unlink</button>
|
||||
<form action="" method="post">
|
||||
<input type="hidden" name="device" value={{ item.deviceName }}>
|
||||
<input type="submit" name="submit" value="Unlink">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@ -27,8 +34,8 @@
|
||||
<form action="" method="post">
|
||||
<div class="container grey" style="margin-top: 3rem;">
|
||||
<div>{{ form.hidden_tag() }}</div>
|
||||
<div style="width: 7rem; margin: 1rem">{{ form.deviceId.label }}</div>
|
||||
<div style="width: 12rem; margin: 1rem">{{ form.deviceId(size=24) }}</div>
|
||||
<div style="width: 7rem; margin: 1rem">{{ form.deviceName.label }}</div>
|
||||
<div style="width: 12rem; margin: 1rem">{{ form.deviceName(size=24) }}</div>
|
||||
<div style="with: 7rem; margin: 1rem">{{ form.submit() }}</div>
|
||||
</div>
|
||||
</form>
|
||||
|
Loading…
Reference in New Issue
Block a user