Exemple #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)
Exemple #2
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)
Exemple #3
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')
Exemple #4
0
 async def post(self):
     data = self.request.data
     user = False
     #print (data)
     try:
         user = await self.request.app.objects.get(User, **data)
     except:
         self.request.status.update({"err": "Логин и пароль не совпадают"})
     if user:
         self.request.session['user'] = str(user.id)
         redirect(self.request, 'GetUser')
     else:
         self.request.status.update({"err": "Логин и пароль не совпадают"})
         return {}
Exemple #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))
Exemple #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)
Exemple #7
0
 async def get(self):
     self.request.session.pop('user')
     add_message(self.request, 'info', 'You are logged out')
     redirect(self.request, 'index')
Exemple #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')