def register(): form = RegisterForm() if form.validate_on_submit(): user = User() user.email = form.email.data user.name = form.name.data user.password = form.password.data if user.email == current_app.config['MAIL_USERNAME']: # 管理员 user.role = Role.query.filter_by(name='admin').first() else: user.role = Role.query.filter_by(default=True).first() db.session.add(user) db.session.commit() # 产生API—KEY user.generate_api_token() # 发送邮件 token = user.generate_confirmed_token() html = render_template('email/register.html', token=token, user_name=user.name) send_async_email(subject='验证', recvs=[user.email], body=None, html=html) return redirect(url_for('main.index')) return render_template('auth/register.html', form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): user = User() user.email = form.email.data user.name = form.name.data user.password = form.password.data # 'user','moderotor','admin' # 如果用户注册的邮箱和config.py中发送邮件的邮箱一样,那么这个用户分配管理员 if user.email == current_app.config['MAIL_USERNAME']: user.role = Role.query.filter_by(name='admin').first() else: user.role = Role.query.filter_by(default=True).first() # 其他用户都设置为user角色 db.session.add(user) db.session.commit() user.generate_api_token() # 发送邮件 token = user.generate_confirmed_token() html = render_template('email/register.html', token=token, user_name=user.name) send_async_email(subject='物联网云平台邮件', recvs=[user.email], body=None, html=html) flash('恭喜!注册成功!赶紧登陆!') return redirect(url_for('.login')) return render_template('auth/register.html', form=form)
def resend_email(): # 发送邮件 token = current_user.generate_confirmed_token() html = render_template('email/register.html', token=token, user_name=current_user.name) send_async_email(subject='验证', recvs=[current_user.email], body=None, html=html) return redirect(url_for('main.index'))