Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
except HTTPError as e:
self.set_status(403)
return self.finish(
self.gettext(e.log_message),
)
try:
password1 = self.get_body_argument('password1')
password2 = self.get_body_argument('password2')
validate.user_password(password1)
if password1 != password2:
raise validate.InvalidFormat(_f("Passwords do not match"))
logger.info("Password reset: changing password for %r", user.login)
user.set_password(password1)
self.db.commit()
return self.redirect(self.reverse_url('index'))
except validate.InvalidFormat as e:
logger.info("Error validating SetNewPassword: %r", e)
return self.render('new_password.html', reset_token=reset_token,
error=self.gettext(e.message))
project, privileges = self.get_project(project_id)
if not privileges.can_update_tag():
self.set_status(403)
return self.send_json({'error': "Unauthorized"})
try:
obj = self.get_json()
tag = self.db.query(database.Tag).get(int(tag_id))
if tag is None or tag.project_id != project.id:
self.set_status(404)
return self.send_json({'error': "No such tag"})
if obj:
if 'path' in obj:
validate.tag_path(obj['path'])
tag.path = obj['path']
if 'description' in obj:
validate.tag_description(obj['description'])
tag.description = obj['description']
cmd = database.Command.tag_add(
self.current_user,
tag,
)
try:
self.db.add(cmd)
self.db.commit()
except IntegrityError:
self.db.rollback()
self.set_status(409)
return self.finish()
self.db.refresh(cmd)
self.application.notify_project(project.id, cmd)
return self.send_json({'id': tag.id})
def post(self, project_id):
project, privileges = self.get_project(project_id)
if not privileges.can_edit_project_meta():
self.set_status(403)
return self.send_json({'error': "Unauthorized"})
try:
obj = self.get_json()
validate.project_name(obj['name'])
project.name = obj['name']
validate.project_description(obj['description'])
project.description = obj['description']
logger.info("Updated project: %r %r",
project.name, project.description)
cmd = database.Command.project_meta(
self.current_user,
project.id,
obj['name'],
obj['description'],
)
self.db.add(cmd)
self.db.commit()
self.db.refresh(cmd)
self.application.notify_project(project.id, cmd)
return self.send_json({})
except validate.InvalidFormat as e:
logger.info("Error validating ProjectMeta: %r", e)
async def post(self, project_id):
project, privileges = self.get_project(project_id)
if not privileges.can_add_document():
self.set_status(403)
return self.send_json({'error': "Unauthorized"})
try:
name = self.get_body_argument('name')
validate.document_name(name)
description = self.get_body_argument('description')
validate.document_description(description)
try:
file = self.request.files['file'][0]
except (KeyError, IndexError):
raise MissingArgumentError('file')
content_type = file.content_type
filename = validate.filename(file.filename)
try:
body = await convert.to_html_chunks(
file.body, content_type, filename,
self.application.config,
)
except convert.ConversionError as err:
self.set_status(400)
def post(self):
if not self.application.config['MULTIUSER']:
raise HTTPError(404)
login = self.get_body_argument('login')
try:
login = validate.user_login(login)
except validate.InvalidFormat:
logger.info("Login: invalid login")
else:
password = self.get_body_argument('password')
user = self.db.query(database.User).get(login)
if user is None:
logger.info("Login: non-existent user")
elif not user.check_password(password):
logger.info("Login: invalid password for %r", user.login)
else:
self.login(user.login)
return self._go_to_next()
return self.render(
'login.html', register=False,
next=self.get_argument('next', ''),
login_error=self.gettext("Invalid login or password"),