Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def consent():
# redirect to next url when current user has already consented
if current_user.has_consented:
return redirect(session.pop("next_url", default_url()))
form = ConsentForm()
if form.validate_on_submit():
current_user.consented_at = datetime.utcnow()
current_user.profile_consent = True
current_user.org_consent = True
current_user.cookies_consent = True
current_user.age_consent = True
current_user.save()
next_url = session.pop("next_url", default_url())
return redirect(next_url)
return {"form": form}
def wrap(*args, **kwargs):
if 'logged_in' in session:
return test(*args, **kwargs)
else:
flash('You need to login first.')
return redirect(url_for('login'))
return wrap
user_err_num = user.err_num
if(user.jobnum=="None" or user.jobnum is None):
return jsonify({'msg': login_user_inactivatesd, 'code': 34, 'data': ''})
if user:
if user.status is True:
return jsonify({'msg': login_user_free_message, 'code': 35, 'data': ''})
if user.check_password(password):
if (user.is_free == True and user.freetime != None and user.err_num > 6 and (
datetime.datetime.now() - user.freetime).minute > 10):
return jsonify({'msg': login_user_fremm, 'code': 200, 'data': ''})
user.is_login = True
userlog = UserLoginlog(user=user.id, ip=ip, datatime=datetime.datetime.now())
db.session.add_all([user, userlog])
db.session.commit()
login_user(user)
session['username'] = username
return jsonify({'msg': login_user_sucess_message, 'code': 200, 'data': ''})
else:
if (user.err_num >= 5):
if (user.freetime != 'None'):
if (datetime.datetime.now() - user.freetime).minute > 10:
user.err_num = user_err_num + 1
db.session.add(user)
db.session.commit()
return jsonify({'msg': login_password_error_message, 'code': 36, 'data': ''})
else:
user.err_num = 5
user.freetime = datetime.datetime.now()
user.is_free = True
db.session.add(user)
db.session.commit()
return jsonify({'msg': login_user_fremm, 'code': 36, 'data': ''})
def getFrontendContent(**params):
"""
Deliver frontend content of module alarms
:return: data of alarms
"""
from emonitor.extensions import monitorserver
if 'alarmfilter' not in session:
session['alarmfilter'] = '7'
if request.args.get('alarmfilter'): # filter for alarms last x days, -1 no filter set
session['alarmfilter'] = request.args.get('alarmfilter', '7')
if 'area' in request.args:
params['area'] = request.args.get('area')
if 'state' in request.args:
params['activeacc'] = request.args.get('state')
if request.form.get('action') == 'updatealarm':
if request.form.get('alarm_id') != 'None': # update alarm
alarm = Alarm.getAlarms(request.form.get('alarm_id'))
else: # create new alarm
d = datetime.datetime.strptime('%s %s' % (request.form.get('edit_timestamp_date'), request.form.get('edit_timestamp_time')), "%d.%m.%Y %H:%M:%S")
alarm = Alarm(d, request.form.get('edit_keyid'), 2, 0)
db.session.add(alarm)
params['activeacc'] = 1
try:
alarm.timestamp = datetime.datetime.strptime('%s %s' % (request.form.get('edit_timestamp_date'), request.form.get('edit_timestamp_time')), "%d.%m.%Y %H:%M:%S")
def logout():
session.pop('user_id', None)
return redirect('/pop')
@app.route('/logout')
def logout():
session.clear()
return redirect(url_for('index'))
def get_attached_folders(linked_object, include_empty=True, include_hidden=True, preload_event=False):
"""
Return a list of all the folders linked to an object.
:param linked_object: The object whose attachments are to be returned
:param include_empty: Whether to return empty folders as well.
:param include_hidden: Include folders that the user can't see
:param preload_event: in the process, preload all objects tied to the
corresponding event and keep them in cache
"""
from indico.modules.attachments.models.folders import AttachmentFolder
folders = AttachmentFolder.get_for_linked_object(linked_object, preload_event=preload_event)
if not include_hidden:
folders = [f for f in folders if f.can_view(session.user)]
if not include_empty:
folders = [f for f in folders if f.attachments]
return folders
@app.route('/logout')
def logout():
logout_user()
session.pop('openid', None)
return redirect('/login')
@app.route('/add', methods=['POST'])
def add_post():
page = int(request.form['index'])
posts = Post.query.order_by(desc(Post.timestamp)).paginate(page, POSTS_PER_PAGE, False).items
has_next = Post.query.order_by(desc(Post.timestamp)).paginate(page, POSTS_PER_PAGE, False).has_next
if request.form['title'] == "" or request.form['body'] == "":
flash('You have to fill all the inputs!','error')
return render_template('show_posts.html', posts=posts, index=page, has_next = str(has_next), title=request.form['title'], body=request.form['body'], tags = request.form['tags'])
if not session.get('logged_in'):
abort(401)
entry = request.form['body']
r=re.compile(r'.*\[code (?P.{1,10})\](?P<code>.+)\[/code\].*', re.DOTALL)
m=r.match(entry)
if m is not None:
lang = m.group('lang')
code = m.group('code')
lexer = get_lexer_by_name(lang, stripall=True)
code = highlight(code, lexer, HtmlFormatter())
front = entry[:entry.find('[code')]
back = entry[entry.find('[/code]') + 7:]</code>
language_translation = LanguageTranslation(username='',
password='')
langsdetected = language_translation.identify(txt)
primarylang = langsdetected["languages"][0]['language']
confidence = langsdetected["languages"][0]['confidence']
lang = "I am %s confident that the language is %s" % (confidence, primarylang)
session['langtext'] = lang
allinfo['lang'] = lang
allinfo['form'] = form
return redirect(url_for('wlhome'))
except WatsonException as err:
allinfo['error'] = err
allinfo['lang'] = session.get('langtext')
allinfo['form'] = form
return render_template('watson/wlindex.html', info=allinfo)