Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

import flask session

$ pip install Flask-Session
Comment

session of flask

# registerviews.py
__author__ = "Daniel Gaspar"

import logging

from flask import flash, redirect, request, session, url_for
from flask_babel import lazy_gettext

from .forms import LoginForm_oid, RegisterUserDBForm, RegisterUserOIDForm
from .. import const as c
from .._compat import as_unicode
from ..validators import Unique
from ..views import expose, PublicFormView

log = logging.getLogger(__name__)


def get_first_last_name(fullname):
    names = fullname.split()
    if len(names) > 1:
        return names[0], " ".join(names[1:])
    elif names:
        return names[0], ""


class BaseRegisterUser(PublicFormView):

    route_base = "/register"
    email_template = "appbuilder/general/security/register_mail.html"
    email_subject = lazy_gettext("Account activation")


## ... source file abbreviated to get to session examples ...


            username=form.username.data,
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            email=form.email.data,
            password=form.password.data,
        )


class RegisterUserOIDView(BaseRegisterUser):

    route_base = "/register"

    form = RegisterUserOIDForm
    default_view = "form_oid_post"

    @expose("/formoidone", methods=["GET", "POST"])
    def form_oid_post(self, flag=True):
        if flag:
            self.oid_login_handler(self.form_oid_post, self.appbuilder.sm.oid)
        form = LoginForm_oid()
        if form.validate_on_submit():
            session["remember_me"] = form.remember_me.data
            return self.appbuilder.sm.oid.try_login(
                form.openid.data, ask_for=["email", "fullname"]
            )
        resp = session.pop("oid_resp", None)
        if resp:
            self._init_vars()
            form = self.form.refresh()
            self.form_get(form)
            form.username.data = resp.email
            first_name, last_name = get_first_last_name(resp.fullname)
            form.first_name.data = first_name
            form.last_name.data = last_name
            form.email.data = resp.email
            widgets = self._get_edit_widget(form=form)
            return self.render_template(
                self.form_template,
                title=self.form_title,
                widgets=widgets,
                form_action="form",
                appbuilder=self.appbuilder,
            )
        else:
            flash(as_unicode(self.error_message), "warning")
            return redirect(self.get_redirect())

    def oid_login_handler(self, f, oid):
        from flask_openid import OpenIDResponse, SessionWrapper
        from openid.consumer.consumer import CANCEL, Consumer, SUCCESS


## ... source file continues with no further session examples...
Comment

sessions in flask

 @app.route("/login",methods = ["POST","GET"])  
    def login():  
        if request.method == "POST":  
            try:   
                Email = request.form["email"]
                pwd = request.form["pwd"]    
                with sqlite3.connect("Account.db") as con:  
                    cur = con.cursor()
                    print("Connection test")   
                    cur.execute("SELECT * FROM Account WHERE Email= ? and Password= ?",(Email, pwd))
                    row = cur.fetchone()
                    print("query test")  
                    while row is not None:
                        session['email']=request.form['email']  
                        print(row[1])
                        return render_template("success.html",msg = msg)
                    else:
                        msg = "sorry wrong id"
                        return render_template("failure.html",msg = msg)
            except:  
                con.rollback()  
                msg = "problem"  
if 'email' in session:
        email = session['email']   
        return render_template("view.html") 
    else:
        return '<p>Please login first</p>'  
Comment

PREVIOUS NEXT
Code Example
Python :: python copy vs deepcopy 
Python :: how to remove some indexes from a dataframe in python 
Python :: np.transpose(x) array([[0, 2], [1, 3]]) 
Python :: random generator python 
Python :: convert images to jpeg 
Python :: create a new column in pandas dataframe based on the existing columns 
Python :: what is self 
Python :: bresenham circle drawing algorithm 
Python :: How to swap elements in a list in Python detailed 
Python :: append to a tuple 
Python :: python print array 
Python :: django filter values with e and operator 
Python :: list slicing in python 
Python :: python string replace method 
Python :: python size of list 
Python :: templates python 
Python :: python return multiple value from a function 
Python :: class object 
Python :: interpreter in python 
Python :: range(n,n) python 
Python :: numpy.empty sorce code 
Python :: python list of possible paths 
Python :: list generation for python 
Python :: custom header footer in odoo 
Python :: print A to Z in python uppercase 
Python :: if boolean func 
Python :: installing python3.8 in rpi 
Python :: python recase 
Python :: py3-env.bat 
Python :: print all data in excel openpyxl 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =