Exemplo n.º 1
0
 async def wrapped(self, *args, **kwargs):
     if self.request.user is not None:
         add_message(
             self.request, 'info',
             '<a href="/logout" class="alert-link">LogOut</a> to continue.')
         redirect(self.request, 'index')
     return await func(self, *args, **kwargs)
Exemplo n.º 2
0
 async def is_valid(self):
     """ Get username from post data, and check is correct """
     data = await self.request.post()
     username = data.get('username', '').lower()
     if not re.match(r'^[a-z]\w{0,9}$', username):
         add_message(
             self.request, 'warning', 'Username should be alphanumeric, with length [1 .. 10], startswith letter!')
         return False
     return username
Exemplo n.º 3
0
 async def post(self):
     """ Check is username unique and create new User """
     username = await self.is_valid()
     if not username:
         redirect(self.request, 'register')
     if await self.request.app.objects.count(User.select().where(User.username ** username)):
         add_message(self.request, 'danger', f'{username} already exists')
         redirect(self.request, 'register')
     user = await self.request.app.objects.create(User, username=username)
     await self.login_user(user)
Exemplo n.º 4
0
 async def post(self):
     """ Check username and login """
     username = await self.is_valid()
     if not username:
         redirect(self.request, 'login')
     try:
         user = await self.request.app.objects.get(User, User.username ** username)
         await self.login_user(user)
     except User.DoesNotExist:
         add_message(self.request, 'danger', f'User {username} not found')
     redirect(self.request, 'login')
Exemplo n.º 5
0
 async def post(self):
     """ Check is roomname unique and create new User """
     roomname = await self.is_valid()
     if not roomname:
         redirect(self.request, 'create_room')
     if await self.request.app.objects.count(Room.select().where(
             Room.name**roomname)):
         add_message(self.request, 'danger',
                     f'Room with {roomname} already exists.')
         redirect(self.request, 'create_room')
     room = await self.request.app.objects.create(Room, name=roomname)
     redirect(self.request, 'room', parts=dict(slug=room.name))
Exemplo n.º 6
0
 async def wrapped(self, *args, **kwargs):
     if self.request.user is None:
         add_message(self.request, 'info', 'LogIn to continue.')
         redirect(self.request, 'login')
     return await func(self, *args, **kwargs)
Exemplo n.º 7
0
 async def get(self):
     self.request.session.pop('user')
     add_message(self.request, 'info', 'You are logged out')
     redirect(self.request, 'index')
Exemplo n.º 8
0
 async def login_user(self, user):
     """ Put user to session and redirect to Index """
     self.request.session['user'] = str(user.id)
     self.request.session['time'] = time()
     add_message(self.request, 'info', f'Hello {user}!')
     redirect(self.request, 'index')