Skip to content

Commit

Permalink
Save twitch id to database
Browse files Browse the repository at this point in the history
  • Loading branch information
rishubil committed Sep 21, 2019
1 parent 43d04b4 commit 7a865b0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/flask/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def json(self):
class User(UserMixin, SerializableMixin, db.Model):
__tablename__ = "user"
id = db.Column(db.Integer, primary_key=True)
twitch_id = db.Column(db.String(120), nullable=False)

def json(self):
data = self._serialize()
Expand Down
5 changes: 4 additions & 1 deletion backend/flask/app/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ def twitch_logged_in(blueprint, token):
oauth = OAuth(provider=blueprint.name, provider_user_id=user_id, token=token)

if not oauth.user:
user = User()
user = User(twitch_id=user_id)
oauth.user = user
db.session.add_all([user, oauth])
db.session.commit()
else:
oauth.user.twitch_id = user_id
db.session.commit()

login_user(oauth.user)
flash("성공적으로 로그인했습니다.")
Expand Down
4 changes: 2 additions & 2 deletions backend/flask/app/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ def connect_handler():

@socketio.on('message', namespace='/recognition')
def handle_message(message):
if current_user.oauth:
send(message, json=True, broadcast=True, namespace=f'/overlay/{current_user.oauth[0].provider_user_id}')
if current_user.twitch_id:
send(message, json=True, broadcast=True, namespace=f'/overlay/{current_user.twitch_id}')
29 changes: 29 additions & 0 deletions backend/flask/migrations/versions/763fc9f85cf2_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""empty message
Revision ID: 763fc9f85cf2
Revises: 59f3082483dd
Create Date: 2019-09-21 17:15:08.386984
"""
from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils


# revision identifiers, used by Alembic.
revision = '763fc9f85cf2'
down_revision = '59f3082483dd'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('user', sa.Column('twitch_id', sa.String(length=120), nullable=False, server_default=''))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('user', 'twitch_id')
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion frontend/recognition.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="root-container">
<div class="links">
<div>오버레이 주소: <a target="_blank"
href="{{ url_for('overlay', _external=True) }}?channel={{ current_user.oauth|first|attr("provider_user_id") }}">{{ url_for('overlay', _external=True) }}?channel={{ current_user.oauth|first|attr("provider_user_id") }}</a>
href="{{ url_for('overlay', _external=True) }}?channel={{ current_user.twitch_id }}">{{ url_for('overlay', _external=True) }}?channel={{ current_user.twitch_id }}</a>
</div>
<div><a href="{{ url_for('logout') }}">로그인 정보 갱신</a></div>
</div>
Expand Down

0 comments on commit 7a865b0

Please sign in to comment.