• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python MySQLdb.thwart函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中MySQLdb.thwart函数的典型用法代码示例。如果您正苦于以下问题:Python thwart函数的具体用法?Python thwart怎么用?Python thwart使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了thwart函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: update_user_tracking

def update_user_tracking():
    try:
        completed = str(request.args['completed'])
        if completed in str(TOPIC_DICT.values()):
            client_name, settings, tracking, rank = userinformation()
            if tracking == None:
                tracking = completed
            else:
                if completed not in tracking:
                    tracking = tracking+","+completed
            
            c,conn = connection()
            c.execute("UPDATE users SET tracking = %s WHERE username = %s",
                    (thwart(tracking),thwart(client_name)))
            conn.commit()
            c.close()
            conn.close()
            client_name, settings, tracking, rank = userinformation()

        else:
            pass

            
    except Exception, e:
        pass
开发者ID:Prmnk,项目名称:PythonProgramming.net-Website,代码行数:25,代码来源:__init__.py


示例2: AddUser

def AddUser():
    try:
        form = AddUserForm(request.form)
        c,conn = confconnection()
        if request.method == "POST" and form.validate():
            passwd = hashlib.sha1(thwart(request.form['password']))
            passwd = passwd.hexdigest()
            x = c.execute("INSERT INTO users (Login, Password, Name, Email, access, developer, edit_card_detail, guest_card_edit,guest_search, show_code,edit_card,add_card,user_edit) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                      (thwart(request.form['username']),
                       passwd,
                       thwart(request.form['name']),
                       thwart(request.form['email']),
                       thwart(request.form['access']),
                       '0', #developer
                       '1', #edit_card_detail
                       '0', #guest_card_edit
                       '1', #guest_search
                       '1', #show_code
                       '0', #edit_card
                       '0', #add_card
                       '0' #user_edit
                       ))
            conn.commit()
            conn.close()
            return "Brukeren er lagt til, husk rettighetsetting"



        return render_template('admin/adduser.html', form=form)
    except Exception as e:
        return (str(e))
开发者ID:B2Crypt,项目名称:cardmin,代码行数:31,代码来源:OLd__init__.py


示例3: register

def register():
	try:
		errorLog = ''
		errorReg = ''
		formReg = RegistrationForm(request.form)
		formLog = LoginForm(request.form)
		if request.method == "POST" and formReg.validate():
			username = formReg.username.data
			email = formReg.email.data
			password = sha256_crypt.encrypt((str(formReg.password.data)))
			c, conn = connection()
			x = c.execute("SELECT * FROM users WHERE username = (%s)",(thwart(username)))
			if int(x) > 0:
				errorReg = "That username is taken."
				print("That username is already taken please choose another")
				return render_template("home.html", formReg = formReg, formLog = formLog, errorLog = errorLog, errorReg = errorReg)
			else:
				c.execute("INSERT INTO users (username, password, email) VALUES (%s, %s, %s)",
				(thwart(username),thwart(password),thwart(email)))
				uid = c.execute("SELECT uid FROM users WHERE username = (%s)",(thwart(username)))
				conn.commit()
				c.close()
				conn.close()
				gc.collect()
				session["uid"]=uid
				session["logged_in"] = True
				session["username"] = username
				return redirect(url_for("news"))
	except Exception as e:
		return str(e)
开发者ID:DarkPrince304,项目名称:Buzzbee,代码行数:30,代码来源:views.py


示例4: login

def login():
	try:
		errorLog = ''
		errorReg = ''
		formLog = LoginForm(request.form)
		formReg = RegistrationForm(request.form)
		if request.method == "POST":
			#print "Hello"
			username = formLog.username.data
			password = formLog.password.data
			#print username, password
			c, conn = connection()
			data = c.execute("SELECT * FROM users WHERE username = (%s)",(thwart(username)))
			data = c.fetchone()[2]
			uid = c.execute("SELECT * FROM users WHERE username = (%s)",(thwart(username)))
			uid = c.fetchone()[0]
			#print "hello",data, uid
			#print "Hello"
			if sha256_crypt.verify(password, data):
				session['uid'] = uid
				session['logged_in'] = True
				session['username'] = username
				gc.collect()
				return redirect(url_for("news"))
				#return render_template("test.html", username = session["username"], loggedIn = session["logged_in"])
			else:
				errorLog = "Invalid Credentials"
				return render_template('home.html', formLog = formLog, formReg = formReg, errorLog = errorLog, errorReg = errorReg)
	except Exception as e:
		errorLog = "Invalid credentials"
		return render_template ("home.html", formLog = formLog, formReg = formReg, errorLog = errorLog, errorReg = errorReg)
开发者ID:DarkPrince304,项目名称:Buzzbee,代码行数:31,代码来源:views.py


示例5: register

def register():
    try:
        form = RegistrationForm(request.form)

        if request.method == "POST" and form.validate():
            firstname  = form.firstname.data
            lastname  = form.lastname.data
            username  = form.username.data
            # salt = uuid.uuid4().hex
            # encrypt_pass = str(salt + form.password.data)
            # password = sha256_crypt.encrypt(encrypt_pass)
            password = sha256_crypt.encrypt(form.password.data)
            c, conn = connection()
            c.execute("SELECT * FROM users WHERE username = (%s)", [thwart(username)])
            if c.rowcount > 0:
                flash("That username is already taken, please choose another")
                return render_template('register.html', form=form)

            else:
                c.execute("INSERT INTO users (firstname , lastname, username, password) VALUES (%s, %s, %s, %s)",
                          (thwart(firstname), thwart(lastname), thwart(username), thwart(password)))
                conn.commit()
                flash("Thanks for registering!")
                c.close()
                conn.close()
                session['logged_in'] = True
                session['username'] = username
                return redirect(url_for('login'))
        return render_template("register.html", form=form)
    except Exception as e:
        return(str(e))
开发者ID:KaustubhCSE,项目名称:WebApplication-Python-Flask,代码行数:31,代码来源:secure.py


示例6: register_page

def register_page():
	try:
		form = RegistrationForm(request.form)
		if request.method == "POST" and form.validate():
			username = form.username.data
			password = sha256_crypt.encrypt((str(form.password.data)))
			email = form.email.data
			c, conn = connection()

			x = c.execute("SELECT * FROM users WHERE username = %s", (username,))

			if int(x) > 0:
				flash("That username is already taken, please choose another")
				return render_template('register.html', form=form)

			else:
				c.execute("INSERT INTO users (username, password, email) VALUES (%s, %s, %s)",
			          (thwart(username), thwart(password), thwart(email)))

				conn.commit()
				flash("Thanks for registering!")
				c.close()
				conn.close()
				gc.collect()

		
				session['logged_in'] = True
				session['username'] = username

				return redirect(url_for('board'))

		return render_template("register.html", form=form)
		
	except Exception as e:
		return(str(e))
开发者ID:outpark,项目名称:nightlyforest,代码行数:35,代码来源:__init__.py


示例7: register_page

def register_page() :
	try :
		form = RegisterationForm(request.form)
		if request.method == "POST" and form.validate() :
			username = form.username.data
			password = sha256_crypt.encrypt((str(form.password.data)))
			email = form.email.data

			conn, cursor = Connection()
			x = cursor.execute("SELECT * FROM users WHERE username = (%s)",({thwart(username)}))
			if int(x) > 0 :
				flash("username taken")
				return render_template('register.html', form=form)
			else :
				cursor.execute('INSERT INTO users (`username`,`password`,`email`,`tracking`) VALUES (%s, %s, %s, %s)',
				({thwart(username)},{thwart(password)},{thwart(email)},{thwart("intro")}))
				conn.commit()
				flash("Thanks for Registering")
				cursor.close()
				conn.close()
				gc.collect()
				session['logged_in'] = True
				session['username'] = username
				return redirect(url_for('dashboard'))

		return render_template("register.html", form = form)

	except Exception as e :
		return (str(e))
开发者ID:pankajpant22,项目名称:flask,代码行数:29,代码来源:app.py


示例8: main

def main():
    form = RegistrationForm(request.form)
    try:
        c,conn = connection()
        error = None
        if request.method == 'POST':
            try:
                data = c.execute("SELECT * FROM users WHERE username = (%s)",
                        thwart(request.form['username']))
                data = c.fetchone()[2]

                if sha256_crypt.verify(request.form['password'], data):
                    session['logged_in'] = True
                    session['username'] = request.form['username']
                    flash('You are now logged in.')
                    return redirect(url_for('dashboard'))
            except Exception, e:
                flash("What are you doing?")


            try:
                
                if request.method == 'POST' and form.validate():

                    username = form.username.data
                    email = form.email.data

                    password = sha256_crypt.encrypt((str(form.password.data)))
                    c,conn = connection()

                    x = c.execute("SELECT * FROM users WHERE username = (%s)",
                        (thwart(username)))

                    if int(x) > 0:
                        flash("That username is already taken, please choose another")
                        return render_template('register.html', form=form)

                    else:
                        c.execute("INSERT INTO users (username, password, email) VALUES (%s, %s, %s)",
                            (thwart(username), thwart(password), thwart(email)))
                        conn.commit()
                        flash('Thanks for registering')
                        c.close()
                        conn.close()
                        gc.collect()
                        session['logged_in'] = True
                        session['username'] = username
                        return redirect(url_for('dashboard'))

            except Exception as e:
                return(str(e))
  
            else:
                flash('Invalid credentials. Try again')
        gc.collect()
        return render_template("main.html", error=error, form=form, page_type = "main")
开发者ID:Prmnk,项目名称:PythonProgramming.net-Website,代码行数:56,代码来源:__init__.py


示例9: submitScore

def submitScore(databaseName, username, score):
  try:
    conn =MySQLdb.connect(host='localhost', user='root', passwd='123456', db='users')
    c = conn.cursor()
    databaseName = databaseName.replace(" ","")
    c.execute("use %s ;" %databaseName)
    conn.commit()
    c.execute("update users set score='%s' where username='%s'" %(thwart(score), thwart(username)))
    conn.commit()
    return True
  
  except Exception as e:
    return False
开发者ID:sahilsehgal1995,项目名称:MarkMe_Quiz_Project,代码行数:13,代码来源:dbConnect.py


示例10: users

def users():
    if request.method == 'POST':
        try:
            c, conn = db_connect()

            first_name = request.form.get('first_name')
            last_name = request.form.get('last_name')
            email = request.form.get('email')

            c.execute(
                "INSERT INTO Users (firstname, lastname, email) VALUES (%s, %s, %s)",
                (thwart(first_name), thwart(last_name), thwart(email)))

            conn.commit()
            c.close()
            conn.close()
            gc.collect()
        except Exception as e:
            print str(e)
            return jsonify(success=False)

        return jsonify(
            success=True,
            firstname=first_name,
            lastname=last_name,
            email=email)
    else:
        try:
            c, conn = db_connect()
            c.execute("SELECT * FROM Users")
            results = c.fetchall()
            c.close()
            conn.close()
            gc.collect()
        except Exception as e:
            return(str(e))

        users = []
        for row in results:
            users.append({
                'id': row[0],
                'firstname': row[1],
                'lastname': row[2],
                'email': row[3]
            })
            print row[0]

        return render_template('register.html', users=users)
开发者ID:killuabone,项目名称:aws-flask,代码行数:48,代码来源:application.py


示例11: LoginPage

def LoginPage():
    form = LoginForm(request.form)
    try:
        if request.method == "POST" and form.validate():
            username = request.form['username']
            password = request.form['password']
            #c, conn = connection() 
            c,conn = confconnection()
            try:
                data = c.execute("SELECT Password FROM users WHERE Login = (%s)",(thwart(username)))
                data = c.fetchone()[0]
                passw = hashlib.sha1(password)
                if passw.hexdigest() == str(data):
                    session['logged_in'] = True
                    session['user'] = username
                    SetPermissions(username)
                    conn.close()
                
                    return redirect(url_for('Profile'))
                else:
                    flash("Error, wrong username or password!")
            except Exception as e:
                return (str(e))
    except Exception as e:
           return (str(e))   

    return render_template('login.html', form=form)
开发者ID:B2Crypt,项目名称:cardmin,代码行数:27,代码来源:OLd__init__.py


示例12: LoginPage

def LoginPage():
    form = LoginForm(request.form) 
    try:
        if request.method == "POST" and form.validate():
            username = thwart(request.form['username'])
            c,conn = confconnection()
            data = c.execute("SELECT password, username FROM new_users WHERE username =(%s)",(username))
            #CheckForOldPass(username,request.form['password'])
            data = c.fetchone()
            passw = request.form['password']
            if c.rowcount == 0:
                return CheckForOldPass(username,passw)
            elif(bcrypt.verify(passw,data[0])):
                session['logged_in'] = True
                session['user'] = username
                setUserName = username #For use in logging
                SetPermissions(username)
                CreateLog("Login",username)
                conn.close()
                return redirect(url_for('Profile'))
            else:
                CreateLog('Wrong password',setUserName)
                return "Feil brukernavn eller passord"
    except Exception as e:
        return (str(e))
    return render_template('login.html', form = form, usrUpdate = userUpdate, userMessage="Det ble utført en nødvendig brukeroppdatering, venligst logg inn igjen")
开发者ID:B2Crypt,项目名称:cardmin,代码行数:26,代码来源:__init__.py


示例13: login_page

def login_page():
    error = ''
    try:
        c, conn = connection()
        if request.method == "POST":

            data = c.execute("SELECT * FROM users WHERE username = (%s)",
                             thwart(request.form['username']))
            
            data = c.fetchone()[2]

            if sha256_crypt.verify(request.form['password'], data):
                session['logged_in'] = True
                session['username'] = request.form['username']

                flash("You are now logged in")
                return redirect(url_for("dashboard"))

            else:
                error = "Invalid credentials, try again."

        gc.collect()

        return render_template("login.html", error=error)

    except Exception as e:
        error =  flash(e)
        #error = "Invalid credentials, try again."
        return render_template("login.html", error = error)  
开发者ID:jonsolis,项目名称:flasktut,代码行数:29,代码来源:backup3__init__.py


示例14: login

def login():
	error = ""
	try:
		if request.method == 'POST':
			c, conn = connection()

			data = c.execute("SELECT * FROM data WHERE username = (%s)", thwart(str(request.form['username'])))
			data = c.fetchone()[3]

			if sha256_crypt.verify(str(request.form['password']), str(data)):
				session['logged_in'] = True
				session['username'] = request.form['username']
				c.close()
				conn.close()
				gc.collect()
				flash('Logged in Successfully')
				return redirect(url_for('show_vault'))

			else:
				error = "Invalid Credentials"
				return render_template("login.html", error=error)

		return render_template("login.html", error=error)

	except Exception as e:
		error = "Invalid Credentials" #str(e)
		return render_template('login.html', error=error)
开发者ID:sahil865gupta,项目名称:pass_vault,代码行数:27,代码来源:app.py


示例15: login_page

def login_page():
    print "login page"
    error = ''
    try:
        c, conn = connection()
        if request.method == "POST":
	    print "login POST"
            data = c.execute("SELECT * FROM users WHERE username = (%s)",
                             [thwart(request.form['username'])] )
	    
            if not data:
		flash('username does not exist')
            data = c.fetchone()[2]
	    print "data fetchone"
            if sha256_crypt.verify(request.form['password'], data):
                session['logged_in'] = True
                session['username'] = request.form['username']

                flash('You are now logged in')
                return redirect(url_for("dashboard"))

            else:
		flash('incorrect password')
                e = "Invalid credentials, try again."

        gc.collect()

        return render_template("login.html", error=error)

    except Exception as e:
        print e
        error = "EXCEPTIONInvalid credentials, try again."
        return render_template("login.html", error = error)  
开发者ID:jk34,项目名称:Python_Flask,代码行数:33,代码来源:main.py


示例16: login

def login():
    error = None
    try:
        c, conn = connection()
        flash("db ok")
        if request.method == "POST":
            flash("method is POST")
            data = c.execute("SELECT * FROM users WHERE username = (%s)",
                             [thwart(request.form['username'])])
            data = c.fetchone()[2]
            name = request.form['username']
            if sha256_crypt.verify(request.form['password'], data):
                session['logged_in'] = True
                session['username'] = request.form['username']
                flash("You are now logged in")
                if name == 'ubuntu':
                    session['is_admin']= True
                    flash("welcome Admin!")
                else:
                    flash("Welcome Standard User")
                return redirect("/")

            else:
                error = "Invalid credentials, try again."
        gc.collect()

        return render_template("register/login.html", error=error)
        
    except Exception as e:
        #flash(e)
        error = "Invalid credentials, try again."
        return render_template('register/login.html',error = error)
开发者ID:mzvast,项目名称:flask-web,代码行数:32,代码来源:home.py


示例17: login_page

def login_page():
	error = ''
	try:
		c, conn = connection()
		if request.method == "POST":
			data = c.execute("select * from users where username = (%s)", [thwart(request.form['username'])])
			
			#get the first record
			data = c.fetchone()[2]
			
			#check if password matches
			if sha256_crypt.verify(request.form['password'], data):
				session['logged_in'] = True
				session['username'] = request.form['username']
				
				flash("You are now logged in!")
				return redirect(url_for('dashboard'))
				
			else:
				error = "Invalid credentials, try again!"
		
		gc.collect()	
		
		return render_template("login.html", error=error)
		
	except Exception as e:
		error = "Invalid credentials, try again!"
		return  render_template("login.html", error = error)
开发者ID:nicecodee,项目名称:metopclub,代码行数:28,代码来源:__init__.py


示例18: register_page

def register_page():
    
    try:
        form = RegistrationForm(request.form)

        if request.method == "POST" and form.validate():
            username = form.username.data
            email = form.email.data
            password = sha256_crypt.encrypt(str(form.password.data))
            c, conn = connection()
            ret = c.execute("SELECT * FROM users WHERE username = ('{0}');".format(thwart(username)))

            if int(ret) > 0:    
                return "Username taken"

            else:
                c.execute("INSERT INTO users (username, password, email) VALUES ('{0}', '{1}', '{2}')".format(thwart(username), thwart(password), thwart(email)))
                conn.commit()
                c.close() #Close db connection, saves ram
                conn.close()

                gc.collect()

                session["logged_in"] = True
                session["username"] = username
                
                return redirect(url_for("dashboard"))

        return render_template("register.html", form = form)

        

    except Exception as e:
        return str(e)
开发者ID:OscarMelin,项目名称:learning-flask-bootstrap,代码行数:34,代码来源:__init__.py


示例19: login

def login():
    try:
        c, conn = connection()
        error = None
        if request.method == 'POST':
            if 'login' in request.form :
                username = request.form['username']
                password = request.form['password']
                c.execute("SELECT * from users where username = %s", [thwart(username)])
                data = c.fetchone()[4]
                # salt = uuid.uuid4().hex
                # saltpassword = str(salt + request.form['password'])
                if not sha256_crypt.verify(password , data):
                    error = 'Invalid Credentials. Please try again.'
                else :
                    flash("You are now logged in")
                    session['logged_in'] = True
                    session['username'] = username
                    return redirect(url_for('upload_file'))
                c.close()
                conn.close()
            elif 'register' in request.form :
                return redirect(url_for('register'))
        return render_template('login.html', error=error)
    except Exception as e:
        return(str(e))
开发者ID:KaustubhCSE,项目名称:WebApplication-Python-Flask,代码行数:26,代码来源:secure.py


示例20: login_page

def login_page():

    error = None

    try:

        #Already logged in
        if "logged_in" in session:
            return redirect(url_for("dashboard"))

        #Else, establish db connection
        c, conn = connection()
        if request.method == "POST":
            
            data = c.execute("SELECT * FROM users WHERE username = ('{0}');".format(thwart(request.form["username"])))
            data = c.fetchone()[2] #password

            if sha256_crypt.verify(request.form["password"], data):
                session["logged_in"] = True
                session["username"] = request.form["username"]

                return redirect(url_for("dashboard"))

            else:
                error = "Invalid credentials, try again."

        c.close() #Close db connection, saves ram
        gc.collect()

        return render_template("login.html", error = error)

    except Exception as e:
        error = "Invalid credentials, try again. {0}".format(str(e))
        return render_template("login.html", error = error)
开发者ID:OscarMelin,项目名称:learning-flask-bootstrap,代码行数:34,代码来源:__init__.py



注:本文中的MySQLdb.thwart函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python conversions.copy函数代码示例发布时间:2022-05-24
下一篇:
Python MySQLdb.escape_string函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap