Esempio n. 1
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('login'))
    return render_template('register.html', title='用户注册', form=form)
Esempio n. 2
0
def register(): #註冊的方法
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form= RegisterForm() #從forms.py內的RegisterForm()導入數據
    if form.validate_on_submit(): #驗證成功送出時將新使用者導入資料庫的步驟
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('login')) #註冊成功跳回登錄頁面
    #如果有問題會保持在註冊頁面
    return render_template('register.html', title='Registration',form=form)
Esempio n. 3
0
def user_activate(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_jwt(token)
    if not user:
        msg = "Token has expired, please try to re-send email."
    else:
        user.is_activated = True
        db.session.commit()
        msg = 'User has been activated!'
    return render_template('user_activated.html', msg=msg)
Esempio n. 4
0
def user_activate(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_jwt(token)
    if not user:
        msg = "令牌失效,请重新发送邮件!"
    else:
        user.is_activated = True
        db.session.commit()
        msg = '用户账号已激活!'
    return render_template('user_activate.html', msg=msg)
Esempio n. 5
0
def password_reset(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_jwt(token)
    if not user:
        return redirect(url_for('login'))
    form = PasswdResetForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        return redirect(url_for('login'))
    return render_template('password_reset.html', title='密码重置', form=form)
Esempio n. 6
0
def password_reset(token):
    if current_user.is_authenticated: #如果當前用戶已經登入不需要重置密碼
        return redirect(url_for('index'))
    user = User.verify_jwt(token)
    if not user: #不是用戶(錯誤或過期) 引導註冊
        return redirect(url_for('login'))
    form = PasswdResetForm() #經過兩關 代表有效用戶 顯示表單
    if form.validate_on_submit(): #如果重設密碼表單已經送出
        user.set_password(form.password.data)
        db.session.commit()
        return redirect(url_for('login'))
    return render_template('password_reset.html', title="Password Reset", form=form)
Esempio n. 7
0
def user_activate(token):
    if current_user.is_authenticated: #如果當前用戶已經登入
        #return redirect(url_for('index'))
        if current_user.is_activated: #而且當前用戶已經激活
            msg= "已驗證通過,不需重複驗證"
            return render_template('user_activate.html',msg=msg)
    user = User.verify_jwt(token)
    if not user: #不是用戶(錯誤或過期) 引導註冊
        msg= "驗證碼已過期 請重新驗證"
    else: #驗證碼有效的處理模式
        user.is_activated = True
        db.session.commit()
        msg="成功驗證使用者信箱"
    return render_template('user_activate.html',msg=msg)