コード例 #1
0
def signup():
    if current_user.is_authenticated:
        return redirect(request.args.get('next') or url_for('home.index'))
    form = RegisterForm()
    if form.validate_on_submit():
        username = request.form.get('username')
        email = request.form.get('email')
        password = request.form.get('password')
        user = User(username=username, email=email,password=password)
        email_suffix = email.split('@')[-1]
        if email_suffix == 'mail.ustc.edu.cn':
            user.identity = 'Student'
        elif email_suffix == 'ustc.edu.cn':
            user.identity = 'Teacher'
            ok,message = user.bind_teacher(email)
            #TODO: deal with bind feedback
        else:
            #TODO: log Intenal error!
            pass
        send_confirm_mail(user.email)
        user.save()
        #login_user(user)
        '''注册完毕后显示一个需要激活的页面'''
        return render_template('feedback.html', status=True, message=_('我们已经向您发送了激活邮件,请在邮箱中点击激活链接。如果您没有收到邮件,有可能是在垃圾箱中。'))
#TODO: log error
    if form.errors:
        print(form.errors)
    return render_template('signup.html',form=form)
コード例 #2
0
def confirm_email():
    if current_user.is_authenticated:
        #logout_user()
        return redirect(request.args.get('next') or url_for('home.index'))
    action = request.args.get('action')
    if action == 'confirm':
        token = request.args.get('token')
        if not token:
            return render_template('feedback.html', status=False, message=_('此激活链接无效,请准确复制邮件中的链接。'))
        if RT.query.get(token):
            return render_template('feedback.html', status=False, message=_('此激活链接已被使用过。'))
        RT.add(token)
        try:
            email = ts.loads(token, salt="email-confirm-key", max_age=86400)
        except:
            abort(404)

        user = User.query.filter_by(email=email).first_or_404()
        user.confirm()
        flash(_('Your email has been confirmed'))
        login_user(user)
        return redirect(url_for('home.index'))
    elif action == 'send':
        email = request.args.get('email')
        user = User.query.filter_by(email=email).first_or_404()
        print(user)
        if not user.confirmed:
            print(email)
            send_confirm_mail(email)
        return render_template('feedback.html', status=True, message=_('邮件已经发送,请查收!'))
    else:
        abort(404)
コード例 #3
0
#!/usr/bin/env python3
import sys
sys.path.append('..')  # fix import directory

from app import app
from app.utils import send_confirm_mail
from app.models import User

# require an app context to work
ctx = app.test_request_context()
ctx.push()

users = User.query.filter(User.confirmed_at == None).all()
for user in users:
    if user.email == '':
        continue
    print(user.email)
    send_confirm_mail(user.email)
コード例 #4
0
#!/usr/bin/env python3
import sys
sys.path.append('..')  # fix import directory

from app import app
from app.utils import send_confirm_mail
from app.models import User

# require an app context to work
ctx = app.test_request_context()
ctx.push()

users = User.query.filter(User.confirmed_at == None).all()
for user in users:
        if user.email == '':
                continue
        print(user.email)
        send_confirm_mail(user.email)