Example #1
0
def load_online_users(mode):
    if mode == 'counts':
        counts = len(load_online_all_users()) - len(load_online_sign_users())
        return counts
    if mode == 'all_counts':
        counts = len(load_online_all_users())
        high = redis_data.hget('online_users', 'high:counts')
        if counts > int(high):
            redis_data.hset('online_users', 'high:counts', counts)
            redis_data.hset('online_users', 'high:time', int(time()) + 28800)
        return counts
    if mode == 'sign_counts':
        return len(load_online_sign_users())
    if mode == 'high':
        counts = redis_data.hget('online_users', 'high:counts')
        return int(counts)
    if mode == 'high_time':
        high_time = redis_data.hget('online_users', 'high:time')
        return datetime.utcfromtimestamp(int(high_time))
Example #2
0
def load_online_users(mode):
    if mode == 'counts':
        counts = len(load_online_all_users()) - len(load_online_sign_users())
        return counts
    if mode == 'all_counts':
        counts = len(load_online_all_users())
        high = redis_data.hget('online_users', 'high:counts')
        if counts > int(high):
            redis_data.hset('online_users', 'high:counts', counts)
            redis_data.hset('online_users', 'high:time', int(time()) + 28800)
        return counts
    if mode == 'sign_counts':
        return len(load_online_sign_users())
    if mode == 'high':
        counts = redis_data.hget('online_users', 'high:counts')
        return int(counts)
    if mode == 'high_time':
        high_time = redis_data.hget('online_users', 'high:time')
        return datetime.utcfromtimestamp(int(high_time))
Example #3
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)
Example #4
0
def load_online_users(mode):
    if mode == 1:
        online_users = load_online_all_users()
        high_online = redis_data.hget('online_users', 'high:counts')
        count = len(online_users)
        if int(high_online) < count:
            redis_data.hset('online_users', 'high:counts', count)
            redis_data.hset('online_users', 'high:time', int(time()) + 28800)
        return count
    if mode == 2:
        # 'online sign users'
        online_users = load_online_sign_users()
        return len(online_users)
    if mode == 3:
        # 'guest users'
        online_users = load_online_all_users()
        online_sign_users = load_online_sign_users()
        return len(online_users) - len(online_sign_users)
    if mode == 4:
        counts = redis_data.hget('online_users', 'high:counts')
        return counts
    if mode == 5:
        high_time = redis_data.hget('online_users', 'high:time')
        return datetime.utcfromtimestamp(int(high_time))
Example #5
0
def set_email_send(uid):
    redis_data.hset('user:%s' % str(uid), 'send_email_time', datetime.utcnow())
Example #6
0
def notice():
    '''未读提醒'''
    user = '******' % str(current_user.id)
    redis_data.hset(user, 'notice', 0)
    messages = Message.query.filter_by(rece_user=current_user.name).all()
    return render_template('user/user_notice.html', messages=messages)
Example #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)
Example #8
0
def notice():
    '''未读提醒'''
    user = '******' % str(current_user.id)
    redis_data.hset(user, 'notice', 0)
    messages = Message.query.filter_by(rece_user=current_user.name).all()
    return render_template('user/user_notice.html', messages=messages)
Example #9
0
def set_email_send(uid):
    redis_data.hset('user:%s' % str(uid), 'send_email_time',
                    datetime.now())