Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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 :: Routes In Django 
Python :: django model 
Python :: python - 
Python :: python uml 
Python :: print all objects in list python 
Python :: write hexadecimal in python 
Python :: python in 
Python :: python 3 
Python :: how to find ascii value by python 
Python :: how to create list of objects in python 
Python :: pybase64 tutorial 
Python :: densenet python keras 
Python :: type of tuple in python 
Python :: how to use str() 
Python :: add new column of dataframe 
Python :: if queryset is empty django 
Python :: python Parse string into integer 
Python :: dockerfile example 
Python :: Python NumPy Reshape function example 
Python :: what is thread in python 
Python :: del(list) python 
Python :: python3 
Python :: python child class init 
Python :: join mulitple dataframe pandas index 
Python :: python string: index error 
Python :: what will be the output of the following python code? i = 0 while i < 5: print(i) i += 1 if i == 3: break else: print(0) 
Python :: Second step creating python project 
Python :: print prime nos from 1 to n 
Python :: tz convert python 
Python :: plotly change marker symboly sequence 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =