コード例 #1
0
ファイル: views.py プロジェクト: RayYu03/maple-blog
def register():
    error = None
    form = RegisterForm()
    if form.validate_on_submit() and request.method == "POST":
        validate_code = session['validate_code']
        validate = form.code.data
        if validate.lower() != validate_code.lower():
            return jsonify(judge=False, error=_('The validate code is error'))
        else:
            useremail = User.load_by_email(form.email.data)
            username = User.load_by_name(form.name.data)
            if username is not None:
                error = _('The name has been registered')
                return jsonify(judge=False, error=error)
            elif useremail is not None:
                error = _('The email has been registered')
                return jsonify(judge=False, error=error)
            else:
                account = User()
                account.name = form.name.data,
                account.email = form.email.data,
                account.passwd = form.passwd.data,
                account.roles = 'visitor'
                account.registered_time = datetime.now()
                '''邮箱验证'''
                token = email_token(account.email)
                confirm_url = url_for('auth.confirm',
                                      token=token,
                                      _external=True)
                html = render_template('templet/email.html',
                                       confirm_url=confirm_url)
                subject = _("Please confirm  your email")
                # email_send(account.email, html, subject)

                account.send_email_time = datetime.now()
                db.session.add(account)
                db.session.commit()

                login_user(account)
                identity_changed.send(current_app._get_current_object(),
                                      identity=Identity(account.id))
                flash(_('An email has been sent to your.Please receive'))
                return jsonify(judge=True, error=error)
    else:
        if form.errors:
            return return_errors(form)
        else:
            pass
        return render_template('auth/register.html', form=form)
コード例 #2
0
ファイル: views.py プロジェクト: KohTseh/maple-blog
def register():
    error = None
    form = RegisterForm()
    if form.validate_on_submit() and request.method == "POST":
        validate_code = session['validate_code']
        validate = form.code.data
        if validate.lower() != validate_code.lower():
            return jsonify(judge=False, error=_('The validate code is error'))
        else:
            useremail = User.load_by_email(form.email.data)
            username = User.load_by_name(form.name.data)
            if username is not None:
                error = _('The name has been registered')
                return jsonify(judge=False, error=error)
            elif useremail is not None:
                error = _('The email has been registered')
                return jsonify(judge=False, error=error)
            else:
                account = User()
                account.name = form.name.data,
                account.email = form.email.data,
                account.passwd = form.passwd.data,
                account.roles = 'visitor'
                account.registered_time = datetime.now()
                '''邮箱验证'''
                token = email_token(account.email)
                confirm_url = url_for('auth.confirm',
                                      token=token,
                                      _external=True)
                html = render_template('templet/email.html',
                                       confirm_url=confirm_url)
                subject = _("Please confirm  your email")
                # email_send(account.email, html, subject)

                account.send_email_time = datetime.now()
                db.session.add(account)
                db.session.commit()

                login_user(account)
                identity_changed.send(current_app._get_current_object(),
                                      identity=Identity(account.id))
                flash(_('An email has been sent to your.Please receive'))
                return jsonify(judge=True, error=error)
    else:
        if form.errors:
            return return_errors(form)
        else:
            pass
        return render_template('auth/register.html', form=form)
コード例 #3
0
ファイル: views.py プロジェクト: shiguol/maple-bbs
def confirm_email():
    if request.method == "POST":
        if not time_permission.allow():
            return time_permission.action()
        else:
            token = email_token(current_user.email)
            '''email模板'''
            confirm_url = url_for('auth.confirm', token=token, _external=True)
            html = render_template(
                'templet/email.html',
                confirm_url=confirm_url)
            subject = "Please confirm your email"
            email_send(current_user.email, html, subject)
            from time import time
            time = int(time()) + 28800
            user = '******' % str(current_user.id)
            redis_data.hset(user, 'send_email_time', time)
            error = '一封验证邮件已发往你的邮箱,請查收.'
            return error
    else:
        abort(404)
コード例 #4
0
ファイル: views.py プロジェクト: RayYu03/maple-blog
def confirm_email():
    if request.method == "POST":
        if current_user.is_confirmed:
            return jsonify(
                judge=False,
                error=_('Your account has been confirmed,don\'t need again'))
        else:
            token = email_token(current_user.email)
            '''email模板'''
            confirm_url = url_for('auth.confirm', token=token, _external=True)
            html = render_template('templet/email.html',
                                   confirm_url=confirm_url)
            subject = _("Please confirm your email")
            email_send(current_user.email, html, subject)
            flash(_('An email has been sent to your.Please receive'))
            current_user.send_email_time = datetime.now()
            db.session.commit()
            return jsonify(
                judge=True,
                error=_('An email has been sent to your.Please receive'))
    else:
        abort(404)
コード例 #5
0
ファイル: views.py プロジェクト: KohTseh/maple-blog
def confirm_email():
    if request.method == "POST":
        if current_user.is_confirmed:
            return jsonify(
                judge=False,
                error=_('Your account has been confirmed,don\'t need again'))
        else:
            token = email_token(current_user.email)
            '''email模板'''
            confirm_url = url_for('auth.confirm', token=token, _external=True)
            html = render_template('templet/email.html',
                                   confirm_url=confirm_url)
            subject = _("Please confirm your email")
            email_send(current_user.email, html, subject)
            flash(_('An email has been sent to your.Please receive'))
            current_user.send_email_time = datetime.now()
            db.session.commit()
            return jsonify(
                judge=True,
                error=_('An email has been sent to your.Please receive'))
    else:
        abort(404)
コード例 #6
0
ファイル: views.py プロジェクト: shiguol/maple-bbs
def register():
    error = None
    form = RegisterForm()
    if form.validate_on_submit() and request.method == "POST":
        validate_code = session['validate_code']
        validate = form.code.data
        if validate.lower() != validate_code.lower():
            return jsonify(judge=False, error=u'验证码错误')
        else:
            useremail = User.load_by_email(form.email.data)
            username = User.load_by_name(form.name.data)
            if username is not None:
                error = u'用户名已存在'
                return jsonify(judge=False, error=error)
            elif useremail is not None:
                error = u'邮箱已被注册'
                return jsonify(judge=False, error=error)
            else:
                account = User(name=form.name.data,
                               email=form.email.data,
                               passwd=form.passwd.data)
                userinfor = UserInfor()
                usersetting = UserSetting()
                roles = Role(name='unconfirmed', rank=1)
                account.infor = userinfor
                account.setting = usersetting
                account.roles.append(roles)
                '''邮箱验证'''
                token = email_token(account.email)
                confirm_url = url_for('auth.confirm',
                                      token=token,
                                      _external=True)
                html = render_template('templet/email.html',
                                       confirm_url=confirm_url)
                subject = "请验证你的邮箱"
                email_send(account.email, html, subject)

                db.session.add(account)
                db.session.commit()
                '''记录用户数'''
                redis_data.hincrby('user', 'all:count', 1)

                login_user(account)
                identity_changed.send(current_app._get_current_object(),
                                      identity=Identity(account.id))
                '''发送邮件时间'''
                from time import time
                time = int(time()) + 28800
                user = '******' % str(current_user.id)
                redis_data.hset(user, 'send_email_time', time)
                flash(u'一封验证邮件已发往你的邮箱,請查收.')
                return jsonify(judge=True, error=error)
    else:
        if form.errors:
            return return_errors(form)
        else:
            pass
        if request.args.get('mode') == 'agree':
            return render_template('auth/register.html',
                                   form=form,
                                   error=error)
        else:
            return render_template('auth/register_service.html',
                                   form=form,
                                   error=error)