def test_is_logged_in(app, client, csrf_token_for): client.get(url_for("simplelogin.login")) assert not is_logged_in() response = client.post( url_for("simplelogin.login"), data={ "username": "******", "password": "******", "csrf_token": csrf_token_for(app), }, ) assert response.status_code == 302 assert is_logged_in()
def test_logout(app, client, csrf_token_for): client.get(url_for("simplelogin.login")) assert not is_logged_in() client.post( url_for("simplelogin.login"), data={ "username": "******", "password": "******", "csrf_token": csrf_token_for(app), }, ) assert is_logged_in() client.get(url_for("simplelogin.logout")) assert not is_logged_in()
def get(self, slug, ext=None): category, _, item_slug = slug.rpartition('/') content = app.db.get_with_content(slug=item_slug, category_slug=category) if not content: abort(404) content = make_model(content) if content.status == 'draft' and not self.is_preview: abort(404) if self.is_preview and not is_logged_in(): # access denied abort(403) context = { 'category': content.category, 'author': content.author, 'content': content, content.content_type: content } self.set_elements_visibility(context, content.content_type) self.set_elements_visibility(context, slug) self.set_content_var_map(context, content) templates = [ f'custom/{content.content_type}/{normalize_var(slug)}.html', f'{content.content_type}.html' ] return render_template(templates, **context)
def _handle_view(self, *args, **kwargs): # noqa """Admin views requires login""" if current_app.config.get('ADMIN_REQUIRES_LOGIN') is True: if not is_logged_in(): return redirect( url_for('simplelogin.login', next="/admin") )
def get(self, slug, ext=None): category, _, item_slug = slug.rpartition('/') content = app.db.get_with_content( slug=item_slug, category_slug=category ) if not content: abort(404) content = make_model(content) if content.status == 'draft' and not self.is_preview: abort(404) if self.is_preview and not is_logged_in(): # access denied abort(403) context = { 'category': content.category, 'author': content.author, 'content': content, content.content_type: content } self.set_elements_visibility(context, content.content_type) self.set_elements_visibility(context, slug) self.set_content_var_map(context, content) templates = [ f'custom/{content.content_type}/{normalize_var(slug)}.html', f'{content.content_type}.html' ] return render_template(templates, **context)
def check_if_admin(): """Check if a given user has admin access. Returns: bool -- Whether or not the user has admin access. """ return bool(is_logged_in() and 'admin' in get_current_access(get_username()))
def campagne(): if is_logged_in(): rows = req.selectAll("campagne").fetchall() return render_template("Campagne.html", rows=rows) else: return redirect("/login", code=302)
def BanqueSession(): if is_logged_in(): #Selection des campagnes rowsCampagne = req.selectAll("campagne").fetchall() return render_template("BanqueSession.html", rowsCampagne=rowsCampagne) else: return redirect("/login", code=302)
def account(account): if is_logged_in() and account == get_username(): # .encode("utf-8"): if platform.node() == "backup-server-vm": flash( "The main jforseth.tech server is experiencing issues. Account changes have been suspended." ) account = get_account(get_username()) # .encode("utf-8")) groups = account["prayer_groups"].split("|") return render_template("accounts/account.html", groups=groups) return render_template("errors/403.html"), 403
def banque(): if is_logged_in(): #Selection des campagnes rowsCampagne = req.selectAll("campagne").fetchall() #Selection des chemin rowsChemin = req.selectAll("Chemin").fetchall() #Selection des sessions rowsSession = req.selectAll("Session").fetchall() return render_template("Banque.html", rowsCampagne=rowsCampagne, rowsChemin=rowsChemin, rowsSession=rowsSession) else: return redirect("/login", code=302)
def upload_file(): if is_logged_in(): form = FormCampagne(request.form) if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: flash('No file part') return redirect(request.url) file = request.files['file'] # if user does not select file, browser also # submit a empty part without filename if file.filename == '': flash('No selected file') return redirect(request.url) #Si tout se passe bien : Alors on upload le fichier, et on peuple la base de donnée if file and allowed_file(file.filename): if form.nom.data not in req.selectFromTable( "nom", "campagne").fetchall(): #Le nom du fichier est identifiant aleatoire filename = binascii.hexlify(os.urandom(16)) #Si les repertoires n'existent pas alors il sont créés if not os.path.exists(UPLOAD_FOLDER + "/ExcelFile"): os.makedirs(UPLOAD_FOLDER + "/ExcelFile") req.insertIntoCampagne( form.nom.data, os.path.join(UPLOAD_FOLDER + "/ExcelFile", filename), form.countdown.data, form.form1.data, form.form2.data) file.save( os.path.join(UPLOAD_FOLDER + "/ExcelFile", filename)) return redirect("/Campagne", code=302) else: return redirect("/login", code=302) return render_template("CreationDeCampagne.html", form=form)
def index(self): if not is_logged_in('admin'): return redirect(url_for('simplelogin.login', next=request.url)) result = None if request.method == 'POST': url = request.form.get('url') if url: download_and_send(url) result = 'In proccess' else: result = 'url not set' session['result'] = result return redirect(url_for('upload_from_url.index')) elif request.method == 'GET': result = session.pop('result', None) return self.render('upload_from_url.html', result=result)
def is_accessible(self): return is_logged_in('admin')
def index(self): if not is_logged_in('admin'): return redirect(url_for('simplelogin.login', next=request.url)) return super(MyAdminIndexView, self).index()
def _handle_view(self, *args, **kwargs): # noqa """Admin views requires login""" if current_app.config.get('ADMIN_REQUIRES_LOGIN') is True: if not is_logged_in(): return redirect(url_for('simplelogin.login', next="/admin"))