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 :: deleting a file using python 
Python :: reset all weights keras 
Python :: Could not find a version that satisfies the requirement ckeditor 
Python :: numpy array serialize to string 
Python :: extract bigrams python 
Python :: save to xlsx in python 
Python :: python community 
Python :: pygame collisions 
Python :: create forms in django 
Python :: no python application found, check your startup logs for errors 
Python :: add python to path 
Python :: python password generation 
Python :: pyaduio 
Python :: os.move file 
Python :: serialization in django 
Python :: how to end an infinite loop in specific time python 
Python :: how to remove time in datetime in python 
Python :: django forms request 
Python :: reorder list python 
Python :: logarithmic scale fitting python 
Python :: replace characters in string python 
Python :: python discord embed link 
Python :: python image layers 
Python :: # read the JSON file and also print the file content in JSON format. 
Python :: Splitting strings in Python without split() 
Python :: python 2d dictionary 
Python :: reversed() python 
Python :: how to use css in php example 
Python :: matplotlib list backend 
Python :: bar plot 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =