Exemple #1
0
def generate_recharge_cards():
    name = request.values.get('name')
    points = request.values.get('points')
    num = request.values.get('num')
    try:
        if int(num) <= 0:
            session['error_message'] = '数量填写错误'
            return redirect(url_for('recharge_cards'))
        if int(points) <= 0:
            session['error_message'] = '点数填写错误'
            return redirect(url_for('recharge_cards'))
        for i in range(0, int(num)):
            _chars = "0123456789ABCDEF"
            card_code = ''.join(random.sample(_chars, 16))
            if r_session.sismember('recharge_card_codes',
                                   card_code) or r_session.sismember(
                                       'used_card_codes', card_code):
                continue
            card = {}
            card['key'] = ''.join(random.sample(_chars, 16))
            card['code'] = card_code
            card['points'] = int(points)
            card['name'] = name
            card['status'] = '待售'
            r_session.sadd('recharge_card_codes', card_code)
            r_session.set('recharge_card:%s' % card_code, json.dumps(card))
    except Exception as e:
        session['error_message'] = e
    return redirect(url_for('recharge_cards'))
Exemple #2
0
def install():
    import random
    import uuid
    from util import hash_password

    if r_session.scard('users') == 0:
        _chars = "0123456789ABCDEF"
        username = "******"
        password = "******"
        #username = ''.join(random.sample(_chars, 6))
        #password = ''.join(random.sample(_chars, 6))

        user = dict(username=username,
                    password=hash_password(password),
                    id=str(uuid.uuid1()),
                    active=True,
                    is_admin=True,
                    max_account_no=5,
                    created_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
        r_session.set('%s:%s' % ('user', username), json.dumps(user))
        r_session.set('%s:%s' % ('record', username),
                      json.dumps(dict(diary=[])))
        r_session.sadd('users', username)
        return 'username:%s,password:%s' % (username, password)

    return redirect(url_for('login'))
Exemple #3
0
def generate_recharge_cards():
    name = request.values.get('name')
    points = request.values.get('points')
    num = request.values.get('num')
    try:
        if int(num) <= 0:
            session['error_message']='数量填写错误'
            return redirect(url_for('recharge_cards'))
        if int(points) <= 0:
            session['error_message']='点数填写错误'
            return redirect(url_for('recharge_cards'))
        for i in range(0, int(num)):
            _chars = "0123456789ABCDEF"
            card_code=''.join(random.sample(_chars, 16))
            if r_session.sismember('recharge_card_codes',card_code) or  r_session.sismember('used_card_codes',card_code):
                continue
            card={}
            card['key']=''.join(random.sample(_chars, 16))
            card['code']=card_code
            card['points']=int(points)
            card['name']=name
            card['status']='待售'
            r_session.sadd('recharge_card_codes', card_code)
            r_session.set('recharge_card:%s' % card_code, json.dumps(card))
    except Exception as e:
        session['error_message']=e
    return redirect(url_for('recharge_cards'))
Exemple #4
0
def generate_inv_code():
    _chars = "0123456789ABCDEF"
    r_session.smembers('invitation_codes')

    for i in range(0, 30 - r_session.scard('invitation_codes')):
        r_session.sadd('invitation_codes', ''.join(random.sample(_chars, 10)))

    return redirect(url_for('admin_invitation'))
Exemple #5
0
def generate_inv_code():
    _chars = "0123456789ABCDEF"
    r_session.smembers('invitation_codes')

    for i in range(0, 30 - r_session.scard('invitation_codes')):
        r_session.sadd('invitation_codes', ''.join(random.sample(_chars, 10)))

    return redirect(url_for('admin_invitation'))
Exemple #6
0
def __handshake():
    user = session.get('user_info')
    username = user.get('username')
    if username is None or not username:
        username = ''
    key = 'user:%s:is_online' % username
    # SETEX(KEY_NAME TIMEOUT VALUE)
    r_session.setex(key, '1', 120)
    r_session.sadd('global:online.users', username)
Exemple #7
0
def __handshake():
    user = session.get('user_info')
    username = user.get('username')
    if username is None or not username:
        username = ''
    key = 'user:%s:is_online' % username
    # SETEX(KEY_NAME TIMEOUT VALUE)
    r_session.setex(key, '1', 120)
    r_session.sadd('global:online.users', username)
Exemple #8
0
def pay_submit():
    session['action'] = 'info'
    user = session.get('user_info')
    pay_code = request.values.get('pay_code')
    pay_key = request.values.get('pay_key')
    if not r_session.sismember('recharge_card_codes', pay_code):
        session['error_message'] = '充值失败,充值卡不存在'
        return redirect(url_for('user_profile'))
    b_card = r_session.get('recharge_card:%s' % pay_code)
    if b_card is not None:
        card = json.loads(b_card.decode('utf-8'))
        if card['key'] == pay_key:
            user_key = '%s:%s' % ('user', user.get('username'))
            user_info = json.loads(r_session.get(user_key).decode('utf-8'))
            if 'total_account_point' in user_info.keys():
                user_info['total_account_point'] += card['points']
                if not user_info[
                        'active'] and user_info['total_account_point'] >= 0:
                    user_info['active'] = True
            else:
                session['error_message'] = '充值失败,新用户请等待后台准备好您的数据后重试,至多半小时后可以继续'
                return redirect(url_for('user_profile'))
            if user_info.get('max_account_no') is not None and user_info.get(
                    'max_account_no') > 0:
                days = int(
                    user_info.get('total_account_point') /
                    user_info.get('max_account_no'))
                if days < 36500:
                    user_info['expire_date'] = (
                        datetime.now() +
                        timedelta(days=days)).strftime('%Y-%m-%d')
                else:
                    user_info['expire_date'] = (
                        datetime.now() +
                        timedelta(days=36500)).strftime('%Y-%m-%d')
            r_session.set(user_key, json.dumps(user_info))
            points = user_info['total_account_point']
            user_info = json.loads(r_session.get(user_key).decode('utf-8'))
            if user_info['total_account_point'] != points:
                session['error_message'] = '充值失败,数据更新失败,请重试'
                return redirect(url_for('user_profile'))
            r_session.sadd('used_card_codes', pay_code)
            card['user'] = user.get('username')
            r_session.set('used_card:%s' % pay_code, json.dumps(card))
            r_session.srem('recharge_card_codes', pay_code)
            r_session.delete('recharge_card:%s' % pay_code)
            account_log(
                user.get('username'), '充值点数', '充值', '卡号:%s 冲入点数:%d 剩余:%d' %
                (pay_code, card['points'], user_info['total_account_point']))
        else:
            session['error_message'] = '充值失败,密码错误'
            return redirect(url_for('user_profile'))
    else:
        session['error_message'] = '充值失败,未知错误'
        return redirect(url_for('user_profile'))
    session['error_message'] = '充值成功'
    return redirect(url_for('user_profile'))
Exemple #9
0
def account_add():
    session['action']='one'

    account_name = request.values.get('xl_username')
    password = request.values.get('xl_password')
    md5_password = md5(password)

    user = session.get('user_info')

    accounts_key = 'accounts:%s' % user.get('username')

    user_key = '%s:%s' % ('user', user.get('username'))
    user_info = json.loads(r_session.get(user_key).decode('utf-8'))
    account_no = r_session.scard(accounts_key) + 1
    if user_info.get('account_limit') is not None and user_info['account_limit'] < account_no:
        session['error_message']='账户数量已达上限,无法完成添加'
        return redirect(url_for('accounts'))
    if account_no is not None:
        if account_no >= user_info.get('total_account_point'):
            session['error_message']='账户余额不足,无法完成添加'
            return redirect(url_for('accounts'))
        elif account_no >= user_info.get('max_account_no'):
            user_info['max_account_no'] = account_no
            days=int(user_info.get('total_account_point') / user_info.get('max_account_no'))
            if days<36500:
                user_info['expire_date'] = (datetime.now() + timedelta(days=days)).strftime('%Y-%m-%d')
            else:
                user_info['expire_date'] = (datetime.now() + timedelta(days=36500)).strftime('%Y-%m-%d')
            r_session.set(user_key, json.dumps(user_info))

    login_result = login(account_name, md5_password, app.config.get('ENCRYPT_PWD_URL'))
    if login_result.get('errorCode') != 0:
        error_message = login_result.get('errorDesc')
        session['error_message'] = '登陆失败,错误信息:%s。' % error_message
        return redirect(url_for('accounts'))

    xl_session_id = login_result.get('sessionID')
    xl_nick_name = login_result.get('nickName')
    xl_user_name = login_result.get('userName')
    xl_user_id = str(login_result.get('userID'))
    xl_user_new_no = str(login_result.get('userNewNo'))
    xl_account_name = account_name
    xl_password = md5_password

    r_session.sadd(accounts_key, xl_user_id)

    account_key = 'account:%s:%s' % (user.get('username'), xl_user_id)
    xl_account_data = dict(session_id=xl_session_id, nick_name=xl_nick_name, username=xl_user_name,
                           user_id=xl_user_id, user_new_no=xl_user_new_no, account_name=xl_account_name,
                           password=xl_password, active=True, status='OK',
                           createdtime=datetime.now().strftime('%Y-%m-%d %H:%M'))
    r_session.set(account_key, json.dumps(xl_account_data))

    return redirect(url_for('accounts'))
Exemple #10
0
def account_add():
    user = session.get('user_info')

    account_name = request.values.get('xl_username')
    password = request.values.get('xl_password')

    md5_password = md5(password)

    user_key = '%s:%s' % ('user', user.get('username'))
    user_info = json.loads(r_session.get(user_key).decode('utf-8'))

    if user_info.get('max_account_no') is None:
        user_info['max_account_no'] = 1

    accounts_key = 'accounts:%s' % user.get('username')

    account_no = r_session.scard(accounts_key)
    if account_no is not None:
        if account_no >= user_info.get('max_account_no'):
            session['error_message'] = '你的账号限制%d个账户。' % account_no
            return redirect(url_for('accounts'))

    login_result = login(account_name, md5_password,
                         app.config.get('ENCRYPT_PWD_URL'))
    if login_result.get('errorCode') != 0:
        error_message = login_result.get('errorDesc')
        session['error_message'] = '登陆失败,错误信息:%s。' % error_message
        return redirect(url_for('accounts'))

    xl_session_id = login_result.get('sessionID')
    xl_nick_name = login_result.get('nickName')
    xl_user_name = login_result.get('userName')
    xl_user_id = str(login_result.get('userID'))
    xl_user_new_no = str(login_result.get('userNewNo'))
    xl_account_name = account_name
    xl_password = md5_password

    r_session.sadd(accounts_key, xl_user_id)

    account_key = 'account:%s:%s' % (user.get('username'), xl_user_id)
    xl_account_data = dict(
        session_id=xl_session_id,
        nick_name=xl_nick_name,
        username=xl_user_name,
        user_id=xl_user_id,
        user_new_no=xl_user_new_no,
        account_name=xl_account_name,
        password=xl_password,
        active=True,
        status='OK',
        createdtime=datetime.now().strftime('%Y-%m-%d %H:%M'))
    r_session.set(account_key, json.dumps(xl_account_data))

    return redirect(url_for('accounts'))
Exemple #11
0
def register():
    if session.get('user_info') is not None:
        return redirect(url_for('dashboard'))

    err_msg = None
    if session.get('error_message') is not None:
        err_msg = session.get('error_message')
        session['error_message'] = None

    info_msg = None
    if session.get('info_message') is not None:
        info_msg = session.get('info_message')
        session['info_message'] = None

    invitation_code = ''
    if request.values.get('inv_code') is not None and len(
            request.values.get('inv_code')) > 0:
        invitation_code = request.values.get('inv_code')

    if request.values.get('active') is not None and len(
            request.values.get('active')) > 0:
        active_code = request.values.get('active')
        try:
            validate = base64.b64decode(active_code)
            code = validate.decode('utf-8')
        except Exception as e:
            session['error_message'] = '非法参数错误.'
            return redirect(url_for('register'))

        key = 'activecode:%s' % code
        activecode = r_session.get(key)
        if activecode is None:
            session['error_message'] = '激活帐户链接已失效.'
            return redirect(url_for('register'))

        user = json.loads(activecode.decode('utf-8'))

        r_session.set('%s:%s' % ('user', user.get('username')),
                      json.dumps(user))
        r_session.set('%s:%s' % ('record', user.get('username')),
                      json.dumps(dict(diary=[])))
        r_session.sadd('users', user.get('username'))
        r_session.sadd('email', user.get('email'))
        r_session.delete(key)

        session['info_message'] = '恭喜你,注册成功.'
        return redirect(url_for('register'))

    return render_template('register.html',
                           err_msg=err_msg,
                           info_msg=info_msg,
                           invitation_code=invitation_code)
Exemple #12
0
def register_user():
    email = request.values.get('username')
    username = request.values.get('username')
    password = request.values.get('password')
    re_password = request.values.get('re_password')
    r = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
    if re.match(r, email) is None:
        session['error_message'] = '邮箱地址格式不正确.'
        return redirect(url_for('add_user'))
    if username == '':
        session['error_message'] = '账号名不能为空。'
        return redirect(url_for('add_user'))
    if r_session.get('%s:%s' % ('user', username)) is not None:
        session['error_message'] = '该账号名已存在。'
        return redirect(url_for('add_user'))
    if password != re_password:
        session['error_message'] = '密码输入不一致.'
        return redirect(url_for('add_user'))
    if len(password) < 8:
        session['error_message'] = '密码必须8位及以上.'
        return redirect(url_for('add_user'))
    if r_session.sismember('email', email):
        session['error_message'] = '该邮件地址已被注册.'
        return redirect(url_for('add_user'))
    config_key = '%s:%s' % ('user', 'system')
    config_info = json.loads(r_session.get(config_key).decode('utf-8'))
    if 'trial_period' not in config_info.keys():
        config_info['trial_period'] = 14
    user = dict(username=username,
                password=hash_password(password),
                id=str(uuid.uuid1()),
                active=True,
                is_admin=False,
                max_account_no=1,
                email=email,
                total_account_point=config_info['trial_period'],
                created_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    days = int(user.get('total_account_point') / user.get('max_account_no'))
    if days < 36500:
        user['expire_date'] = (datetime.now() +
                               timedelta(days=days)).strftime('%Y-%m-%d')
    else:
        user['expire_date'] = (datetime.now() +
                               timedelta(days=36500)).strftime('%Y-%m-%d')
    r_session.set('%s:%s' % ('user', user.get('username')), json.dumps(user))
    r_session.set('%s:%s' % ('record', user.get('username')),
                  json.dumps(dict(diary=[])))
    r_session.sadd('users', user.get('username'))
    r_session.sadd('email', user.get('email'))
    session['info_message'] = '注册成功'
    return redirect(url_for('admin_user'))
Exemple #13
0
def user_register():
    invitation_code = request.values.get('invitation_code')

    if not r_session.sismember('invitation_codes', invitation_code) and \
    not r_session.sismember('public_invitation_codes', invitation_code):
        session['error_message'] = '无效的邀请码。'
        return redirect(url_for('register'))

    username = request.values.get('username')
    password = request.values.get('password')
    re_password = request.values.get('re_password')

    if username == '':
        session['error_message'] = '用户名不能为空.'
        return redirect(url_for('register'))

    if r_session.get('%s:%s' % ('user', username)) is not None:
        session['error_message'] = '该用户名已存在.'
        return redirect(url_for('register'))

    r = r"^[a-zA-Z0-9_.+-]+$"
    if re.match(r, username) is None:
        session['error_message'] = '用户名含有非法字符.'
        return redirect(url_for('register'))

    if len(username) < 6 or len(username) > 20:
        session['error_message'] = '用户名长度6~20个字符.'
        return redirect(url_for('register'))

    if password != re_password:
        session['error_message'] = '两次输入的密码不一致.'
        return redirect(url_for('register'))

    if len(password) < 8:
        session['error_message'] = '输入的密码必须8位数以上.'
        return redirect(url_for('register'))

    r_session.srem('invitation_codes', invitation_code)
    r_session.srem('public_invitation_codes', invitation_code)

    user = dict(username=username, password=hash_password(password), id=str(uuid.uuid1()),
                active=True, is_admin=False, max_account_no=20,
                created_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    r_session.set('%s:%s' % ('user', username), json.dumps(user))
    r_session.sadd('users', username)

    session['info_message'] = '恭喜你,注册成功.'
    return redirect(url_for('register'))
Exemple #14
0
def user_register():
    invitation_code = request.values.get('invitation_code')

    if not r_session.sismember('invitation_codes', invitation_code) and \
    not r_session.sismember('public_invitation_codes', invitation_code):
        session['error_message'] = '无效的邀请码。'
        return redirect(url_for('register'))

    username = request.values.get('username')
    password = request.values.get('password')
    re_password = request.values.get('re_password')

    if username == '':
        session['error_message'] = '用户名不能为空.'
        return redirect(url_for('register'))

    if r_session.get('%s:%s' % ('user', username)) is not None:
        session['error_message'] = '该用户名已存在.'
        return redirect(url_for('register'))

    r = r"(^[a-zA-Z]+[a-zA-Z0-9_-]+$)"
    if re.match(r, username) is None:
        session['error_message'] = '用户名由字母开头数字和下划线组成.'
        return redirect(url_for('register'))

    if len(username) < 6 or len(username) > 20:
        session['error_message'] = '用户名长度在6~20个字符之间.'
        return redirect(url_for('register'))

    if password != re_password:
        session['error_message'] = '两次输入的密码不一致.'
        return redirect(url_for('register'))

    if len(password) < 8:
        session['error_message'] = '输入的密码必须8位数以上.'
        return redirect(url_for('register'))

    r_session.srem('invitation_codes', invitation_code)
    r_session.srem('public_invitation_codes', invitation_code)

    user = dict(username=username, password=hash_password(password), id=str(uuid.uuid1()),
                active=True, is_admin=False, max_account_no=20,
                created_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    r_session.set('%s:%s' % ('user', username), json.dumps(user))
    r_session.sadd('users', username)

    session['info_message'] = '恭喜你,注册成功.'
    return redirect(url_for('register'))
Exemple #15
0
def pay_submit():
    session['action'] = 'info'
    user = session.get('user_info')
    pay_code = request.values.get('pay_code')
    pay_key = request.values.get('pay_key')
    if not r_session.sismember('recharge_card_codes',pay_code):
        session['error_message'] = '充值失败,充值卡不存在'
        return redirect(url_for('user_profile'))
    b_card = r_session.get('recharge_card:%s' % pay_code)
    if b_card is not None:
        card=json.loads(b_card.decode('utf-8'))
        if card['key'] == pay_key:
            user_key = '%s:%s' % ('user', user.get('username'))
            user_info = json.loads(r_session.get(user_key).decode('utf-8'))
            if 'total_account_point' in user_info.keys():
                user_info['total_account_point'] += card['points']
                if not user_info['active'] and user_info['total_account_point'] >= 0:
                    user_info['active'] = True
            else:
                session['error_message'] = '充值失败,新用户请等待后台准备好您的数据后重试,至多半小时后可以继续'
                return redirect(url_for('user_profile'))
            if user_info.get('max_account_no') is not None and user_info.get('max_account_no') > 0:
                days=int(user_info.get('total_account_point')/user_info.get('max_account_no'))
                if days<36500:
                    user_info['expire_date'] = (datetime.now() + timedelta(days=days)).strftime('%Y-%m-%d')
                else:
                    user_info['expire_date'] = (datetime.now() + timedelta(days=36500)).strftime('%Y-%m-%d')
            r_session.set(user_key,json.dumps(user_info))
            points=user_info['total_account_point']
            user_info = json.loads(r_session.get(user_key).decode('utf-8'))
            if user_info['total_account_point'] != points:
                session['error_message'] = '充值失败,数据更新失败,请重试'
                return redirect(url_for('user_profile'))
            r_session.sadd('used_card_codes', pay_code)
            card['user']=user.get('username')
            r_session.set('used_card:%s' % pay_code, json.dumps(card))
            r_session.srem('recharge_card_codes',pay_code)
            r_session.delete('recharge_card:%s' % pay_code)
            account_log(user.get('username'),'充值点数','充值','卡号:%s 冲入点数:%d 剩余:%d' % (pay_code,card['points'],user_info['total_account_point']))
        else:
            session['error_message'] = '充值失败,密码错误'
            return redirect(url_for('user_profile'))
    else:
        session['error_message'] = '充值失败,未知错误'
        return redirect(url_for('user_profile'))
    session['error_message'] = '充值成功'
    return redirect(url_for('user_profile'))
Exemple #16
0
def install():
    import random, uuid
    from util import hash_password

    if r_session.scard('users') == 0:
        _chars = "0123456789ABCDEF"
        username = ''.join(random.sample(_chars, 6))
        password = ''.join(random.sample(_chars, 6))

        user = dict(username=username, password=hash_password(password), id=str(uuid.uuid1()),
                    active=True, is_admin=True, max_account_no=2,
                    created_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
        r_session.set('%s:%s' % ('user', username), json.dumps(user))
        r_session.sadd('users', username)
        return 'username:%s,password:%s' % (username, password)

    return redirect(url_for('login'))
Exemple #17
0
def register():
    if session.get('user_info') is not None:
        return redirect(url_for('dashboard'))

    err_msg = None
    if session.get('error_message') is not None:
        err_msg = session.get('error_message')
        session['error_message'] = None

    info_msg = None
    if session.get('info_message') is not None:
        info_msg = session.get('info_message')
        session['info_message'] = None

    invitation_code = ''
    if request.values.get('inv_code') is not None and len(request.values.get('inv_code')) > 0 :
        invitation_code = request.values.get('inv_code')

    if request.values.get('active') is not None and len(request.values.get('active')) > 0 :
        active_code = request.values.get('active')
        try:
            validate = base64.b64decode(active_code)
            code = validate.decode('utf-8')
        except Exception as e:
            session['error_message'] = '非法参数错误.'
            return redirect(url_for('register'))

        key = 'activecode:%s' % code
        activecode = r_session.get(key)
        if activecode is None:
            session['error_message'] = '激活帐户链接已失效.'
            return redirect(url_for('register'))

        user = json.loads(activecode.decode('utf-8'))

        r_session.set('%s:%s' % ('user', user.get('username')), json.dumps(user))
        r_session.set('%s:%s' % ('record', user.get('username')), json.dumps(dict(diary=[])))
        r_session.sadd('users', user.get('username'))
        r_session.sadd('email', user.get('email'))
        r_session.delete(key)

        session['info_message'] = '恭喜你,注册成功.'
        return redirect(url_for('register'))

    return render_template('register.html', err_msg=err_msg, info_msg=info_msg, invitation_code=invitation_code)
Exemple #18
0
def user_register():
    email = request.values.get('username')
    invitation_code = request.values.get('invitation_code')
    username = request.values.get('username')
    password = request.values.get('password')
    re_password = request.values.get('re_password')

    if not r_session.sismember('invitation_codes', invitation_code) and \
            not r_session.sismember('public_invitation_codes', invitation_code):
        session['error_message'] = '无效的邀请码。'
        return redirect(url_for('register'))

    if username == '':
        session['error_message'] = '账号名不能为空。'
        return redirect(url_for('register'))

    if r_session.get('%s:%s' % ('user', username)) is not None:
        session['error_message'] = '该账号名已存在。'
        return redirect(url_for('register'))

    if password != re_password:
        session['error_message'] = '新密码输入不一致.'
        return redirect(url_for('register'))

    if len(password) < 8:
        session['error_message'] = '密码必须8位及以上.'
        return redirect(url_for('register'))

    r_session.srem('invitation_codes', invitation_code)
    r_session.srem('public_invitation_codes', invitation_code)

    user = dict(username=username,
                password=hash_password(password),
                id=str(uuid.uuid1()),
                active=True,
                is_admin=False,
                max_account_no=20,
                email=email,
                created_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    r_session.set('%s:%s' % ('user', username), json.dumps(user))
    r_session.set('%s:%s' % ('record', username), json.dumps(dict(diary=[])))
    r_session.sadd('users', username)

    session['info_message'] = '恭喜你,注册成功.'
    return redirect(url_for('register'))
Exemple #19
0
def account_add():
    # 获取表单提交的迅雷会员名和帐户密码
    account_name = request.values.get('xl_username')
    password = request.values.get('xl_password')
    md5_password = md5(password)

    user = session.get('user_info')

    accounts_key = 'accounts:%s' % user.get('username')

    if user.get('max_account_no') is None:
        user['max_account_no'] = 5

    account_no = r_session.scard(accounts_key)

    if account_no is not None:
        if account_no >= user.get('max_account_no'):
            session['error_message'] = '你的账号限制%d个账户。' % account_no
            return redirect(url_for('accounts'))

    login_result = login(account_name, md5_password,
                         app.config.get('ENCRYPT_PWD_URL'))
    if login_result.get('errorCode') != 0:
        error_message = login_result.get('errorDesc')
        session['error_message'] = '登陆失败,错误信息:%s。' % error_message
        return redirect(url_for('accounts'))

    xl_session_id = login_result.get('sessionID')
    xl_nick_name = login_result.get('nickName')
    xl_user_name = login_result.get('userName')
    xl_user_id = str(login_result.get('userID'))
    xl_user_new_no = str(login_result.get('userNewNo'))
    xl_account_name = account_name
    xl_password = md5_password

    r_session.sadd(accounts_key, xl_user_id)

    account_key = 'account:%s:%s' % (user.get('username'), xl_user_id)
    xl_account_data = dict(session_id=xl_session_id, nick_name=xl_nick_name, username=xl_user_name,
                           user_id=xl_user_id, user_new_no=xl_user_new_no, account_name=xl_account_name,
                           password=xl_password, active=True, status='OK',
                           createdtime=datetime.now().strftime('%Y-%m-%d %H:%M'))
    r_session.set(account_key, json.dumps(xl_account_data))

    return redirect(url_for('accounts'))
Exemple #20
0
def user_register():
    invitation_code = request.values.get("invitation_code")
    username = request.values.get("username")
    password = request.values.get("password")
    re_password = request.values.get("re_password")

    if not r_session.sismember("invitation_codes", invitation_code) and not r_session.sismember(
        "public_invitation_codes", invitation_code
    ):
        session["error_message"] = "无效的邀请码。"
        return redirect(url_for("register"))

    if username == "":
        session["error_message"] = "账号名不能为空。"
        return redirect(url_for("register"))

    if r_session.get("%s:%s" % ("user", username)) is not None:
        session["error_message"] = "该账号名已存在。"
        return redirect(url_for("register"))

    if password != re_password:
        session["error_message"] = "新密码输入不一致."
        return redirect(url_for("register"))

    if len(password) < 8:
        session["error_message"] = "密码必须8位及以上."
        return redirect(url_for("register"))

    r_session.srem("invitation_codes", invitation_code)
    r_session.srem("public_invitation_codes", invitation_code)

    user = dict(
        username=username,
        password=hash_password(password),
        id=str(uuid.uuid1()),
        active=True,
        is_admin=False,
        max_account_no=2,
        created_time=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
    )
    r_session.set("%s:%s" % ("user", username), json.dumps(user))
    r_session.sadd("users", username)
    return redirect(url_for("login"))
Exemple #21
0
def register_user():
    email = request.values.get('username')
    username = request.values.get('username')
    password = request.values.get('password')
    re_password = request.values.get('re_password')
    r = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
    if re.match(r, email) is None:
        session['error_message'] = '邮箱地址格式不正确.'
        return redirect(url_for('add_user'))
    if username == '':
        session['error_message'] = '账号名不能为空。'
        return redirect(url_for('add_user'))
    if r_session.get('%s:%s' % ('user', username)) is not None:
        session['error_message'] = '该账号名已存在。'
        return redirect(url_for('add_user'))
    if password != re_password:
        session['error_message'] = '密码输入不一致.'
        return redirect(url_for('add_user'))
    if len(password) < 8:
        session['error_message'] = '密码必须8位及以上.'
        return redirect(url_for('add_user'))
    if r_session.sismember('email', email):
        session['error_message'] = '该邮件地址已被注册.'
        return redirect(url_for('add_user'))
    config_key = '%s:%s' % ('user', 'system')
    config_info = json.loads(r_session.get(config_key).decode('utf-8'))
    if 'trial_period' not in config_info.keys():
        config_info['trial_period'] = 14
    user = dict(username=username, password=hash_password(password), id=str(uuid.uuid1()),
                active=True, is_admin=False, max_account_no=1, email=email,total_account_point=config_info['trial_period'],
                created_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    days=int(user.get('total_account_point')/user.get('max_account_no'))
    if days<36500:
        user['expire_date'] = (datetime.now() + timedelta(days=days)).strftime('%Y-%m-%d')
    else:
        user['expire_date'] = (datetime.now() + timedelta(days=36500)).strftime('%Y-%m-%d')
    r_session.set('%s:%s' % ('user', user.get('username')), json.dumps(user))
    r_session.set('%s:%s' % ('record', user.get('username')), json.dumps(dict(diary=[])))
    r_session.sadd('users', user.get('username'))
    r_session.sadd('email', user.get('email'))
    session['info_message'] = '注册成功'
    return redirect(url_for('admin_user'))
Exemple #22
0
def user_register():
    invitation_code = request.values.get('invitation_code')
    username = request.values.get('username')
    password = request.values.get('password')
    re_password = request.values.get('re_password')

    if not r_session.sismember('invitation_codes', invitation_code) and \
            not r_session.sismember('public_invitation_codes', invitation_code):
        session['error_message'] = '无效的邀请码。'
        return redirect(url_for('register'))

    if username == '':
        session['error_message'] = '账号名不能为空。'
        return redirect(url_for('register'))

    if r_session.get('%s:%s' % ('user', username)) is not None:
        session['error_message'] = '该账号名已存在。'
        return redirect(url_for('register'))

    if password != re_password:
        session['error_message'] = '新密码输入不一致.'
        return redirect(url_for('register'))

    if len(password) < 8:
        session['error_message'] = '密码必须8位及以上.'
        return redirect(url_for('register'))

    r_session.srem('invitation_codes', invitation_code)
    r_session.srem('public_invitation_codes', invitation_code)

    user = dict(username=username, password=hash_password(password), id=str(uuid.uuid1()),
                active=True, is_admin=False, max_account_no=20,
                created_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    r_session.set('%s:%s' % ('user', username), json.dumps(user))
    r_session.set('%s:%s' % ('record', username), json.dumps(dict(diary=[])))
    r_session.sadd('users', username)

    session['info_message'] = '恭喜你,注册成功.'
    return redirect(url_for('register'))
Exemple #23
0
def __handshake(user):
    username = user.get('username')
    r_session.setex('user:%s:is_online' % username, '1', 120)
    r_session.sadd('global:online.users', username)
Exemple #24
0
def async_account_addmore(list_valid, user):
    for item in list_valid:
        account_name = item[0]
        password = item[1]
        md5_password = md5(password)
        accounts_key = 'accounts:%s' % user.get('username')

        user_key = '%s:%s' % ('user', user.get('username'))
        user_info = json.loads(r_session.get(user_key).decode('utf-8'))
        account_no = r_session.scard(accounts_key) + 1
        if user_info.get('account_limit') is not None and user_info[
                'account_limit'] < account_no:
            session['error_message'] = '账户数量已达上限,无法完成添加'
            return redirect(url_for('accounts'))
        if account_no is not None:
            if account_no >= user.get('total_account_point'):
                session['error_message'] = '账户余额不足,无法完成添加'
                return redirect(url_for('accounts'))
            elif account_no >= user.get('max_account_no'):
                user_info['max_account_no'] = account_no
                days = int(
                    user_info.get('total_account_point') /
                    user_info.get('max_account_no'))
                if days < 36500:
                    user_info['expire_date'] = (
                        datetime.now() +
                        timedelta(days=days)).strftime('%Y-%m-%d')
                else:
                    user_info['expire_date'] = (
                        datetime.now() +
                        timedelta(days=36500)).strftime('%Y-%m-%d')
                r_session.set(user_key, json.dumps(user_info))
        login_result = login(account_name, md5_password,
                             app.config.get('ENCRYPT_PWD_URL'))
        time.sleep(2)
        if login_result.get('errorCode') != 0:
            continue

        xl_session_id = login_result.get('sessionID')
        xl_nick_name = login_result.get('nickName')
        xl_user_name = login_result.get('userName')
        xl_user_id = str(login_result.get('userID'))
        xl_user_new_no = str(login_result.get('userNewNo'))
        xl_account_name = account_name
        xl_password = md5_password

        r_session.sadd(accounts_key, xl_user_id)

        account_key = 'account:%s:%s' % (user.get('username'), xl_user_id)
        xl_account_data = dict(
            session_id=xl_session_id,
            nick_name=xl_nick_name,
            username=xl_user_name,
            user_id=xl_user_id,
            user_new_no=xl_user_new_no,
            account_name=xl_account_name,
            password=xl_password,
            active=True,
            status='OK',
            createdtime=datetime.now().strftime('%Y-%m-%d %H:%M'))
        r_session.set(account_key, json.dumps(xl_account_data))
Exemple #25
0
def __handshake():
    user = session.get('user_info')
    username = user.get('username') if user.get('username') is not None else ''
    key = 'user:%s:is_online' % username
    r_session.setex(key, '1', 120)
    r_session.sadd('global:online.users', username)
Exemple #26
0
def __handshake():
    user = session.get('user_info')
    username = user.get('username') if user.get('username') is not None else ''
    key = 'user:%s:is_online' % username
    r_session.setex(key, '1', 120)
    r_session.sadd('global:online.users', username)
Exemple #27
0
def __handshake():
    user = session.get('user_info')
    username = user.get('username')
    r_session.setex('user:%s:is_online' % username, '1', 120)
    r_session.sadd('global:online.users', username)
Exemple #28
0
def __handshake():
    user = session.get("user_info")
    username = user.get("username") if user.get("username") is not None else ""
    key = "user:%s:is_online" % username
    r_session.setex(key, "1", 120)
    r_session.sadd("global:online.users", username)