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)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
|
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
|
||||||
deviceName = db.Column(db.String(64), unique=True)
|
deviceName = db.Column(db.String(64), unique=True)
|
||||||
|
connection = db.Column(db.Boolean)
|
||||||
|
|
||||||
class Calendar(db.Model):
|
class Calendar(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
|
@ -10,8 +10,6 @@ class LoginForm(FlaskForm):
|
|||||||
remember_me = BooleanField('Remember Me')
|
remember_me = BooleanField('Remember Me')
|
||||||
submit = SubmitField('Sign In')
|
submit = SubmitField('Sign In')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RegistrationForm(FlaskForm):
|
class RegistrationForm(FlaskForm):
|
||||||
username = StringField('Username', validators=[DataRequired()])
|
username = StringField('Username', validators=[DataRequired()])
|
||||||
email = StringField('Email', validators=[DataRequired(), Email()])
|
email = StringField('Email', validators=[DataRequired(), Email()])
|
||||||
@ -31,5 +29,5 @@ class RegistrationForm(FlaskForm):
|
|||||||
raise ValidationError('Please use a different email address.')
|
raise ValidationError('Please use a different email address.')
|
||||||
|
|
||||||
class DeviceForm(FlaskForm):
|
class DeviceForm(FlaskForm):
|
||||||
deviceId=StringField('New Device ID', validators=[DataRequired()])
|
deviceName=StringField('New Device ID', validators=[DataRequired()])
|
||||||
submit = SubmitField('Add New Device')
|
submit = SubmitField('Add New Device')
|
||||||
|
@ -52,15 +52,29 @@ def devices():
|
|||||||
if not current_user.is_authenticated:
|
if not current_user.is_authenticated:
|
||||||
return flask.render_template('login.html')
|
return flask.render_template('login.html')
|
||||||
|
|
||||||
device = Device()
|
# if this is a post request from the 'unlink' submittion form
|
||||||
device.deviceId="Anthon-Mouse-Car"
|
# delete this device from the list
|
||||||
devices = [device]
|
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()
|
form = DeviceForm()
|
||||||
if form.validate_on_submit():
|
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
|
# TODO add device to database here
|
||||||
|
db.session.commit()
|
||||||
return flask.render_template('devices.html', devices=devices, form=form)
|
return flask.render_template('devices.html',
|
||||||
|
devices=current_user.devices,
|
||||||
|
form=form)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/calendar")
|
@app.route("/calendar")
|
||||||
@ -89,6 +103,9 @@ def emaillogin():
|
|||||||
def register():
|
def register():
|
||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
return redirect(url_for('account'))
|
return redirect(url_for('account'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
form = RegistrationForm()
|
form = RegistrationForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
user = User(userid=form.username.data,
|
user = User(userid=form.username.data,
|
||||||
@ -105,16 +122,9 @@ def register():
|
|||||||
def deleteAccount():
|
def deleteAccount():
|
||||||
if not current_user.is_authenticated:
|
if not current_user.is_authenticated:
|
||||||
return redirect(url_for('account'))
|
return redirect(url_for('account'))
|
||||||
# TODO fix google delete account
|
|
||||||
if current_user.google_token != None:
|
if current_user.google_token != None:
|
||||||
google.deleteAccount(current_user)
|
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.delete(current_user)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
logout_user()
|
logout_user()
|
||||||
@ -199,7 +209,7 @@ def generateDeviceFingerprint():
|
|||||||
# check not in Device Database
|
# check not in Device Database
|
||||||
# Save as new Device
|
# Save as new Device
|
||||||
# Send to User
|
# Send to User
|
||||||
return jsonify(deviceId="Carrot-Enamel-Storm")
|
return jsonify(deviceName="Carrot-Enamel-Storm")
|
||||||
|
|
||||||
# POST
|
# POST
|
||||||
|
|
||||||
|
@ -10,16 +10,23 @@
|
|||||||
{% for item in devices %}
|
{% for item in devices %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<!--device id-->
|
<!--device id-->
|
||||||
<div style="width: 15rem; margin: 1rem;">{{ item.deviceId }}</div>
|
<div style="width: 15rem; margin: 1rem;">{{ item.deviceName }}</div>
|
||||||
|
|
||||||
<!--link status-->
|
<!--link status-->
|
||||||
<div style="width: 10rem; margin: 1rem; padding-right: 4rem">
|
<div style="width: 10rem; margin: 1rem; padding-right: 4rem">
|
||||||
|
{% if item.connection %}
|
||||||
Connected
|
Connected
|
||||||
|
{% else %}
|
||||||
|
Not Connected
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--action button-->
|
<!--action button-->
|
||||||
<div style="width: 4rem; margin: 1rem;">
|
<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>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -27,8 +34,8 @@
|
|||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
<div class="container grey" style="margin-top: 3rem;">
|
<div class="container grey" style="margin-top: 3rem;">
|
||||||
<div>{{ form.hidden_tag() }}</div>
|
<div>{{ form.hidden_tag() }}</div>
|
||||||
<div style="width: 7rem; margin: 1rem">{{ form.deviceId.label }}</div>
|
<div style="width: 7rem; margin: 1rem">{{ form.deviceName.label }}</div>
|
||||||
<div style="width: 12rem; margin: 1rem">{{ form.deviceId(size=24) }}</div>
|
<div style="width: 12rem; margin: 1rem">{{ form.deviceName(size=24) }}</div>
|
||||||
<div style="with: 7rem; margin: 1rem">{{ form.submit() }}</div>
|
<div style="with: 7rem; margin: 1rem">{{ form.submit() }}</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
Reference in New Issue
Block a user