def post(self):
        user_type = _USER_TYPE_INVEST
        # 2.0 获取参数
        argument_dict, aes_share_key, aes_nonce = self.get_argument_dict(
            must_keys=['user_id'],
            api_type=user_type,
            request_type=_REQUEST_TYPE_LOGIN)

        user_info = UserBaseService(aes_share_key=aes_share_key, aes_nonce=aes_nonce).\
            get_user_info_by_id(argument_dict['user_id'], user_type=user_type)

        if check_use_source(_USE_SOURCE_TYPE_1):
            if 'user_mobile' in user_info and 'user_id' in user_info and user_info[
                    'user_id'] == user_info['user_mobile']:
                user_info['user_mobile'] = ''
            if 'email' in user_info and 'user_id' in user_info and user_info[
                    'user_id'] == user_info['email']:
                user_info['email'] = ''

            # 5.0 补充账户信息
            transfer_url = get_transfer_to_platform_path("invest", "user_info")
            if transfer_url != '':
                account_response_dict = transfer_to_platform(
                    transfer_url, data={"user_id": user_info['user_id']})

                if ("code" not in account_response_dict) or (
                        "data" not in account_response_dict):
                    self.return_error(30207)
                if account_response_dict['code'] != '00000':
                    self.return_error(account_response_dict['code'],
                                      account_response_dict['msg'])

                user_info.update(account_response_dict['data'])

        return user_info, aes_share_key, aes_nonce
Ejemplo n.º 2
0
 def get(self, path):
     argument_dict = self.get_request_content(set_default=False)
     raise_logger('CommonTransferToPlatformController' +
                  json.dumps(argument_dict))
     transfer_url = get_transfer_to_platform_config(
     )['default_ip'] + request.path
     response_dict = transfer_to_platform(transfer_url, data=argument_dict)
     return response_dict
Ejemplo n.º 3
0
    def send_Intl_ZT_sms(self, mobile, vcode, template=None, mobile_country_code=None):
        # 发送国际短信
        # 去除区号的+和0
        mobile_country_code = mobile_country_code.replace('+', '')
        mobile_country_code = str(int(mobile_country_code))

        zt_config = get_intl_zt_config()
        user_name = zt_config['user_name']
        password = zt_config['password']
        send_url = zt_config['send_url']

        time_str = datetime.datetime.fromtimestamp(int(time.time()), pytz.timezone('Asia/Shanghai')).strftime('%Y%m%d%H%M%S')
        send_password = encrypt_md5(encrypt_md5(password) + time_str)
        if template is None:
            send_message = '验证码为:' + str(vcode)
        else:
            send_message = str(template)
        request_data = {
                'username': user_name,
                'tkey': time_str,
                'password': send_password,
                'code': mobile_country_code,
                'mobile': mobile,
                'content': send_message,
            }
        response_data = transfer_to_platform(
            send_url,
            data=request_data,
            headers={
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            method="post",
            decode_type='str',
        )
        with self.session_scope() as session:
            q = SmsMessageModel(
                send_message=json.dumps({
                    'request_data': request_data,
                    'mobile': mobile,
                    'send_message': send_message,
                }),
                response_message=json.dumps(response_data),
                gateway='Intl_ZT',
            )
            session.add(q)
            session.commit()
        response_result = response_data.split(',')
        if response_result[0] == '1':
            return True
        else:
            return False
Ejemplo n.º 4
0
    def post(self, path):
        all_path_list = request.path.split("/")[1:]
        path_list = path.split("/")

        # 1.0 区别前后台用户
        if all_path_list[0] == 'bg':
            if len(path_list) < 2:
                self.return_error(10043)
            self.user_type = _USER_TYPE_ADMIN
            # 后台用户需要校验ip
            result = check_bg_ip()
            if result is False:
                self.return_error(30000)
        elif all_path_list[0] == 'users':
            pass
        else:
            self.return_error(10004)

        # 2.0 获取参数
        argument_dict, share_key, nonce = self.get_argument_dict(
            must_keys=self.must_keys,
            is_transfer=True,
            api_type=self.user_type,
            request_type=self.request_type,
            invariable_key=self.invariable_key,
            check_token=self.check_token,
            check_user_id=self.check_user_id,
            verify_timeliness=self.verify_timeliness,
            encrypt=self.encrypt,
            check_form_token=self.check_form_token)
        raise_logger('UsersTransferToPlatformController' +
                     json.dumps(argument_dict))
        # 3.0 后台用户校验权限
        user_service = UserBaseService(aes_share_key=share_key,
                                       aes_nonce=nonce)
        if self.user_type == _USER_TYPE_ADMIN:
            user_id = argument_dict['user_id']
            module_url = path_list[0]
            transfer_check_result = user_service.check_admin_user_module_rights_by_user_id(
                user_id, module_url)
            if not transfer_check_result:
                self.return_error(30232)
        transfer_url = get_transfer_to_platform_config(
        )['default_ip'] + request.path
        response_dict = transfer_to_platform(transfer_url, data=argument_dict)
        if self.return_aes:
            return response_dict, share_key, nonce
        else:
            return response_dict
Ejemplo n.º 5
0
    def get_argument_dict(self,
                          must_keys=None,
                          format_str=False,
                          format_keys=True,
                          format_eval=True,
                          check_form_token=False,
                          time_key_list=None):
        """
        :param must_keys: must_keys=["aa", "bb"] 判断出入列表里的值,是否在请求参数里,没有报错
        :param format_str: 是否需要把所有int类型,强转成字符串
        :param format_eval: 是否开启 把字符串 '["a","b"]' '{"a":1,"b":"1"}' 强转回list dict
        :param format_keys: 是否开启 把key的值 转为全小写
        :param check_form_token: 是否校验表单中的随机字符串,所有会修改数据的请求,都应该校验!!
        :param time_key_list: 转换时区的校验时间key补充字段列表
        :return:
        """
        # 获取参数字典
        request_args = self.get_request_content()

        request_args = formate_args(request_args, format_str, format_keys,
                                    format_eval)

        if get_env() != 'dev' and check_form_token:
            if 'form_token' not in request_args:
                self.return_error(10018)
            check_url = get_user_center_conf()[get_env(
            )]['base_url'] + '/transfer/' + str(request_args['form_token'])
            check_result = transfer_to_platform(check_url)
            if not check_result:
                self.return_error(10018)
            request_args.pop('form_token')

        # 判断必填字段
        if must_keys:
            for key in must_keys:
                if key not in request_args:
                    raise_logger("请求缺少 [%s] 参数" % key, lv="error")
                    self.return_error(20003)
        return self.timezone_transform(request_args, time_key_list)
    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