本文整理汇总了Python中models.user.User.set_password方法的典型用法代码示例。如果您正苦于以下问题:Python User.set_password方法的具体用法?Python User.set_password怎么用?Python User.set_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.set_password方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: signup
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import set_password [as 别名]
def signup():
if current_user.is_authenticated():
return redirect(url_for('tickets'))
form = SignupForm(request.form, next=request.args.get('next'))
if request.method == 'POST' and form.validate():
user = User(form.email.data, form.name.data)
user.set_password(form.password.data)
db.session.add(user)
try:
db.session.commit()
except IntegrityError, e:
app.logger.warn('Adding user raised %r, assuming duplicate email', e)
flash("This email address %s is already in use. Please log in, or reset your password if you've forgotten it." % (form.email.data))
return redirect(url_for('login'))
login_user(user)
# send a welcome email.
msg = Message("Welcome to Electromagnetic Field",
sender=app.config['TICKETS_EMAIL'],
recipients=[user.email])
msg.body = render_template("welcome-email.txt", user=user)
mail.send(msg)
return redirect(form.next.data or url_for('tickets'))
示例2: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import set_password [as 别名]
def post(self):
form = RegisterForm(self.request.body_arguments)
if form.validate():
user = self.db.query(User).filter(User.email == form.email.data).first()
if user is not None:
form.email.errors.append('邮箱已被使用')
return self.render('auth/register.html', form=form)
user = User(email=form.email.data, name=form.username.data)
user.set_password(form.password.data)
self.db.add(user)
self.db.commit()
self.redirect(self.reverse_url('login'))
return self.render('auth/register.html', form=form)
示例3: signup
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import set_password [as 别名]
def signup():
if current_user.is_authenticated():
return redirect('/home')
form = SignupForm(request.form)
if form.email.data:
user = User(form.email.data)
user.set_password(form.password.data)
db.session.add(user)
db.session.commit()
login_user(user)
return redirect('/home')
return render_template('signup.html', form=form)
示例4: register
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import set_password [as 别名]
def register():
"""
注册一个新的用户
"""
template_var = {}
form = RegisterForm()
if request.method == "POST" and form.validate():
form = RegisterForm(request.form)
with session_cm() as session:
user = User()
user.username = form.username.data
user.nickname = form.nickname.data
user.email = form.email.data
user.set_password(form.password.data)
session.add(user)
if user is not None:
login_user(user)
session.commit()
return redirect(url_for('frontend.index'))
template_var['form'] = form
return render_template('account/register.html', **template_var)
示例5: signup
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import set_password [as 别名]
def signup():
if current_user.is_authenticated():
return redirect(url_for('tickets'))
form = SignupForm(request.form, next=request.args.get('next'))
if request.method == 'POST' and form.validate():
user = User(form.email.data, form.name.data)
user.set_password(form.password.data)
db.session.add(user)
try:
db.session.commit()
except IntegrityError, e:
flash("Email address %s is already in use, please use another or reset your password" % (form.email.data))
return redirect(url_for('signup'))
login_user(user)
# send a welcome email.
msg = Message("Welcome to Electromagnetic Field",
sender=app.config.get('TICKETS_EMAIL'),
recipients=[user.email])
msg.body = render_template("welcome-email.txt", user=user)
mail.send(msg)
return redirect(form.next.data or url_for('tickets'))