def post(self):
        user_type = _USER_TYPE_INVEST

        if check_use_source(_USE_SOURCE_TYPE_1):
            argument_dict, aes_share_key, aes_nonce = self.get_argument_dict(
                must_keys=['user_id', 'email', 'vcode'],
                api_type=user_type,
                request_type=_REQUEST_TYPE_LOGIN,
                check_form_token=True)

            user_id = argument_dict['user_id']
            email = argument_dict['email']
            vcode = argument_dict['vcode']

            register_by = _REGISTER_SET_EMAIL

            vcode_service = VcodeService(aes_share_key=aes_share_key,
                                         aes_nonce=aes_nonce)
            vcode_service.check_vcode(
                vcode,
                _VCODE_SET_EMAIL,
                user_id,
                user_type=user_type,
                register_by=register_by,
            )

            r = UserBaseService(aes_share_key=aes_share_key, aes_nonce=aes_nonce). \
                set_email(user_id, email, user_type=user_type)
            return r, aes_share_key, aes_nonce
        else:
            self.return_error(10004)
Ejemplo n.º 2
0
    def post(self):
        """
        发送验证码
          :param user_mobile: 手机号码
        :return:
        """
        user_type = _USER_TYPE_BORROW
        argument_dict, aes_share_key, aes_nonce = self.get_argument_dict(
            must_keys=['user_mobile', 'pvcode'],
            check_token=False,
            invariable_key=False,
            api_type=user_type,
            request_type=_REQUEST_TYPE_REGISTER)

        user_mobile = str(argument_dict['user_mobile'])
        pvcode = str(argument_dict['pvcode'])
        send_type = _VCODE_REGISTER
        service = VcodeService(aes_share_key=aes_share_key,
                               aes_nonce=aes_nonce)

        # 校验图形验证码
        service.check_vcode_picture(pvcode)

        # 校验是否已经注册
        result = service.send_vcode(send_type,
                                    user_mobile,
                                    user_type=user_type)
        return result, aes_share_key, aes_nonce
    def post(self):
        user_type = _USER_TYPE_INVEST

        if check_use_source(_USE_SOURCE_TYPE_1):
            argument_dict, aes_share_key, aes_nonce = self.get_argument_dict(
                must_keys=[
                    'user_id', 'pay_password', 'login_password', 'vcode',
                    'register_by'
                ],
                api_type=user_type,
                request_type=_REQUEST_TYPE_LOGIN,
                check_form_token=True)

            user_id = argument_dict['user_id']
            pay_password = argument_dict['pay_password']
            login_password = argument_dict['login_password']
            vcode = argument_dict['vcode']
            register_by = argument_dict['register_by']

            # 1.0 检查验证码有效性
            vcode_service = VcodeService(aes_share_key=aes_share_key,
                                         aes_nonce=aes_nonce)
            vcode_service.check_vcode(vcode,
                                      _VCODE_SET_PAY_PD,
                                      user_id,
                                      user_type=user_type,
                                      register_by=register_by)

            r = UserBaseService(aes_share_key=aes_share_key, aes_nonce=aes_nonce). \
                set_pay_password(user_id, login_password, pay_password, user_type=user_type)
            return r, aes_share_key, aes_nonce
        else:
            self.return_error(10004)
Ejemplo n.º 4
0
    def gather_to_gather(self, coin_id, from_address, amount, to_address, verification_code):
        """
        归集转归集
        :param coin_id: 币种
        :param from_address: 待归集地址
        :param amount: 归集数量
        :param to_address: 收款地址
        :param verification_code: 验证码
        :return:
        """
        conf = get_config()
        env = conf["env"]
        if env == "pd":
            vcode_service = VcodeService()
            result = vcode_service.check_sms_email_vcode('common', verification_code)
        with MysqlTools().session_scope() as session:
            record_id = generate_order_no()
            foreign_gather_record = ForeignGatherRecordModel(
                record_id=record_id,
                public_address=to_address,
                purpose_amount=amount,
                gather_status=_FOUR_S
            )
            session.add(foreign_gather_record)
            gather_record_id = foreign_gather_record.record_id
            order_no = generate_order_no()
            withdraw = ForeignWithdrawOrderRecordModel(
                order_no=order_no,
                relate_flow_no=gather_record_id,
                coin_id=coin_id,
                from_address=from_address,
                withdraw_address=to_address,
                withdraw_amount=amount,
                withdraw_type=_THREE_S,
                withdraw_status=_ZERO_S,
                audit_status=_ONE_S,
                source_status=_ZERO_S,
                transfer_at=get_utc_now()
            )
            session.add(withdraw)
            session.commit()
            withdraw_order_no = withdraw.order_no
            withdraw = session.query(ForeignWithdrawOrderRecordModel).filter(
                ForeignWithdrawOrderRecordModel.order_no == order_no).first()
            wfs = WalletForeignService()
            send_result = None
            if coin_id == _ZERO_S:  # 比特币
                send_result = wfs.btc_send_tx(withdraw)
            elif coin_id == _SIXTY_S:  # 以太坊
                send_result = wfs.eth_send_tx(withdraw)

            if send_result is True:
                gather_record_model = session.query(ForeignGatherRecordModel).filter(ForeignGatherRecordModel.record_id == gather_record_id).first()
                gather_record_model.gather_status = _ONE_S
                withdraw_reocrd_model = session.query(ForeignWithdrawOrderRecordModel).filter(ForeignWithdrawOrderRecordModel.order_no == withdraw_order_no).first()
                withdraw_reocrd_model.withdraw_status = _ONE_S
                session.commit()
            return
Ejemplo n.º 5
0
    def post(self):
        """
        发送验证码
          :param user_mobile: 手机号码
        :return:
        """
        user_type = _USER_TYPE_INVEST
        if check_use_source(_USE_SOURCE_TYPE_1):
            argument_dict, aes_share_key, aes_nonce = self.get_argument_dict(
                must_keys=[
                    'user_mobile', 'pvcode', 'register_by',
                    'mobile_country_code'
                ],
                check_token=False,
                invariable_key=False,
                api_type=user_type,
                request_type=_REQUEST_TYPE_REGISTER)

            user_mobile = str(argument_dict['user_mobile'])
            pvcode = str(argument_dict['pvcode'])
            register_by = argument_dict['register_by']
            mobile_country_code = argument_dict['mobile_country_code']
            send_type = _VCODE_REGISTER
            service = VcodeService(aes_share_key=aes_share_key,
                                   aes_nonce=aes_nonce)

            # 校验图形验证码
            service.check_vcode_picture(pvcode)

            # 校验是否已经注册
            result = service.send_vcode_by_register_type(
                send_type,
                user_mobile,
                user_type=user_type,
                register_by=register_by,
                mobile_country_code=mobile_country_code)
        else:
            argument_dict, aes_share_key, aes_nonce = self.get_argument_dict(
                must_keys=['user_mobile', 'pvcode'],
                check_token=False,
                invariable_key=False,
                api_type=user_type,
                request_type=_REQUEST_TYPE_REGISTER)

            user_mobile = str(argument_dict['user_mobile'])
            pvcode = str(argument_dict['pvcode'])
            send_type = _VCODE_REGISTER
            service = VcodeService(aes_share_key=aes_share_key,
                                   aes_nonce=aes_nonce)

            # 校验图形验证码
            service.check_vcode_picture(pvcode)

            # 校验是否已经注册
            result = service.send_vcode(send_type,
                                        user_mobile,
                                        user_type=user_type)
        return result, aes_share_key, aes_nonce
Ejemplo n.º 6
0
    def post(self):
        argument_dict = self.get_argument_dict(check_token=False)

        user_mobile = argument_dict['user_mobile']
        vcode = argument_dict['vcode']
        type = argument_dict['type']

        vcode_service = VcodeService()
        result = vcode_service.check_vcode(user_mobile, int(type), vcode)
        return {"status": result}
Ejemplo n.º 7
0
 def post(self):
     """
     发送验证码
     :return:
     """
     service = VcodeService()
     result, vcode_str = service.make_vcode_picture()
     resp = Response(result)
     service.set_vcode_picture(vcode_str, user_type=_USER_TYPE_BORROW)
     return resp
Ejemplo n.º 8
0
 def post(self):
     """
     发送验证码
     :return:
     """
     service = VcodeService()
     result, vcode_str = service.make_vcode_picture()
     resp = Response(result)
     service.set_vcode_picture(vcode_str,
                               user_type=_USER_TYPE_INVEST,
                               vcode_type=_VCODE_SET_PAY_PD)
     return resp
Ejemplo n.º 9
0
 def post(self):
     """
     发送验证码
     :return:
     """
     service = VcodeService()
     result, vcode_str = service.make_vcode_picture()
     resp = Response(result)
     service.set_vcode_picture(vcode_str,
                               user_type=_USER_TYPE_INVEST,
                               vcode_type=_REQUEST_TYPE_LOGINING)
     return resp
Ejemplo n.º 10
0
 def get(self):
     """
     获取图片验证码
     :return:
     """
     arg = self.get_argument_dict(check_token=False)
     print(arg)
     path, code = VcodeService().get_image_code_path()
     try:
         response = make_response(send_file(path))
         response.headers[
             "Content-Disposition"] = "attachment; filename=code.jpg;"
         return response
     finally:
         VcodeService().del_image_code_file(path)
         print(path)
Ejemplo n.º 11
0
 def post(self):
     """
     发送验证码
     :return:
     """
     # 仅仅是为了保证不是重复请求
     argument_dict, aes_share_key, aes_nonce = self.get_argument_dict(
         encrypt=False,
         check_token=False,
         invariable_key=False,
         api_type=_USER_TYPE_BORROW,
         request_type=_REQUEST_TYPE_REGISTER)
     service = VcodeService(aes_share_key=aes_share_key,
                            aes_nonce=aes_nonce)
     result = service.make_register_signature()
     return result
Ejemplo n.º 12
0
    def post(self):
        """
        发送验证码
          :param user_mobile: 手机号码
        :return:
        """
        user_type = _USER_TYPE_INVEST
        if check_use_source(_USE_SOURCE_TYPE_1):
            argument_dict, aes_share_key, aes_nonce = self.get_argument_dict(
                must_keys=[
                    'user_id', 'mobile', 'pvcode', 'mobile_country_code'
                ],
                api_type=user_type,
                request_type=_REQUEST_TYPE_LOGIN)

            user_id = str(argument_dict['user_id'])
            user_mobile = argument_dict['mobile']
            mobile_country_code = argument_dict['mobile_country_code']
            pvcode = argument_dict['pvcode']

            register_by = _REGISTER_SET_MOBILE

            send_type = _VCODE_SET_MOBILE
            vcode_service = VcodeService(aes_share_key=aes_share_key,
                                         aes_nonce=aes_nonce)

            # 校验图形验证码
            vcode_service.check_vcode_picture(pvcode,
                                              user_type=_USER_TYPE_INVEST,
                                              vcode_type=_VCODE_SET_MOBILE)

            # 校验是否已经注册
            result = vcode_service.send_vcode_by_register_type(
                send_type,
                user_mobile,
                user_type=user_type,
                register_by=register_by,
                mobile_country_code=mobile_country_code,
                check_user_id=user_id,
            )

            return result, aes_share_key, aes_nonce
        else:
            self.return_error(10004)
Ejemplo n.º 13
0
    def post(self):
        """
        发送验证码
          :param user_mobile: 手机号码
        :return:
        """
        user_type = _USER_TYPE_INVEST
        if check_use_source(_USE_SOURCE_TYPE_1):
            argument_dict, aes_share_key, aes_nonce = self.get_argument_dict(
                must_keys=['user_id', 'register_by', 'pvcode'],
                api_type=user_type,
                request_type=_REQUEST_TYPE_LOGIN)

            user_id = str(argument_dict['user_id'])
            register_by = argument_dict['register_by']
            pvcode = argument_dict['pvcode']

            if register_by not in [
                    _REGISTER_SET_PAYPD_EMAIL,
                    _REGISTER_SET_PAYPD_MOBILE,
            ]:
                self.return_error(30223)

            send_type = _VCODE_SET_PAY_PD
            service = VcodeService(aes_share_key=aes_share_key,
                                   aes_nonce=aes_nonce)

            # 校验图形验证码
            service.check_vcode_picture(pvcode,
                                        user_type=_USER_TYPE_INVEST,
                                        vcode_type=_VCODE_SET_PAY_PD)

            # 校验是否已经注册
            result = service.send_vcode_by_register_type(
                send_type,
                user_id,
                user_type=user_type,
                register_by=register_by)

            return result, aes_share_key, aes_nonce
        else:
            self.return_error(10004)
    def post(self):
        """
        用户注册
        :return:
        """
        # 1.0 获取注册参数
        user_type = _USER_TYPE_BORROW

        argument_dict, aes_share_key, aes_nonce = self.get_argument_dict(
            must_keys=[
                'user_mobile', 'vcode', 'password', 'register_signature'
            ],
            check_token=False,
            invariable_key=True,
            api_type=user_type,
            request_type=_REQUEST_TYPE_REGISTER)
        user_mobile = argument_dict['user_mobile']
        vcode = argument_dict['vcode']
        password = argument_dict['password']
        register_signature = argument_dict['register_signature']

        vcode_service = VcodeService(aes_share_key=aes_share_key,
                                     aes_nonce=aes_nonce)
        # 2.0 校验touken
        vcode_service.check_register_signature(register_signature)

        # 3.0 检查验证码有效性
        vcode_service.check_vcode(vcode,
                                  _VCODE_REGISTER,
                                  user_mobile,
                                  user_type=user_type)

        user_service = UserBaseService(aes_share_key=aes_share_key,
                                       aes_nonce=aes_nonce)
        # 4.0 处理用户注册逻辑
        result = user_service.register(user_mobile,
                                       password,
                                       0,
                                       user_type=user_type)

        if ('status' not in result) or result['status'] != "true":
            return result, aes_share_key, aes_nonce

        # 5.0 注册后直接登录
        login_result = user_service.login(user_mobile, password, user_type)
        result = dict(result, **login_result)
        return result, aes_share_key, aes_nonce
Ejemplo n.º 15
0
 def check_form_token(self, token):
     vcode_service = VcodeService()
     # 2.0 校验token
     return vcode_service.check_register_signature(token,
                                                   direct_error=False)
Ejemplo n.º 16
0
    def get_argument_dict(self,
                          must_keys=None,
                          format_str=False,
                          format_keys=True,
                          format_eval=True,
                          verify_timeliness=True,
                          encrypt=True,
                          check_token=True,
                          invariable_key=True,
                          check_form_token=False,
                          is_transfer=False,
                          api_type=_USER_TYPE_INVEST,
                          request_type=_REQUEST_TYPE_LOGIN,
                          decode_by_inner=_DECODE_TYPE_DEFAULT,
                          check_user_id=False):
        """
        :param must_keys: 必须含有的key
        :param format_str: str格式化
        :param format_keys: keys格式化
        :param format_eval:
        :param verify_timeliness: 校验时效性
        :param encrypt: 是否加密
        :param check_token: 是否校验token
        :param invariable_key: 是否采用默认的sharekey解密
        :param check_form_token: 是否校验表单的随机字符串
        :param is_transfer: 是否是通过usercenter传递数据到其他平台
        :param api_type: 访问接口的用户类型
        :param request_type: 请求的类型:注册、登陆前、登陆后
        :param decode_by_inner: 是否采用内网的sharekey解析
        :param check_user_id: 是否校验userid的正确性
        :return:
        """
        env = get_conf('env')
        if env == 'dev' and get_conf('close_all_aes'):
            # 测试环境,关所有校验的函数头
            verify_timeliness = False
            encrypt = False
            check_token = False
            invariable_key = False
            check_form_token = False

        try:
            # 1. 校验时效性
            if not verify_timeliness:
                request_header = request.headers
                source = request_header.get("Source", _SOURCE_TYPE_1)
            else:
                '''
                # 校验实效性,需要header中存在如下参数 Timestamp, Signature, Nonce, Source
                '''
                redis_tools = RedisTools()
                request_header = request.headers
                # 1.0 判断时间是否在请求限制时间内
                timestamp = request_header.get("Timestamp", '0')
                df_timestamp = abs(int(time.time()) - int(timestamp))
                if df_timestamp > 6000 or df_timestamp < 0:
                    self.return_error(10005)

                # 2.0 检查signature是否在redis中,防止重复请求
                c_signature = request_header.get("Signature")
                if redis_tools.exists(c_signature):
                    self.return_error(10003)

                # 3.0 验证c_signature合理性
                nonce = request_header.get("Nonce", '')
                source = request_header.get("Source", _SOURCE_TYPE_1)
                if nonce == '' or source == '':
                    self.return_error(10006)
                s_signature = sha256_hex(
                    str(timestamp) + str(nonce) + str(source))
                self.logger.info('check signature ' + str(timestamp) + ' ' +
                                 str(nonce) + ' ' + str(source) + ' ' +
                                 str(s_signature) + ' ' + str(c_signature))
                if s_signature != c_signature:
                    self.return_error(10004)

                # 4.0 将c_signature存到redis中
                redis_tools.set(name=c_signature, value="c_signature", ex=60)

            content = self.get_request_content()
            share_key, nonce = None, None

            # 2.1 不解密解析,仅开发环境生效
            if not encrypt:
                decrypt_content = content
                if 'data' in content and isinstance(content['data'], dict):
                    for k, v in content['data'].items():
                        content[k] = v
                    del content['data']

                if check_token:
                    #  2.0 获取用户信息
                    ts = ApiTokenService(
                        aes_share_key=share_key,
                        aes_nonce=nonce).check_access_token_by_user_id(
                            decrypt_content, api_type)
                    if not ts:
                        self.return_error(10035)
            else:
                if 'data' not in content.keys():
                    self.return_error(10008)
                delete_user_id = False
                if is_transfer and content['user_mobile'] == '':
                    invariable_key = False
                    check_token = False
                    decode_by_inner = _DECODE_TYPE_DEFAULT
                    delete_user_id = True

                # 2.2 使用指定秘钥解密
                if invariable_key:
                    decrypt_content, share_key, nonce = self.decrypt_request_content(
                        content,
                        check_token=check_token,
                        api_type=api_type,
                        request_type=request_type,
                        check_user_id=check_user_id,
                        source=source)
                else:
                    decrypt_content, share_key, nonce = self.decrypt_request_content_with_invariable_key(
                        content,
                        check_token=check_token,
                        api_type=api_type,
                        decode_by_inner=decode_by_inner,
                        source=source)
                if delete_user_id:
                    decrypt_content['user_id'] = ''

            # 3 规范入参
            request_args = formate_args(decrypt_content, format_str,
                                        format_keys, format_eval)
            self.logger.info("request_args解析后:" + str(request_args))

            # 4 确保表单有效性
            if check_form_token:
                if 'form_token' not in request_args:
                    self.return_error(10046)
                vcode_service = VcodeService(aes_share_key=share_key,
                                             aes_nonce=nonce)
                # 2.0 校验token
                vcode_service.check_register_signature(
                    request_args['form_token'])
                request_args.pop('form_token')

            # 5 校验是否包含规定的参数
            if must_keys:
                for key in must_keys:
                    if key not in request_args:
                        error_msg = "请求缺少 [%s] 参数" % key
                        self.return_error(10048, error_msg=error_msg)
            return request_args, share_key, nonce
        except InvalidUsageException as error:
            raise_logger(error.error_msg, error_code=error.error_code)
            raise error
        except OperateUsageException as error:
            raise error
        except Exception as error:
            raise_logger(str(error), error_code=10022)
            self.return_error(10022)
    def post(self):
        """
        用户注册
        :return:
        """
        # 1.0 获取注册参数
        user_type = _USER_TYPE_INVEST

        if check_use_source(_USE_SOURCE_TYPE_1):
            argument_dict, aes_share_key, aes_nonce = self.get_argument_dict(
                must_keys=[
                    'user_mobile', 'vcode', 'password', 'source',
                    'register_by', 'mobile_country_code'
                ],
                check_token=False,
                invariable_key=True,
                api_type=user_type,
                check_form_token=True,
                request_type=_REQUEST_TYPE_REGISTER)
            user_mobile = argument_dict['user_mobile']
            vcode = argument_dict['vcode']
            password = argument_dict['password']
            source = argument_dict['source']
            register_by = argument_dict['register_by']
            mobile_country_code = argument_dict['mobile_country_code']
            # 新需求取消用户名注册的方式
            # user_name = argument_dict['user_name']
            user_name = None

            vcode_service = VcodeService(aes_share_key=aes_share_key,
                                         aes_nonce=aes_nonce)

            # 3.0 检查验证码有效性
            vcode_service.check_vcode(vcode,
                                      _VCODE_REGISTER,
                                      user_mobile,
                                      user_type=user_type,
                                      register_by=register_by)

            user_service = UserBaseService(aes_share_key=aes_share_key,
                                           aes_nonce=aes_nonce)
            # 4.0 处理用户注册逻辑
            result = user_service.register_by_type(
                user_mobile,
                password,
                user_type=user_type,
                source=source,
                db_user_name=user_name,
                register_by=register_by,
                mobile_country_code=mobile_country_code,
                change_key_nonce=True)

            if ('status' not in result) or result['status'] != "true":
                return result, aes_share_key, aes_nonce

            # 6.0 注册后直接登录
            login_result = user_service.login_by_type(
                user_mobile,
                password,
                user_type,
                source=source,
                register_by=register_by,
                mobile_country_code=mobile_country_code)
            result = dict(result, **login_result)
        else:
            argument_dict, aes_share_key, aes_nonce = self.get_argument_dict(
                must_keys=['user_mobile', 'vcode', 'password'],
                check_token=False,
                invariable_key=True,
                api_type=user_type,
                request_type=_REQUEST_TYPE_REGISTER)
            user_mobile = argument_dict['user_mobile']
            vcode = argument_dict['vcode']
            password = argument_dict['password']

            vcode_service = VcodeService(aes_share_key=aes_share_key,
                                         aes_nonce=aes_nonce)

            # 3.0 检查验证码有效性
            vcode_service.check_vcode(vcode,
                                      _VCODE_REGISTER,
                                      user_mobile,
                                      user_type=user_type)

            user_service = UserBaseService(aes_share_key=aes_share_key,
                                           aes_nonce=aes_nonce)
            # 4.0 处理用户注册逻辑
            result = user_service.register(user_mobile,
                                           password,
                                           0,
                                           user_type=user_type)

            if ('status' not in result) or result['status'] != "true":
                return result, aes_share_key, aes_nonce

            # 5.0 账户表中生成用户账户
            transfer_url = get_transfer_to_platform_path(
                "invest", "generate_account")
            account_response_dict = transfer_to_platform(transfer_url,
                                                         data={
                                                             "user_id":
                                                             result['user_id'],
                                                             "user_mobile":
                                                             user_mobile
                                                         })

            if ("code" not in account_response_dict) or ("data" not in account_response_dict) or \
                    ('status' not in account_response_dict["data"]) or account_response_dict["data"]['status'] != "true":
                return account_response_dict, aes_share_key, aes_nonce
            user_service.register_on(user_mobile)

            # 6.0 注册后直接登录
            login_result = user_service.login(user_mobile, password, user_type)
            result = dict(result, **login_result)
        return result, aes_share_key, aes_nonce
    def post(self):
        user_type = _USER_TYPE_INVEST
        if check_use_source(_USE_SOURCE_TYPE_1):
            argument_dict, aes_share_key, aes_nonce = self.get_argument_dict(
                must_keys=[
                    'user_mobile', 'vcode', 'password', 'mobile_country_code',
                    'register_by'
                ],
                check_token=False,
                api_type=user_type,
                invariable_key=False,
                request_type=_REQUEST_TYPE_REGISTER,
                check_form_token=True)

            user_mobile = argument_dict['user_mobile']
            vcode = argument_dict['vcode']
            password = argument_dict['password']
            mobile_country_code = argument_dict['mobile_country_code']
            register_by = argument_dict['register_by']

            if register_by not in [
                    _RESET_PWD_MOBILE,
                    _RESET_PWD_EMAIL,
            ]:
                self.return_error(30223)

            vcode_service = VcodeService(aes_share_key=aes_share_key,
                                         aes_nonce=aes_nonce)
            vcode_service.check_vcode(vcode,
                                      _VCODE_RESETPD,
                                      user_mobile,
                                      user_type=user_type,
                                      register_by=register_by)

            r = UserBaseService(
                aes_share_key=aes_share_key,
                aes_nonce=aes_nonce).reset_login_password_by_type(
                    user_mobile,
                    password,
                    user_type=user_type,
                    register_by=register_by,
                    mobile_country_code=mobile_country_code,
                )
        else:
            argument_dict, aes_share_key, aes_nonce = self.get_argument_dict(
                must_keys=['user_mobile', 'vcode', 'password'],
                check_token=False,
                api_type=user_type,
                invariable_key=False,
                request_type=_REQUEST_TYPE_REGISTER)

            user_mobile = argument_dict['user_mobile']
            vcode = argument_dict['vcode']
            password = argument_dict['password']

            vcode_service = VcodeService(aes_share_key=aes_share_key,
                                         aes_nonce=aes_nonce)
            vcode_service.check_vcode(vcode,
                                      _VCODE_RESETPD,
                                      user_mobile,
                                      user_type=user_type)

            r = UserBaseService(aes_share_key=aes_share_key, aes_nonce=aes_nonce).\
                reset_login_password(user_mobile, password, user_type=user_type)

        return r, aes_share_key, aes_nonce
Ejemplo n.º 19
0
    def operation_gather(self, user_name, sub_public_address, conditions, coin_id, to_address, verification_code):
        """
        归集操作
        :param user_name: 用户名
        :param sub_public_address: 钱包地址
        :param conditions: 归集条件(大于等于xx个单位)
        :param coin_id: 币种(必填)
        :param to_address: 归集账户
        :param verification_code: 验证码
        :return:
        """
        conf = get_config()
        env = conf["env"]
        if env == "pd":
            vcode_service = VcodeService()
            result = vcode_service.check_sms_email_vcode('common', verification_code)
        f_filters = {}
        u_filters = {}
        if user_name:
            u_filters["user_name"] = user_name
        if sub_public_address:
            f_filters["sub_public_address"] = sub_public_address
        if not conditions:
            conditions = 0
        wfs = WalletForeignService()

        with MysqlTools().session_scope() as session:
            model = None
            if coin_id == _ZERO_S:
                model = WalletBtcModel
            elif coin_id == _SIXTY_S:
                model = WalletEthModel
            # token_conf = session.query(TokenConfModel).filter(TokenConfModel.coin_id == coin_id).first()
            # gather_minimum_amount = token_conf.gather_minimum_amount
            gather_minimum_amount = wfs.eth_get_gas()

            wallet_list = session.query(model, UserAccountModel).filter(
                model.amount >= conditions, model.account_id != "").filter_by(**f_filters).outerjoin(
                UserAccountModel,
                model.account_id == UserAccountModel.account_id).filter_by(**u_filters)
            total_amount = 0
            available_wallet_list = []
            for w in wallet_list:
                amount = 0
                if coin_id == _ZERO_S:
                    amount = w.WalletBtcModel.amount
                elif coin_id == _SIXTY_S:
                    amount = w.WalletEthModel.amount
                if gather_minimum_amount < amount:
                    available_wallet_list.append(w)
                    total_amount = total_amount + amount

            record_id = generate_order_no()
            foreign_gather_record = ForeignGatherRecordModel(
                record_id=record_id,
                coin_id=coin_id,
                public_address=to_address,
                conditions=conditions,
                purpose_amount=total_amount
            )
            session.add(foreign_gather_record)
            foreign_withdraw_order_record_list = []
            wallet_list = available_wallet_list
            if coin_id == _ZERO_S:
                for wallet in wallet_list:
                    if wallet.WalletBtcModel.amount > 0:
                        foreign_withdraw_order_record = ForeignWithdrawOrderRecordModel(
                            order_no=generate_order_no(),
                            relate_flow_no=foreign_gather_record.record_id,
                            account_id=wallet.WalletBtcModel.account_id,
                            coin_id=coin_id,
                            from_address=wallet.WalletBtcModel.sub_public_address,
                            withdraw_address=to_address,
                            withdraw_amount=wallet.WalletBtcModel.amount,
                            withdraw_type=_TWO,
                            withdraw_status=_ZERO,
                            audit_status=_ONE,
                            source_status=_ONE
                        )
                        foreign_withdraw_order_record_list.append(foreign_withdraw_order_record)
            elif coin_id == _SIXTY_S:
                for wallet in wallet_list:
                    if wallet.WalletEthModel.amount > 0:
                        foreign_withdraw_order_record = ForeignWithdrawOrderRecordModel(
                            order_no=generate_order_no(),
                            relate_flow_no=foreign_gather_record.record_id,
                            account_id=wallet.WalletEthModel.account_id,
                            coin_id=coin_id,
                            from_address=wallet.WalletEthModel.sub_public_address,
                            withdraw_address=to_address,
                            withdraw_amount=wallet.WalletEthModel.amount,
                            withdraw_type=_TWO,
                            withdraw_status=_ZERO,
                            audit_status=_ONE,
                            source_status=_ONE
                        )
                        foreign_withdraw_order_record_list.append(foreign_withdraw_order_record)
            session.add_all(foreign_withdraw_order_record_list)
            session.commit()

            if coin_id == _ZERO_S:  # 比特币
                for withdraw in foreign_withdraw_order_record_list:
                    wfs.btc_send_tx(withdraw)
            elif coin_id == _SIXTY_S:  # 以太坊
                for withdraw in foreign_withdraw_order_record_list:
                    wfs.eth_send_tx(withdraw)
            return