Skip to content
This repository has been archived by the owner on Oct 14, 2021. It is now read-only.

Commit

Permalink
interim commit of chatroom example
Browse files Browse the repository at this point in the history
  • Loading branch information
amitnabarro committed May 1, 2018
1 parent 12388d3 commit 5a768df
Show file tree
Hide file tree
Showing 47 changed files with 20,912 additions and 8 deletions.
7 changes: 7 additions & 0 deletions examples/chatrooms/backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
ACCESS_PROTECTED = 20
ACCESS_PRIVATE = 30

STATUS_AVAILABLE = 10
STATUS_AWAY = 20
STATUS_OFFLINE = 30


class BaseModel(Model, MongoCollectionMixin):
_id = ObjectIdField(primary_key=True)
Expand All @@ -29,8 +33,10 @@ class User(BaseModel):
username = StringField(required=True)
first_name = StringField()
last_name = StringField()
display_name = StringField()
avatar = URLField()
active = BooleanField(default=True)
status = IntegerField(default=STATUS_OFFLINE, choices=[STATUS_AVAILABLE, STATUS_AWAY, STATUS_OFFLINE])

class Meta:
name = 'users'
Expand All @@ -46,6 +52,7 @@ class Meta:
class Room(BaseModel):
name = StringField(primary_key=True)
title = StringField()
default = BooleanField(default=False) # new users will be added to this channel as they join in
active = BooleanField(default=True)
access = IntegerField(default=ACCESS_PUBLIC, choices=[ACCESS_PUBLIC, ACCESS_PROTECTED, ACCESS_PRIVATE])
owner = DBRefField(User, required=True)
Expand Down
3 changes: 2 additions & 1 deletion examples/chatrooms/backend/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ async def is_authenticated(self, request):
if 'user' in request:
return True
if 'Authorization' in request.headers:
username = request.headers['Authorization']
bearer, username = request.headers['Authorization'].split(' ')

user = await User.find_one(request.app.db, {'username': username})
if user:
request['user'] = user
Expand Down
5 changes: 3 additions & 2 deletions examples/chatrooms/backend/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from resources import *

# create a resource router for this app
chatrooms_router = Router(name='api/chatrooms')
chatrooms_router = Router(name='api/team')
chatrooms_router.register(UserResource, 'user')
chatrooms_router.register(RoomResource, 'room')
chatrooms_router.register(RoomResource, 'channel')
chatrooms_router.register(RoomResource, 'entry')



Expand Down
2 changes: 1 addition & 1 deletion examples/chatrooms/backend/websocket_sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def unsubscribe(request, ws):
async def resource_event_websocket(request, ws):
waiting = True

subscribe(request, ws)
# subscribe(request, ws)
while waiting:
# data was received from the client
data = await ws.recv()
Expand Down
21 changes: 21 additions & 0 deletions examples/chatrooms/web-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
2,164 changes: 2,164 additions & 0 deletions examples/chatrooms/web-client/README.md

Large diffs are not rendered by default.

0 comments on commit 5a768df

Please sign in to comment.