本文整理汇总了Python中user.make_secure_val函数的典型用法代码示例。如果您正苦于以下问题:Python make_secure_val函数的具体用法?Python make_secure_val怎么用?Python make_secure_val使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_secure_val函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_login
def process_login():
connection = pymongo.Connection(connection_string, safe=True)
username = bottle.request.forms.get("username")
password = bottle.request.forms.get("password")
print "user submitted ", username, "pass ", password
userRecord = {}
if (user.validate_login(connection, username, password, userRecord)):
session_id = user.start_session(connection, username)
if (session_id == -1):
bottle.redirect("/internal_error")
cookie = user.make_secure_val(session_id)
# Warning, if you are running into a problem whereby the cookie being set here is
# not getting set on the redirct, you are probably using the experimental version of bottle (.12).
# revert to .11 to solve the problem.
bottle.response.set_cookie("session", cookie)
bottle.redirect("/welcome")
else:
return bottle.template("login",
dict(username=cgi.escape(username), password="",
login_error="Invalid Login"))
示例2: process_signup
def process_signup():
connection = pymongo.Connection(connection_string, safe=True)
email = bottle.request.forms.get("email")
username = bottle.request.forms.get("username")
password = bottle.request.forms.get("password")
verify = bottle.request.forms.get("verify")
# set these up in case we have an error case
errors = {'username':cgi.escape(username), 'email':cgi.escape(email)}
if (user.validate_signup(username, password, verify, email, errors)):
if (not user.newuser(connection, username, password, email)):
# this was a duplicate
errors['username_error'] = "Username already in use. Please choose another"
return bottle.template("signup", errors)
session_id = user.start_session(connection, username)
print session_id
cookie= user.make_secure_val(session_id)
bottle.response.set_cookie("session",cookie)
bottle.redirect("/welcome")
else:
print "user did not validate"
return bottle.template("signup", errors)
示例3: process_login
def process_login():
connection = pymongo.Connection(connection_string, safe=True)
username = bottle.request.forms.get("username")
password = bottle.request.forms.get("password")
userRecord = {}
if user.validate_login(connection, username, password, userRecord):
# looks good. start a new session
session_id = user.start_session(connection, username)
if session_id == -1:
bottle.redirect("/internal_error")
cookie = user.make_secure_val(session_id)
# send the cookie back to the user
bottle.response.set_cookie("session", cookie)
# full round trip here.
bottle.redirect("/welcome")
else:
# not a valid login
return bottle.template("login", dict(username=cgi.escape(username), password="", login_error="Invalid Login"))
示例4: process_signup
def process_signup():
print('signup process')
connection = MongoClient("localhost", 27017)
email = bottle.request.forms.get("email").strip()
username = bottle.request.forms.get("username").strip()
password = bottle.request.forms.get("password").strip()
verify = bottle.request.forms.get("verify").strip()
print(email,username,password,verify)
# set these up in case we have an error case
errors = {'username': cgi.escape(username), 'email': cgi.escape(email)}
print('er:', errors)
if (user.validate_signup(username, password, verify, email, errors)):
print('here1')
if (not user.newuser(connection, username, password, email)):
# this was a duplicate
print('dup')
errors['username_error'] = "Username already in use. Please choose another"
return bottle.template("signup", errors)
session_id = user.start_session(connection, username)
print ('sessionid', session_id)
cookie = user.make_secure_val(session_id)
bottle.response.set_cookie("session", cookie)
#cook = bottle.request.get_cookie('session')
#print('cook', cook)
#print('user', username)
#username = bottle.request.forms.get("username")
return bottle.template("welcome", username=username)
else:
print ("user did not validate")
return bottle.template("signup", errors)
示例5: process_login
def process_login():
connection = pymongo.Connection(connection_string, safe=True)
username = bottle.request.forms.get("username")
password = bottle.request.forms.get("password")
print ("user submitted ", username, "pass ", password)
userRecord = {}
if (user.validate_login(connection, username, password, userRecord)):
session_id = user.start_session(connection, username)
if (session_id == -1):
bottle.redirect("/internal_error")
cookie = user.make_secure_val(session_id)
bottle.response.set_cookie("session", cookie)
bottle.redirect("/welcome")
else:
return bottle.template("login",
dict(username=cgi.escape(username), password="",
login_error="Invalid Login"))
示例6: process_login
def process_login():
connection = pymongo.MongoClient(connection_string)
username = bottle.request.forms.get("username")
password = bottle.request.forms.get("password")
print "user submitted ", username, "pass ", password
userRecord = {}
if (user.validate_login(connection, username, password, userRecord)):
session_id = user.start_session(connection, username)
if (session_id == -1):
bottle.redirect("/internal_error")
cookie = user.make_secure_val(session_id)
# не работает с bottle .12, откатитесь на версию .11
bottle.response.set_cookie("session", cookie)
bottle.redirect("/")
else:
return bottle.template("login",
dict(username=cgi.escape(username), password="",
login_error="неверно"))
示例7: process_signup
def process_signup():
connection = pymongo.MongoClient(connection_string)
email = bottle.request.forms.get("email")
username = bottle.request.forms.get("username")
password = bottle.request.forms.get("password")
verify = bottle.request.forms.get("verify")
# подготовоим объект, если вдруг у нас будут ошибки
errors = {'username':cgi.escape(username), 'email':cgi.escape(email)}
if (user.validate_signup(username, password, verify, email, errors)):
if (not user.newuser(connection, username, password, email)):
# дубликат
errors['username_error'] = "Имя уже используется"
return bottle.template("signup", errors)
session_id = user.start_session(connection, username)
print session_id
cookie= user.make_secure_val(session_id)
bottle.response.set_cookie("session",cookie)
bottle.redirect("/")
else:
print "user did not validate"
return bottle.template("signup", errors)
示例8: process_login
def process_login():
username = bottle.request.forms.get("username")
password = bottle.request.forms.get("password")
userRecord = {}
if (user.validate_login(username, password, userRecord)):
session_id = user.start_session(userRecord['uid'])
cookie = user.make_secure_val(str(int(session_id)))
bottle.response.set_cookie("session", cookie)
bottle.redirect("/blog/welcome")
else:
return bottle.template("login",
dict(username=cgi.escape(username), password="",
login_error="Invalid Login"))
示例9: process_signup
def process_signup():
email = bottle.request.forms.get("email")
username = bottle.request.forms.get("username")
password = bottle.request.forms.get("password")
verify = bottle.request.forms.get("verify")
# set these up in case we have an error case
errors = {'username':cgi.escape(username), 'email':cgi.escape(email)}
if (user.validate_signup(username, password, verify, email, errors)):
uid = user.newuser(username, password, email)
if (uid == None):
# this was a duplicate
errors['username_error'] = "Username already in use. Please choose another"
return bottle.template("signup", errors)
session_id = user.start_session(uid)
cookie= user.make_secure_val(str(int(session_id)))
bottle.response.set_cookie("session",cookie)
bottle.redirect("/blog/welcome")
else:
return bottle.template("signup", errors)
示例10: signup
def signup():
connection = pymongo.Connection(connection_string, safe=True)
username = request.forms.get("username")
password = request.forms.get("password")
# set these up in case we have an error case
errors = {'username_value': cgi.escape(username), 'username': ''}
if user.validate_signup(username, password, errors):
if not user.new_user(connection, username, password):
# this was a duplicate
errors['username_error'] = "Username already in use. Please choose another"
return template("signup", errors)
session_id = user.start_session(connection, username)
print session_id
cookie = user.make_secure_val(session_id)
response.set_cookie("session", cookie)
redirect("/main")
else:
print "user did not validate"
return template("signup", errors)
示例11: set_secure_cookie
def set_secure_cookie(self, name, val):
cookie_val = user.make_secure_val(val)
self.response.headers.add_header(
'Set-Cookie',
'%s=%s; Path=/' % (name, cookie_val))