本文整理汇总了Python中model.User.add_new_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.add_new_user方法的具体用法?Python User.add_new_user怎么用?Python User.add_new_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.add_new_user方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_login
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import add_new_user [as 别名]
def process_login():
"""Look up user and store user in session"""
email_input = request.form.get("email")
password_input = request.form.get("password")
user = User.query.filter_by(email=email_input).first()
print "USER HERE:", user
if user is None:
flash("Welcome to Ratings!")
new_user = User.add_new_user(email=email_input, password=password_input)
session['logged_in_user'] = new_user.user_id
return redirect("/users/" + str(new_user.user_id))
else:
if password_input != user.password:
flash("Incorrect password, try again")
return redirect("/login")
else:
flash("Login successful")
session['logged_in_user'] = user.user_id
return redirect("/users/" + str(user.user_id))
示例2: process_login
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import add_new_user [as 别名]
def process_login():
"""Log user into siteself.
Find the user's login credentials located in the 'request.form'
dictionary, look up the user, and store them in the session.
"""
email_input = request.form.get("email")
pword_input = request.form.get("password")
user = User.query.filter_by(email=email_input).first()
print "******************", user
if user is None:
flash("Welcome new user!")
new_user = User.add_new_user(email=email_input, password=pword_input)
session['logged_in_user'] = new_user.user_id
return redirect("/users/" + str(new_user.user_id))
else:
if pword_input != user.password:
flash("Incorrect password, try again")
return redirect("/login")
else:
flash("Login successful!!")
session['logged_in_user'] = user.user_id
return redirect("/users/" + str(user.user_id))
示例3: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import add_new_user [as 别名]
def post(self):
try:
name = self.get_argument("name")
password = self.get_argument("password")
except:
self.redirect('%s/admin/login'% BASE_URL)
return
if name and password:
has_user = User.check_has_user()
if has_user:
#check user
password = md5(password.encode('utf-8')).hexdigest()
user = User.check_user( name, password)
if user:
#logging.error('user ok')
self.set_cookie('username', name, path="/", expires_days = 365 )
self.set_cookie('userpw', password, path="/", expires_days = 365 )
self.redirect('%s/admin/'% BASE_URL)
return
else:
#logging.error('user not ok')
self.redirect('%s/admin/login'% BASE_URL)
return
else:
#add new user
newuser = User.add_new_user( name, password)
if newuser:
self.set_cookie('username', name, path="/", expires_days = 365 )
self.set_cookie('userpw', md5(password.encode('utf-8')).hexdigest(), path="/", expires_days = 365 )
self.redirect('%s/admin/'% BASE_URL)
return
else:
self.redirect('%s/admin/login'% BASE_URL)
return
else:
self.redirect('%s/admin/login'% BASE_URL)