コード例 #1
0
def change_email(token):
    if validate_token(token=token,
                      user=current_user,
                      operation=Operation.CHANGE_EMAIL):
        flash('Email updated', 'success')
        return redirect(url_for('.index', username=current_user.username))
    else:
        flash('Invalid or expired token.', 'warning')
        return redirect(url_for('.change_email_request'))
コード例 #2
0
def change_email(token):
    if validate_token(user=current_user,
                      token=token,
                      operation=Operations.CHANGE_EMAIL):
        flash('已更换邮箱', 'success')
        return redirect(url_for('.index', username=current_user.username))
    else:
        flash('token无效或过期', 'warning')
        return redirect(url_for('.change_email_request'))
コード例 #3
0
ファイル: user.py プロジェクト: jiangyue0013/albumy
def change_email(token):
    if validate_token(user=current_user,
                      token=token,
                      operation=Operations.CHANGE_EMAIL):
        flash("Email updated.", "success")
        return redirect(url_for("user.index", username=current_user.username))
    else:
        flash("Invalid or expired token.", "warning")
        return redirect(url_for("user.change_email_request"))
コード例 #4
0
def change_email(token):
    if validate_token(user=current_user,
                      token=token,
                      operation=Operations.CHANGE_EMAIL):
        flash('邮箱地址修改成功。', 'success')
        return redirect(url_for('main.index'))
    else:
        flash('无效或超时。', 'danger')
        return redirect(url_for('user.change_email_request'))
コード例 #5
0
def confirm(token):
	if current_user.confirmed:
		return redirect(url_for('main.index'))
	
	if validate_token(user=current_user, token=token, operation=Operations.CONFIRM):
		flash('Account confirmed.', 'success')
		return redirect(url_for('main.index'))
	else:
		flash('Invalid or expired token.', 'danger')
		return redirect(url_for('.resend_confirm_email'))
コード例 #6
0
ファイル: auth.py プロジェクト: haichong98/albumy
def confirm(token):
    if current_user.confirmed:
        return redirect(url_for('main.index'))

    if validate_token(user=current_user,
                      token=token,
                      operation=Operations.CONFIRM):
        flash('账号确认成功', 'success')
        return redirect(url_for('main.index'))
    else:
        flash('验证失败或者会话过期', 'danger')
        return redirect(url_for('.resend_confirm_email'))
コード例 #7
0
def confirm(token):
    if current_user.confirmed:
        return redirect(url_for("main.index"))

    if validate_token(user=current_user,
                      token=token,
                      operation=Operations.CONFIRM):
        flash("Account confirmed.", "success")
        return redirect(url_for("main.index"))
    else:
        flash("Invalid or expired token.", "danger")
        return redirect(url_for("auth.resend_confirm_email"))
コード例 #8
0
def change_email(token):
	"""
	修改邮箱
	:param token: 从邮箱中点击链接携带的token
	"""
	logger.info('url = ' + str(request.url))
	if validate_token(user=current_user, token=token, operation=Operations.CHANGE_EMAIL):
		flash('邮箱更新成功!', 'success')
		return redirect(url_for('.index', username=current_user.username))
	else:
		flash('无效或过期的token!', 'warning')
		return redirect(url_for('.change_email_request'))
コード例 #9
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = ResetPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user is None:
            return False
        if validate_token(user=user, token=token, operation=Operations.RESET_PASSWORD, new_password=form.password.data):
            flash('Password updated', 'info')
            return redirect(url_for('auth.login'))
        else:
            flash('Invalid or expired token', 'danger')
            return redirect(url_for('auth.forget_password'))
    return render_template('auth/reset_password.html', form=form)
コード例 #10
0
ファイル: auth.py プロジェクト: zhengpanone/flask_web
def confirm(token):
    """
    确认令牌
    :param token:
    :return:
    """
    if current_user.confirmed:
        return redirect(url_for('main.index'))
    if validate_token(user=current_user,
                      token=token,
                      operation=Operations.CONFIRM):
        flash("Account confirmed.", 'success')
        return redirect(url_for('main.index'))
    else:
        flash('Invalid or expired token.', 'danger')
        return redirect(url_for('auth.resend_confirmation'))
コード例 #11
0
ファイル: auth.py プロジェクト: MoonMonsters/GodAlbumy
def confirm(token):
	"""
	验证邮箱
	:param token: register中通过邮件发送的token,有时间限制
	"""
	logger.info('url = ' + str(request.url))
	# 如果已经验证通过,不需要重复验证
	if current_user.confirmed:
		return redirect(url_for('main.index'))

	# 验证token
	if validate_token(user=current_user, token=token, operation=Operations.CONFIRM):
		flash('验证通过!', 'success')
		return redirect(url_for('main.index'))
	else:
		flash('无效或过期的token!', 'danger')
		# 重新发送邮件
		return redirect(url_for('.resend_confirm_email'))
コード例 #12
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = ResetPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user is None:
            flash('用户不存在!', 'warning')
            return redirect(url_for('main.index'))
        if validate_token(user=user,
                          token=token,
                          operation=Operations.RESET_PASSWORD,
                          new_password=form.password.data):  # 传入新密码
            flash('重置密码成功。', 'success')
            return redirect(url_for('.login'))

    return render_template('auth/reset_password.html', form=form)
コード例 #13
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))

    form = ResetPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user is None:
            return redirect(url_for("main.index"))
        if validate_token(user=user,
                          token=token,
                          operation=Operations.RESET_PASSWORD,
                          new_password=form.password.data):
            flash("Password updated successfully.", "success")
            return redirect(url_for("auth.login"))
        else:
            flash("Invalid or expired link.", "danger")
            return redirect(url_for("auth.forget_password"))
    return render_template("auth/reset_password.html", form=form)
コード例 #14
0
def reset_password(token):
	if current_user.is_authenticated:
		return redirect(url_for('main.index'))
	
	form = ResetPasswordForm()
	if form.validate_on_submit():
		email = form.email.data.lower()
		user = User.query.filter_by(email=email).first()
		if not user:
			return redirect(url_for('main.index'))
		new_password = form.password.data
		if validate_token(user, token, Operations.RESET_PASSWORD, new_password=new_password):
			flash('Password updated', 'success')
			return redirect(url_for('.login'))
		else:
			flash('Invalid or expired link.', 'danger')
			return redirect(url_for('.forget_password'))
	# 问题:如何针对未登录用户进行验证?要怎么修改?user参数怎么传?
	# 在post时候再验证
	return render_template('auth/reset_password.html', form=form)