Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def authorize(request):
""" Check for current user's permissions.
Can be redifined for each handler.
"""
user = yield from app.ps.session.load_user(request)
if not user or not user.is_super:
raise muffin.HTTPFound('/')
return user
async def post(self, request):
"""Create/Edit items."""
form = await self.get_form(request)
if not form.validate():
raise muffin.HTTPBadRequest(
text=json.dumps(form.errors), content_type='application/json')
await self.save_form(form, request)
raise muffin.HTTPFound(self.url)
def logout(request):
""" Implement user's logout. """
yield from app.ps.session.logout(request)
return muffin.HTTPFound('/')
def login(request):
""" Implement user's login. """
data = yield from request.post()
user = User.select().where(User.email == data.get('email')).get()
if user.check_password(data.get('password')):
yield from app.ps.session.login(request, user.pk)
return muffin.HTTPFound('/')
def bulk_delete(handler, request):
"""Bulk delete items"""
ids = request.GET.getall('ids')
Message.delete().where(Message.id << ids).execute()
raise muffin.HTTPFound(handler.url)
try:
token = Token.select().where(Token.token == client.access_token).get()
user = token.user
except Exception:
response = yield from client.request('GET', 'user')
info = yield from response.json()
user = User(username=info['login'], email=info['email'], password='NULL')
user.save()
token = Token(provider='github', token=client.access_token, user=user)
token.save()
yield from app.ps.session.login(request, user.id)
return muffin.HTTPFound('/')
def check_user(self, request, func=FUNC, location=None, **kwargs):
""" Check for user is logged and pass func. """
user = yield from self.load_user(request)
func = func or self.options.default_user_checker
if not func(user):
raise HTTPFound(location or self.options.login_url, **kwargs)
return user