def post(self): parser = CustomRequestParser() parser.add_argument('amount', type=str, required=True, nullable=False, location='json') parsed_args = parser.parse_args() api = cryptopay_api() url = '{}/member/create_charge_order'.format( current_app.config['CRYPTOPAY_BASE_URL']) currency_overt = CurrencyConvertApi() current_covert = currency_overt.get() for item in current_covert: if item['symbol'] == 'BTC': BTC = float(parsed_args['amount']) / float(item['price_usd']) elif item['symbol'] == 'ETH': ETH = float(parsed_args['amount']) / float(item['price_usd']) payments = 'BTC={};ETH={}'.format(BTC, ETH) data = { 'number': str(uuid.uuid4()), 'amount': parsed_args['amount'], 'payments': payments, 'extra': '' } try: result = api.post(url, data) except CryptoPayApiError as e: abort(e.http_status_code, code=e.code, message=e.message) result['currency_address_qr_code'] = current_app.config[ 'CRYPTOPAY_BASE_URL'] + '/currency_address_qr_code' return result
def get(self): parser = CustomRequestParser() parser.add_argument('uid', type=str, location='args') parser.add_argument('create_begin_timestamp', type=int, location='args') parser.add_argument('create_end_timestamp', type=int, location='args') parsed_args = parser.parse_args() q = AssetsBalanceRecord.query.filter( AssetsBalanceRecord.delta_amount < 0) if parsed_args['uid']: user = User.get_user(uid=parsed_args['uid']) q = q.filter_by(user_id=user.id) if parsed_args['create_begin_timestamp'] is not None: create_begin_datetime = timestamp_to_datetime( parsed_args['create_begin_timestamp']) q = q.filter( AssetsBalanceRecord.created_at >= create_begin_datetime) if parsed_args['create_end_timestamp'] is not None: create_end_datetime = timestamp_to_datetime( parsed_args['create_end_timestamp']) q = q.filter(AssetsBalanceRecord.created_at < create_end_datetime) expense = q.with_entities( db.func.sum(db.func.abs(AssetsBalanceRecord.delta_amount))) return {'expense': expense.scalar()}
def get(self): parser = CustomRequestParser() parser.add_argument('page', type=int, default=1, location='args') parser.add_argument('per_page', type=int, default=5, location='args') parser.add_argument('currency', type=str, location='args') parsed_args = parser.parse_args() wallet = Wallet.query.filter( Wallet.user_id == g.current_user.id, Wallet.currency_id != 'USDT', Wallet.currency_id != 'DASH', Wallet.currency_id != 'BTG', Wallet.currency_id != 'BCH', ) if parsed_args['currency']: wallet = wallet.filter_by(currency_id=parsed_args['currency']) wallet_list = pagination_query(parsed_args['per_page'], parsed_args['page'], wallet) objects = [] sort_currency = ['BTC', 'ETH', 'LTC'] for currency in sort_currency: for item in wallet_list['objects']: if item.currency_id == currency: objects.append(item) break wallet_list['objects'] = objects Wallet.query_wallet(wallet_list['objects']) return wallet_list
def get(self): parser = CustomRequestParser() parser.add_argument('uid', type=str, location='args') parser.add_argument('create_begin_timestamp', type=int, location='args') parser.add_argument('create_end_timestamp', type=int, location='args') parsed_args = parser.parse_args() q = AssetsBalanceRecord.query.filter( AssetsBalanceRecord.delta_amount > 0) q = q.filter(AssetsBalanceRecord.user_id != User.VIRTUAL_ID) if parsed_args['uid']: user = User.get_user(uid=parsed_args['uid']) if user is None: abort(400, code=1001, message={'user': '******'}) q = q.filter_by(user_id=user.id) if parsed_args['create_begin_timestamp'] is not None: create_begin_datetime = timestamp_to_datetime( parsed_args['create_begin_timestamp']) q = q.filter( AssetsBalanceRecord.created_at >= create_begin_datetime) if parsed_args['create_end_timestamp'] is not None: create_end_datetime = timestamp_to_datetime( parsed_args['create_end_timestamp']) q = q.filter(AssetsBalanceRecord.created_at < create_end_datetime) income = q.with_entities(db.func.sum(AssetsBalanceRecord.delta_amount)) return {'income': income.scalar()}
def get(self): parser = CustomRequestParser() parser.add_argument('currency_list', type=str, location='args') parsed_args = parser.parse_args() if parsed_args['currency_list']: currency_list = parsed_args['currency_list'].split(',') q = CryptoCurrency.query.filter( CryptoCurrency.currency_code.in_(currency_list)) else: q = CryptoCurrency.query q = q.order_by(CryptoCurrency.sequence.asc()) return q.all()
def post(self): parser = CustomRequestParser() parser.add_argument('id', type=str, required=True, location='json') parser.add_argument('assets_type', type=int, required=True, choices=(g_assets_type.TOTAL, g_assets_type.COMMUNITY, g_assets_type.TRANSACTION), location='json') parser.add_argument('amount', type=decimal.Decimal, required=True, location='json') parsed_args = parser.parse_args() assets = Assets.query.get(parsed_args['id']) if assets is None: abort(400, code=1001, message={'assets': 'assets does not exist'}) details = {'message': '管理员:{}'.format(g.current_user.uid)} if parsed_args['assets_type'] == g_assets_type.TOTAL: if not assets.update_total_balance(parsed_args['amount'], g_assets_record_type.RECHARGE, details): abort(400, code=1008, message={ 'balance': 'current balance < {}'.format(parsed_args['amount']) }) elif parsed_args['assets_type'] == g_assets_type.COMMUNITY: if not assets.update_community_balance( parsed_args['amount'], g_assets_record_type.RECHARGE, details): abort(400, code=1008, message={ 'balance': 'current balance < {}'.format(parsed_args['amount']) }) else: if not assets.update_transaction_balance( parsed_args['amount'], g_assets_record_type.RECHARGE, details): abort(400, code=1008, message={ 'balance': 'current balance < {}'.format(parsed_args['amount']) }) db.session.commit() return {}
def post(self): parser = CustomRequestParser() parser.add_argument('mobile', type=str, required=True, nullable=False, location='json') # parser.add_argument('pin_code', type=str, required=True, nullable=False, location='json') parser.add_argument('password', type=str, required=True, nullable=False, location='json') # parser.add_argument('uuid', type=str, required=True, nullable=False, location='json') # parser.add_argument('captcha_pin_code', type=str, required=True, nullable=False, location='json') parsed_args = parser.parse_args() # CaptchaPinCode.flask_check(parsed_args['uuid'], parsed_args['captcha_pin_code']) # user = User.reset_password(parsed_args['mobile'], parsed_args['pin_code'], parsed_args['password']) user = User.reset_password(parsed_args['mobile'], parsed_args['password']) if not user: abort(400, code=1001, message={'mobile': 'user does not exist'}) db.session.commit() cookie = dump_cookie(key='token', value=user.token, max_age=datetime.timedelta(days=365)) return user, {'Set-Cookie': cookie}
def post(self): parser = CustomRequestParser() parser.add_argument('mobile', type=str, required=True, nullable=False, location='json') parser.add_argument('password', type=str, required=True, nullable=False, location='json') parsed_args = parser.parse_args() user = User.query.filter(User.mobile == parsed_args['mobile']).first() if user is None: user = User(id=str(uuid.uuid4()), mobile=parsed_args['mobile']) user.set_password(parsed_args['password']) user.generate_auth_token() db.session.add(user) db.session.commit() Wallet.generate_wallet(user.id, None) else: if not user.verify_password(parsed_args['password']): abort(400, code=1002, message={'password': '******'}) user.generate_auth_token() user.save() cookie = dump_cookie(key='token', value=user.token, max_age=datetime.timedelta(days=1000)) return user, {'Set-Cookie': cookie}
def post(self): parser = CustomRequestParser() parser.add_argument('mobile', type=str, required=True, nullable=False, location='json') # parser.add_argument('pin_code', type=str, required=True, nullable=False, location='json') parser.add_argument('password', type=str, required=True, nullable=False, location='json') # parser.add_argument('uuid', type=str, required=True, nullable=False, location='json') # parser.add_argument('captcha_pin_code', type=str, required=True, nullable=False, location='json') parsed_args = parser.parse_args() # CaptchaPinCode.flask_check(parsed_args['uuid'], parsed_args['captcha_pin_code']) # user = User.reset_security_password(parsed_args['mobile'], parsed_args['pin_code'], parsed_args['password']) user = User.reset_security_password(parsed_args['mobile'], parsed_args['password']) if not user: abort(400, code=1001, message={'mobile': 'user does not exist'}) db.session.commit() return user
def get(self): parser = CustomRequestParser() parser.add_argument('page', type=int, default=1, location='args') parser.add_argument('per_page', type=int, default=5, location='args') parsed_args = parser.parse_args() q = LoginInfo.query.filter_by(user_id=g.current_user.id) q = q.order_by(LoginInfo.created_at.desc()) return pagination_query(parsed_args['per_page'], parsed_args['page'], q)
def post(self): parser = CustomRequestParser() parser.add_argument('mobile', type=str, required=True, nullable=False, location='json') # 收款人的用户手机号 parser.add_argument('amount', type=int, required=True, nullable=False, location='json') parser.add_argument('security_password', type=str, required=True, nullable=False, location='json') parsed_args = parser.parse_args() user = User.query.filter(User.mobile == parsed_args['mobile']).first() if user is None: abort(400, code=1001, message={'mobile': 'user does not exist'}) if parsed_args['amount'] <= 0: abort(400, code=1003, message={'amount': 'amount <= 0'}) if not g.current_user.security_password: abort(400, code=1012, message={'security_password': '******'}) if not g.current_user.verify_security_password(parsed_args['security_password']): abort(400, code=1002, message={'security_password': '******'}) if not g.current_user.is_community_node: abort(400, code=1001, message={'current_user': '******'}) if user.is_community_node: abort(400, code=1001, message={'user': '******'}) option = Setting.get_json('general_option') community_transaction_fee_rate = option['community_transaction_fee_rate'] # exchange_amount_min = option['exchange_amount_min'] # exchange_amount_max = option['exchange_amount_max'] # # if parsed_args['amount'] < exchange_amount_min or parsed_args['amount'] > exchange_amount_max: # abort(400, code=1006, # message={'amount': 'amount < {} or amount > {}'.format(exchange_amount_min, exchange_amount_max)}) fee = decimal.Decimal(parsed_args['amount']) * decimal.Decimal(community_transaction_fee_rate) amount = decimal.Decimal(parsed_args['amount']) + decimal.Decimal(fee) assets = Assets.get_assets(g.current_user.id) detail = { 'message': '{}转给{}, 金额:{}, 手续费:{}'.format( g.current_user.mobile, user.mobile, parsed_args['amount'], fee) } if not assets.update_transaction_balance(-amount, g_assets_record_type.TRANSACTION, detail): abort(400, code=1008, message={'balance': 'current balance < {}'.format(amount)}) assets = Assets.get_assets(user.id) assets.update_total_balance(parsed_args['amount'], g_assets_record_type.TRANSACTION, detail) db.session.commit() return assets
def post(self): parser = CustomRequestParser() parser.add_argument('amount', type=int, required=True, nullable=False, location='json') parser.add_argument('security_password', type=str, required=True, nullable=False, location='json') parsed_args = parser.parse_args() if parsed_args['amount'] <= 0: abort(400, code=1003, message={'amount': 'amount <= 0'}) if not g.current_user.security_password: abort(400, code=1012, message={'security_password': '******'}) if not g.current_user.verify_security_password(parsed_args['security_password']): abort(400, code=1002, message={'security_password': '******'}) option = Setting.get_json('general_option') exchange_amount_min = option['exchange_amount_min'] exchange_amount_max = option['exchange_amount_max'] if parsed_args['amount'] % exchange_amount_min > 0: abort(400, code=1001, message={'amount': 'the amount must be a multiple of {}'.format(exchange_amount_min)}) # 用于计算今天兑换的数量 str_time = datetime.datetime.now().strftime('%Y-%m-%d') sum_amount = db.session.query(db.func.sum(AssetsBalanceRecord.delta_amount)).filter( db.func.date_format(AssetsBalanceRecord.created_at, '%Y-%m-%d') == str_time, AssetsBalanceRecord.user_id == g.current_user.id, AssetsBalanceRecord.record_type == g_assets_record_type.EXCHANGE, AssetsBalanceRecord.assets_type == g_assets_type.COMMUNITY).first()[0] sum_amount = sum_amount if sum_amount is not None else 0 if sum_amount + parsed_args['amount'] > exchange_amount_max: abort(400, code=1006, message={ 'amount': 'already amount {} + current amount {} > {}'.format(sum_amount, parsed_args['amount'], exchange_amount_max)}) assets = Assets.get_assets(g.current_user.id) detail = {'message': '兑换'} if not assets.update_transaction_balance(-parsed_args['amount'], g_assets_record_type.EXCHANGE, detail): abort(400, code=1008, message={'balance': 'current balance < {}'.format(parsed_args['amount'])}) assets.update_community_balance(parsed_args['amount'], g_assets_record_type.EXCHANGE, detail) db.session.commit() return assets
def post(self): parser = CustomRequestParser() parser.add_argument('currency', type=str, required=True, nullable=False, location='json') parser.add_argument('amount', type=decimal.Decimal, required=True, nullable=False, location='json') parser.add_argument('fee', type=decimal.Decimal, nullable=False, location='json') parser.add_argument('message', type=unicode, location='json') parsed_args = parser.parse_args() wallet = Wallet.query.filter_by( user_id=g.current_user.id, currency_id=parsed_args['currency']).first() if wallet is None: abort(400, code=1001, message={'currency': 'currency does not exist'}) if parsed_args["currency"] == "BTC": if parsed_args['amount'] <= decimal.Decimal("0.000001"): abort(400, code=1003, message={'amount': 'amount <= 0.00001'}) elif parsed_args["currency"] == "ETH": if parsed_args['amount'] <= 0.00001: abort(400, code=1003, message={'amount': 'amount <= 0.0001'}) order = TransferOrder(user_id=g.current_user.id, currency_id=parsed_args['currency'], amount=parsed_args['amount'], fee=parsed_args['fee'], message=parsed_args['message']) db.session.add(order) db.session.flush() TransferOrder.create_transaction_order(order.number, wallet.address, order.amount, order.fee, type=order.type) TransferOrder.pay_order(order.number) order.status = 2 db.session.commit() return order
def post(self): parser = CustomRequestParser() parser.add_argument( 'type', type=int, required=True, choices=(g_payment_type.BANK, g_payment_type.WECHAT, g_payment_type.ALIPAY, g_payment_type.USDT), location='json') parser.add_argument('name', type=str, location='json') parser.add_argument('bank', type=str, location='json') parser.add_argument('card_number', type=str, location='json') parser.add_argument('wechat', type=str, location='json') parser.add_argument('wechat_image', type=str, default='', location='json') parser.add_argument('alipay', type=str, location='json') parser.add_argument('alipay_image', type=str, default='', location='json') parser.add_argument('address', type=str, location='json') parser.add_argument('remark', type=str, default='', location='json') parser.add_argument('security_password', type=str, required=True, nullable=False, location='json') parsed_args = parser.parse_args() if not g.current_user.security_password: abort(400, code=1012, message={'security_password': '******'}) if not g.current_user.verify_security_password( parsed_args['security_password']): abort(400, code=1002, message={ 'security_password': '******' }) payment = Payment.get_payment(g.current_user.id, parsed_args['type']) if payment is not None: abort(400, code=1006, message={'type': 'payment type does exist'}) if parsed_args['type'] == g_payment_type.BANK: if parsed_args['name'] is None or parsed_args[ 'bank'] is None or parsed_args['card_number'] is None: abort(400, code=1001, message={ 'payment': 'name|bank|card_number does not exist' }) payment = Payment(user_id=g.current_user.id, type=parsed_args['type'], name=parsed_args['name'], bank=parsed_args['bank'], card_number=parsed_args['card_number']) elif parsed_args['type'] == g_payment_type.WECHAT: if parsed_args['name'] is None or parsed_args['wechat'] is None: abort(400, code=1001, message={'payment': 'name|wechat does not exist'}) payment = Payment(user_id=g.current_user.id, type=parsed_args['type'], name=parsed_args['name'], wechat=parsed_args['wechat'], wechat_image=parsed_args['wechat_image']) elif parsed_args['type'] == g_payment_type.ALIPAY: if parsed_args['name'] is None or parsed_args['alipay'] is None: abort(400, code=1001, message={'payment': 'name|alipay does not exist'}) payment = Payment(user_id=g.current_user.id, type=parsed_args['type'], name=parsed_args['name'], alipay=parsed_args['alipay'], alipay_image=parsed_args['alipay_image']) else: if parsed_args['address'] is None: abort(400, code=1001, message={'payment': 'address does not exist'}) payment = Payment(user_id=g.current_user.id, type=parsed_args['type'], address=parsed_args['address'], remark=parsed_args['remark']) db.session.add(payment) db.session.commit() return payment
def get(self): parser = CustomRequestParser() parser.add_argument('page', type=int, default=1, location='args') parser.add_argument('per_page', type=int, default=5, location='args') parser.add_argument( 'type', type=int, choices=(g_payment_type.BANK, g_payment_type.WECHAT, g_payment_type.ALIPAY, g_payment_type.USDT), location='args') parser.add_argument('invalid', type=int, default=0, location='args') parsed_args = parser.parse_args() q = Payment.query.filter_by(user_id=g.current_user.id) if parsed_args['type'] is not None: q = q.filter(Payment.type == parsed_args['type']) if parsed_args['invalid'] is not None: q = q.filter(Payment.invalid == parsed_args['invalid']) q = q.order_by(Payment.created_at.desc()) return pagination_query(parsed_args['per_page'], parsed_args['page'], q)
def get(self): parser = CustomRequestParser() parser.add_argument('page', type=int, default=1, location='args') parser.add_argument('per_page', type=int, default=5, location='args') parser.add_argument('create_begin_timestamp', type=int, location='args') parser.add_argument('create_end_timestamp', type=int, location='args') parsed_args = parser.parse_args() q = CurrencyPriceRecord.query if parsed_args['create_begin_timestamp'] is not None: create_begin_datetime = timestamp_to_datetime( parsed_args['create_begin_timestamp']) q = q.filter( CurrencyPriceRecord.created_at >= create_begin_datetime) if parsed_args['create_end_timestamp'] is not None: create_end_datetime = timestamp_to_datetime( parsed_args['create_end_timestamp']) q = q.filter(CurrencyPriceRecord.created_at < create_end_datetime) q = q.order_by(CurrencyPriceRecord.id.asc()) return pagination_query(parsed_args['per_page'], parsed_args['page'], q)
def get(self): parser = CustomRequestParser() parser.add_argument('page', type=int, default=1, location='args') parser.add_argument('per_page', type=int, default=5, location='args') parser.add_argument('assets_type', type=int, location='args') parser.add_argument('record_type', type=int, location='args') parser.add_argument('create_begin_timestamp', type=int, location='args') parser.add_argument('create_end_timestamp', type=int, location='args') # delta_amount_flag用来查找兑换中大于0的记录 如果为1则查找 parser.add_argument('delta_amount_flag', type=int, location='args') parsed_args = parser.parse_args() q = AssetsBalanceRecord.query q = q.filter_by(user_id=g.current_user.id) if parsed_args['assets_type']: q = q.filter(AssetsBalanceRecord.assets_type.op('&')(parsed_args['assets_type'])) if parsed_args['record_type']: q = q.filter(AssetsBalanceRecord.record_type.op('&')(parsed_args['record_type'])) if parsed_args['create_begin_timestamp'] is not None: create_begin_datetime = timestamp_to_datetime(parsed_args['create_begin_timestamp']) q = q.filter(AssetsBalanceRecord.created_at >= create_begin_datetime) if parsed_args['create_end_timestamp'] is not None: create_end_datetime = timestamp_to_datetime(parsed_args['create_end_timestamp']) q = q.filter(AssetsBalanceRecord.created_at < create_end_datetime) if parsed_args['delta_amount_flag'] is not None: if parsed_args['delta_amount_flag']: q = q.filter(AssetsBalanceRecord.delta_amount > 0) q = q.order_by(AssetsBalanceRecord.id.desc()) return pagination_query(parsed_args['per_page'], parsed_args['page'], q)
def put(self): parser = CustomRequestParser() parser.add_argument('old_password', type=str, location='json') parser.add_argument('new_password', type=str, nullable=False, location='json') parser.add_argument('old_security_password', type=str, location='json') parser.add_argument('new_security_password', type=str, nullable=False, location='json') parser.add_argument('avatar', type=str, location='json') parser.add_argument('order_mobile', type=str, location='json') parser.add_argument('name', type=str, nullable=False, location='json') # 姓名 parser.add_argument('nickname', type=str, nullable=False, location='json') # 姓名 parser.add_argument('gender', type=int, default=0, choices=(0, 1, 2), location='json') # 性别 parser.add_argument('wechat', type=str, nullable=False, location='json') # 微信 parsed_args = parser.parse_args() if parsed_args['old_password'] and parsed_args['new_password']: if not g.current_user.verify_password(parsed_args['old_password']): abort(400, code=1002, message={'old_password': '******'}) g.current_user.set_password(parsed_args['new_password']) if parsed_args['new_security_password']: if g.current_user.has_security_password: if not g.current_user.verify_security_password( parsed_args['old_security_password']): abort(400, code=1002, message={ 'old_security_password': '******' }) g.current_user.set_security_password( parsed_args['new_security_password']) if parsed_args['avatar']: g.current_user.avatar = parsed_args['avatar'] if parsed_args['name']: g.current_user.name = parsed_args['name'] if parsed_args['nickname']: g.current_user.nickname = parsed_args['nickname'] if parsed_args['gender'] is not None: g.current_user.gender = parsed_args['gender'] if parsed_args['wechat']: g.current_user.wechat = parsed_args['wechat'] if parsed_args['order_mobile']: g.current_user.order_mobile = parsed_args['order_mobile'] if g.current_user.name is not None and g.current_user.gender != 0 and g.current_user.wechat is not None and \ g.current_user.state == g_user_state_type.UNCOMPLETED_DATA: g.current_user.set_uid() g.current_user.update_state(g_user_state_type.COMPLETED_DATA) db.session.commit() return g.current_user
def post(self): parser = CustomRequestParser() parser.add_argument('mobile', type=str, required=True, nullable=False, location='json') parser.add_argument('uuid', type=str, required=True, nullable=False, location='json') parser.add_argument('password', type=str, required=True, nullable=False, location='json') # parser.add_argument('captcha_pin_code', type=str, required=True, nullable=False, location='json') parser.add_argument('client_ip', type=str, default=request.access_route[0], location='json') parser.add_argument('platform', type=str, nullable=False, default='android', location='json') parsed_args = parser.parse_args() user = User.query.filter(User.mobile == parsed_args['mobile']).first() if user is None: abort(400, code=1001, message={'unique_id': 'user does not exist'}) # CaptchaPinCode.flask_check(parsed_args['uuid'], parsed_args['captcha_pin_code']) if user.verify_password(parsed_args['password']): user.generate_auth_token() cookie = dump_cookie(key='token', value=user.token, max_age=datetime.timedelta(days=365)) login_info = LoginInfo(user_id=user.id, client_ip=parsed_args['client_ip']) # 设置登录平台 ,android or ios user.platform = parsed_args['platform'] db.session.add(login_info) db.session.commit() return user, {'Set-Cookie': cookie} else: abort(400, code=1002, message={'password': '******'})
def post(self): parser = CustomRequestParser() parser.add_argument('country_code', type=str, default='86', location='json') parser.add_argument('mobile', type=str, required=True, nullable=False, location='json') parser.add_argument('password', type=str, required=True, nullable=False, location='json') parser.add_argument('security_password', type=str, required=True, nullable=False, location='json') # parser.add_argument('pin_code', type=str, required=True, nullable=False, location='json') parser.add_argument('source', type=str, default='', location='json') parser.add_argument('sponsor_uid', type=str, required=True, nullable=False, location='json') # parser.add_argument('uuid', type=str, required=True, nullable=False, location='json') # parser.add_argument('captcha_pin_code', type=str, required=True, nullable=False, location='json') parsed_args = parser.parse_args() # CaptchaPinCode.flask_check(parsed_args['uuid'], parsed_args['captcha_pin_code']) sponsor = User.query.filter( User.uid == parsed_args['sponsor_uid']).first() if not sponsor: abort(400, code=1001, message={'sponsor': 'sponsor does not exist'}) # 测试环境,不验证手机验证码 # product_name = str(current_app.config['PRODUCT_NAME']) # country_code = parsed_args['country_code'] # if parsed_args['country_code']: # if "+" in parsed_args['country_code']: # country_code = parsed_args['country_code'][1:] if member_user_mobile_exists(parsed_args['mobile']): abort(400, code=1011, message={'mobile': 'mobile already exists'}) # SmsPinCode.flask_check(parsed_args['mobile'], parsed_args['pin_code']) user = User( id=str(uuid.uuid4()), # country_code=country_code, mobile=parsed_args['mobile'], source=parsed_args['source'], sponsor_id=sponsor.id) # user.set_uid() # 项目要求完善资料后生成 user.set_password(parsed_args['password']) user.set_security_password(parsed_args['security_password']) user.generate_auth_token() db.session.add(user) db.session.flush() user.activate() db.session.commit() cookie = dump_cookie(key='token', value=user.token, max_age=datetime.timedelta(days=365)) return user, {'Set-Cookie': cookie}
def post(self): parser = CustomRequestParser() parser.add_argument('mobile', type=str, required=True, nullable=False, location='json') # parser.add_argument('pin_code', type=str, required=True, nullable=False, location='json') parser.add_argument('new_mobile', type=str, required=True, nullable=False, location='json') parser.add_argument('new_pin_code', type=str, required=True, nullable=False, location='json') parser.add_argument('country_code', type=str, location='json') parsed_args = parser.parse_args() g.current_user.rebind_id( parsed_args['mobile'], # parsed_args['pin_code'], parsed_args['new_mobile'], # parsed_args['new_pin_code'], parsed_args['country_code']) db.session.commit() return {}
def get(self): parser = CustomRequestParser() parser.add_argument('page', type=int, default=1, location='args') parser.add_argument('per_page', type=int, default=5, location='args') parser.add_argument('currency', type=str, location='args') parser.add_argument('status', type=int, location='args') parser.add_argument('type', type=int, location='args') parsed_args = parser.parse_args() q = TransferOrder.query.filter( db.or_(TransferOrder.user_id == g.current_user.id, TransferOrder.to_user_id == g.current_user.id)) if parsed_args['currency']: q = q.filter(TransferOrder.currency_id == parsed_args['currency']) if parsed_args['status'] is not None: q = q.filter( TransferOrder.status.op('&')(parsed_args['status']) != 0) if parsed_args['type']: q = q.filter(TransferOrder.type == parsed_args['type']) q = q.order_by(TransferOrder.created_at.desc()) return pagination_query(parsed_args['per_page'], parsed_args['page'], q)
def get(self): parser = CustomRequestParser() parser.add_argument('page', type=int, default=1, location='args') parser.add_argument('per_page', type=int, default=5, location='args') parser.add_argument('uid', type=str, location='args') parser.add_argument('mobile', type=str, location='args') parsed_args = parser.parse_args() q = Assets.query if parsed_args['uid']: q = q.filter(Assets.user.has(User.uid.contains( parsed_args['uid']))) if parsed_args['mobile']: q = q.filter( Assets.user.has(User.mobile.contains(parsed_args['mobile']))) q = q.order_by(Assets.id.desc()) return pagination_query(parsed_args['per_page'], parsed_args['page'], q)