Exemplo n.º 1
0
 def set_user_all():
     redis_data.hincrby('user:%s' % str(current_user.id), 'all_topic', 1)
Exemplo n.º 2
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)
Exemplo n.º 3
0
 def set_collect(user,num):
     redis_data.hincrby('user:%s' % str(user.id), 'collect', num)
Exemplo n.º 4
0
 def set_love(user,num):
     redis_data.hincrby('user:%s' % str(user.id), 'love', num)
Exemplo n.º 5
0
 def set_read_count(qid):
     redis_data.hincrby('question:%s' % str(qid), 'read', 1)
Exemplo n.º 6
0
 def set_notice(user):
     redis_data.hincrby('user:%s' % str(user.id), 'notice', 1)
Exemplo n.º 7
0
 def set_collect(user, num):
     redis_data.hincrby('user:%s' % str(user.id), 'collect', num)
Exemplo n.º 8
0
 def set_read_count(qid):
     redis_data.hincrby('topic:%s' % str(qid), 'read', 1)
Exemplo n.º 9
0
 def set_notice(user):
     redis_data.hincrby('user:%s' % str(user.id), 'notice', 1)
Exemplo n.º 10
0
 def set_read_count(qid):
     redis_data.hincrby('question:%s' % str(qid), 'read', 1)
Exemplo n.º 11
0
 def set_user_all():
     redis_data.hincrby('user:%s' % str(current_user.id), 'all_topic', 1)
Exemplo n.º 12
0
 def set_love(user, num):
     redis_data.hincrby('user:%s' % str(user.id), 'love', num)
Exemplo n.º 13
0
 def set_read_count(qid):
     redis_data.hincrby('topic:%s' % str(qid), 'read', 1)