Beispiel #1
0
def forget():
    '''忘记密码'''
    error = None
    form = ForgetPasswdForm()
    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:
            exsited_email = User.query.filter_by(
                email=form.confirm_email.data).first()
            if exsited_email:
                '''email模板'''
                from random import sample
                from string import ascii_letters, digits
                npasswd = ''.join(sample(ascii_letters + digits, 8))
                exsited_email.passwd = generate_password_hash(npasswd)
                db.session.commit()
                html = render_template('templet/forget.html',
                                       confirm_url=npasswd)
                subject = "请及时修改你的密码"
                email_send(form.confirm_email.data, html, subject)
                flash(u'邮件已发送到你的邮箱,请及时查收并修改密码')
                return jsonify(judge=True, error=error)
            else:
                error = u'邮箱未注册'
                return jsonify(judge=False, error=error)
    else:
        if form.errors:
            return return_errors(form)
        else:
            pass
        return render_template('auth/forget.html', form=form)
Beispiel #2
0
def forget():
    '''忘记密码'''
    error = None
    form = ForgetPasswdForm()
    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:
            exsited_email = User.query.filter_by(
                email=form.confirm_email.data).first()
            if exsited_email:
                '''email模板'''
                from random import sample
                from string import ascii_letters, digits
                npasswd = ''.join(sample(ascii_letters + digits, 8))
                exsited_email.passwd = generate_password_hash(npasswd)
                db.session.commit()
                html = render_template('templet/forget.html',
                                       confirm_url=npasswd)
                subject = "Please update your password in time"
                email_send(form.confirm_email.data, html, subject)
                flash(_(
                    'An email has been sent to you.Please receive and update your password in time'))
                return jsonify(judge=True, error=error)
            else:
                error = _('The email is error')
                return jsonify(judge=False, error=error)
    else:
        if form.errors:
            return return_errors(form)
        else:
            pass
        return render_template('auth/forget.html', form=form)
Beispiel #3
0
def forget():
    '''忘记密码'''
    error = None
    form = ForgetPasswdForm()
    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:
            exsited_email = User.query.filter_by(
                email=form.confirm_email.data).first()
            if exsited_email:
                '''email模板'''
                from random import sample
                from string import ascii_letters, digits
                npasswd = ''.join(sample(ascii_letters + digits, 8))
                exsited_email.passwd = generate_password_hash(npasswd)
                db.session.commit()
                html = render_template('templet/forget.html',
                                       confirm_url=npasswd)
                subject = "Please update your password in time"
                email_send(form.confirm_email.data, html, subject)
                flash(_(
                    'An email has been sent to you.Please receive and update your password in time'))
                return jsonify(judge=True, error=error)
            else:
                error = _('The email is error')
                return jsonify(judge=False, error=error)
    else:
        if form.errors:
            return return_errors(form)
        else:
            pass
        return render_template('auth/forget.html', form=form)
Beispiel #4
0
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)
Beispiel #5
0
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)
Beispiel #6
0
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)
Beispiel #7
0
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)