def accounts_count(): count_key = 'count:accounts' b_count_info = r_session.get(count_key) if b_count_info is not None: return dict(accounts_count=json.loads(r_session.get(count_key).decode('utf-8'))) users = r_session.scard('users') accounts = 0 accountsk = 0 for name in r_session.smembers('users'): accounts_key = 'accounts:%s' % name.decode('utf-8') for acct in r_session.smembers(accounts_key): account_key = 'account:%s:%s' % ( name.decode('utf-8'), acct.decode("utf-8")) account_data_key = account_key + ':data' account_data_value = r_session.get(account_data_key) if account_data_value is None: continue account_info = json.loads(account_data_value.decode("utf-8")) for i in account_info.get('device_info'): accountsk += 1 accounts += r_session.scard(accounts_key) accounts_count = dict(users=users, accounts=accounts, accountsk=accountsk) r_session.setex(count_key, json.dumps(accounts_count), 120) return dict(accounts_count=accounts_count)
def accounts_count(): count_key = 'count:accounts' b_count_info = r_session.get(count_key) if b_count_info is not None: return dict(accounts_count=json.loads( r_session.get(count_key).decode('utf-8'))) users = r_session.scard('users') accounts = 0 accountsk = 0 for name in r_session.smembers('users'): accounts_key = 'accounts:%s' % name.decode('utf-8') for acct in r_session.smembers(accounts_key): account_key = 'account:%s:%s' % (name.decode('utf-8'), acct.decode("utf-8")) account_data_key = account_key + ':data' account_data_value = r_session.get(account_data_key) if account_data_value is None: continue account_info = json.loads(account_data_value.decode("utf-8")) for i in account_info.get('device_info'): accountsk += 1 accounts += r_session.scard(accounts_key) accounts_count = dict(users=users, accounts=accounts, accountsk=accountsk) r_session.setex(count_key, json.dumps(accounts_count), 120) return dict(accounts_count=accounts_count)
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'))
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'))
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'))
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'))
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'))
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'))
def account_del(xl_id): user = session.get('user_info') accounts_key = 'accounts:%s' % user.get('username') account_key = 'account:%s:%s' % (user.get('username'), xl_id) account_data_key = account_key+':data' r_session.srem(accounts_key, xl_id) r_session.delete(account_key) r_session.delete(account_data_key) 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) if account_no is not None: if account_no > 0: days=int(user_info.get('total_account_point')/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)) return redirect(url_for('accounts'))
def account_del(xl_id): user = session.get('user_info') accounts_key = 'accounts:%s' % user.get('username') account_key = 'account:%s:%s' % (user.get('username'), xl_id) account_data_key = account_key + ':data' r_session.srem(accounts_key, xl_id) r_session.delete(account_key) r_session.delete(account_data_key) 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) if account_no is not None: if account_no > 0: days = int(user_info.get('total_account_point') / 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)) return redirect(url_for('accounts'))
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))