示例#1
0
 def test_update(self):
     assert not Identity.get(self.user.id_)
     assert not has_real_identity(self.user)
     Identity.save(self.user.id_, u'张无忌', u'44011320141005001X')
     Identity.save(self.user.id_, u'谢逊', u'360426199101010071')
     identity = Identity.get(self.user.id_)
     assert has_real_identity(self.user)
     assert identity and identity.id_
     assert identity.id_ == self.user.id_
     assert identity.person_name == u'谢逊'
     assert identity.person_ricn == u'360426199101010071'
     assert identity.masked_name == u'*逊'
示例#2
0
文件: order.py 项目: c1xfr2e/soledad
    def check_before_adding(cls, user_id, product_id, bankcard_id, amount):
        product = PlaceboProduct.get(product_id)
        bankcard = BankCard.get(bankcard_id)
        user = Account.get(user_id)

        # 检查关联对象
        for attr_name, attr in [('product_id', product),
                                ('bankcard_id', bankcard), ('user_id', user)]:
            if not attr:
                raise ValueError('invalid %s' % attr_name)

        # 检查身份认证
        if not has_real_identity(user):
            raise InvalidIdentityError()

        # 检查产品是否可售
        if not product.strategy.target(user_id):
            raise InvalidProductError(product_id)  # 策略拒绝
        if not product.in_stock:
            raise OffShelfError(product_id)  # 下架

        # 检查金额范围
        if amount is None and product.min_amount == product.max_amount:
            amount = product.min_amount
        if (amount.is_nan() or amount < product.min_amount
                or amount > product.max_amount):
            raise OutOfRangeError(amount,
                                  (product.min_amount, product.max_amount))

        return user, product, bankcard, amount
示例#3
0
def initialize():
    if not g.user:
        return redirect(url_for('accounts.login.login', next=request.path))

    # 圣诞游戏获取红包的用户如果没有身份信息则跳转
    game_gift = ChristmasGift.get_by_mobile_phone(g.user.mobile)
    if not has_real_identity(
            g.user) and game_gift and game_gift.rank.award.firewood_wrapper:
        return redirect(url_for('profile.auth.supply', next=request.path))

    # 礼券管理
    g.coupon_manager = CouponManager(g.user.id_)
    # 为用户创建抵扣金账户
    g.firewood_flow = FirewoodWorkflow(g.user.id_)
    # 用户浏览任意福利相关页,则关闭福利提醒提示
    welfare_reminder_group.remove_member(g.user.id_)

    # 用户红包记录
    pileds = FirewoodPiling.get_multi_by_user(g.user.id_)
    burneds = FirewoodBurning.get_multi_by_user(g.user.id_)
    g.records = sorted(pileds + burneds,
                       key=attrgetter('creation_time'),
                       reverse=True)

    # 临时:用户访问该页面时默认将相关通知置为已读
    unread_notices = Notification.get_multi_unreads_by_user(g.user.id_)
    unread_notices = [
        n for n in unread_notices if n.kind is welfare_gift_notification
    ]
    for un in unread_notices:
        un.mark_as_read()
示例#4
0
文件: order.py 项目: c1xfr2e/soledad
    def check_before_adding(cls, service_id, user_id, order_amount):
        yixin_service = YixinService.get(service_id)
        yixin_account = YixinAccount.get_by_local(user_id)
        user = Account.get(user_id)

        # checks the related entities
        if not yixin_service:
            raise NotFoundError(service_id, YixinService)
        if not user:
            raise NotFoundError(user_id, Account)
        if not yixin_account:
            raise UnboundAccountError(user_id)

        # checks the identity
        if not has_real_identity(user):
            raise InvalidIdentityError

        # checks available
        if yixin_service.sell_out:
            raise SellOutError(yixin_service.uuid)
        if yixin_service.take_down:
            raise TakeDownError(yixin_service.uuid)

        # checks the amount type
        if not isinstance(order_amount, decimal.Decimal):
            raise TypeError('order_amount must be decimal')

        # checks the amount range
        amount_range = (yixin_service.invest_min_amount,
                        yixin_service.invest_max_amount)
        if (order_amount.is_nan() or order_amount < 0
                or order_amount < yixin_service.invest_min_amount
                or order_amount > yixin_service.invest_max_amount):
            raise OutOfRangeError(order_amount, amount_range)
示例#5
0
 def test_create(self):
     identity = Identity.save(self.user.id_, u'张无忌', u'44011320141005001X')
     assert has_real_identity(self.user)
     assert identity and identity.id_
     assert identity.id_ == self.user.id_
     assert identity.person_name == u'张无忌'
     assert identity.person_ricn == u'44011320141005001X'
     assert identity.masked_name == u'**忌'
示例#6
0
def check_identity():
    if ZhiwangAccount.get_by_local(g.user.id_):
        if not has_real_identity(g.user):
            # 当用户有指旺账号却没有身份信息时跳转完善信息(基本不可能发生)
            return redirect(url_for('profile.auth.supply', next=request.path))
    else:
        # 没有指旺账号则跳转注册页
        return redirect(url_for('savings.auth.zhiwang', next=request.path))

    g.identity = Identity.get(g.user.id_)
示例#7
0
文件: mine.py 项目: c1xfr2e/soledad
def index():
    cur_path = 'savings'

    # 个人信息
    saving_manager = SavingsManager(g.user.id_)
    coupon_manager = CouponManager(g.user.id_)

    # 礼券
    coupons = coupon_manager.deduplicated_available_coupons

    # 指旺产品
    fdb_products, cls_products, ncm_products = [], [], []
    for p in ZhiwangProduct.get_all():
        if p.product_type is ZhiwangProduct.Type.fangdaibao:
            fdb_products.append(p)
        elif p.product_type is ZhiwangProduct.Type.classic:
            # 指旺暂不显示中长期产品
            if p.profit_period['min'] not in (
                    ProfitPeriod(90, 'day'),  # 临时决定不在Web上显示90天产品
                    ProfitPeriod(180, 'day'),
                    ProfitPeriod(270, 'day'),
                    ProfitPeriod(365, 'day')):
                cls_products.append(p)

    # 2016年五月一日下线指旺自选到期日产品
    if not zhiwang_fdb_product_on_switch.is_enabled:
        fdb_products = []

    xm_products = XMFixedDuedayProduct.get_all()

    has_identity = has_real_identity(g.user)
    # 合作方授权(检查是否需要验证(尝试自动注册)指旺账号
    zhiwang_account = ZhiwangAccount.get_by_local(g.user.id_)
    can_quick_reg_zhiwang = has_identity and not zhiwang_account

    # 合作方授权(检查是否需要验证(尝试自动注册)新米账号
    xm_account = XMAccount.get_by_local(g.user.id_)
    can_quick_reg_xm = has_identity and not xm_account

    context = {
        'cur_path': cur_path,
        'coupons': coupons,
        'ncm_products': ncm_products,
        'fdb_products': fdb_products,
        'cls_products': cls_products,
        'xm_products': xm_products,
        'saving_manager': saving_manager,
        'plan_amount': g.hoard_profile.plan_amount,
        'can_quick_reg_xm': can_quick_reg_xm,
        'can_quick_reg_zhiwang': can_quick_reg_zhiwang
    }
    return render_template('savings/mine.html', **context)
示例#8
0
文件: facade.py 项目: c1xfr2e/soledad
    def initialize_with_user(self, user_id):
        """Initializes with user and identity.

        :param user_id: The local account id of user.
        :raises RealIdentityRequiredError: if the user has not real identity.
        """
        self.user = Account.get(user_id)
        self.identity = Identity.get(user_id)

        if not self.user:
            raise ProgrammingError('user %r not found' % user_id)
        if not has_real_identity(self.user):
            raise RealIdentityRequiredError(self.user)
示例#9
0
def publicity():
    # 指旺活动产品
    products = [
        p for p in ZhiwangProduct.get_all()
        if p.product_type is ZhiwangProduct.Type.fangdaibao
    ]
    products = sorted(products, key=attrgetter('final_due_date'))
    product = first((p for p in products if p.in_stock), None)
    can_quick_reg_zhiwang = None
    if g.user:
        zhiwang_account = ZhiwangAccount.get_by_local(g.user.id_)
        can_quick_reg_zhiwang = not zhiwang_account and has_real_identity(
            g.user)
    return render_template('savings/publicity.html',
                           cur_path='savings',
                           product=product,
                           can_quick_reg_zhiwang=can_quick_reg_zhiwang)
示例#10
0
def invitation():
    invitation_reminder_group.remove_member(g.user.id)
    # 50为临时性限制单页显示数目,防止炸裂,以后考虑分页.
    invitation_ids = Invitation.get_ids_by_inviter_id(g.user.id_)[:50]
    invitations = Invitation.get_multi(invitation_ids)
    has_identity = has_real_identity(g.user)
    code = transform_digit(int(g.user.id_))
    invite_url = url_for('invite.invite', inviter=code, _external=True)
    package_worth = invite_investment_package.firewood_wrapper.worth
    total_award = sum([
        invite_investment_package.firewood_wrapper.worth
        for invitation in invitations
        if invitation.status is Invitation.Status.accepted
    ])
    return render_template('invite/invite_app.html',
                           has_identity=has_identity,
                           invitations=invitations,
                           total_award=total_award,
                           invite_url=invite_url,
                           package_worth=package_worth)
示例#11
0
文件: order.py 项目: c1xfr2e/soledad
    def check_before_adding(cls, vendor, user_id, bankcard_id, product_id,
                            amount):
        if not vendor:
            raise NotFoundEntityError(vendor.id_, Account)

        product = HoarderProduct.get(product_id)
        local_account = Account.get(user_id)
        bankcard = BankCard.get(bankcard_id)
        hoarder_account = HoarderAccount.get(vendor.id_, user_id)

        if not local_account:
            raise NotFoundEntityError(user_id, Account)
        if not bankcard:
            raise NotFoundEntityError(bankcard_id, BankCard)
        if not hoarder_account:
            raise UnboundAccountError(user_id)

        if not has_real_identity(local_account):
            raise InvalidIdentityError()

        # 产品是否处于可售状态
        if product.is_sold_out:
            raise SoldOutError(product_id)
        # 产品是否处于正常销售状态
        if product.is_taken_down:
            raise SuspendedError(product_id)
        # 产品是否处于在售状态
        if not product.is_on_sale:
            raise OffShelfError(product_id)

        # checks the product amount limit
        if not isinstance(amount, Decimal):
            raise TypeError('order amount must be decimal')

        amount_range = (product.min_amount, product.max_amount)
        amount_check = [
            amount.is_nan(), amount < 0, amount < amount_range[0],
            amount > amount_range[1]
        ]
        if any(amount_check):
            raise OutOfRangeError(amount, amount_range)
示例#12
0
文件: order.py 项目: c1xfr2e/soledad
    def check_before_adding(cls, user_id, bankcard_id, product_id, amount):
        product = XMFixedDuedayProduct.get(product_id)

        bankcard = BankCard.get(bankcard_id)
        local_account = Account.get(user_id)
        xm_account = XMAccount.get_by_local(user_id)

        # checks the related entities
        if not bankcard:
            raise NotFoundError(bankcard_id, BankCard)
        if not local_account:
            raise NotFoundError(local_account, Account)
        if not xm_account:
            raise UnboundAccountError(user_id)

        # checks the identity
        if not has_real_identity(local_account):
            raise InvalidIdentityError

        # 产品是否处于可售状态
        if product.is_sold_out:
            raise SoldOutError(product_id)
        # 产品是否处于正常销售状态
        if product.is_taken_down:
            raise SuspendedError(product_id)
        # 产品是否处于在售状态
        if not product.in_stock:
            raise OffShelfError(product_id)

        # checks the product amount limit
        if not isinstance(amount, Decimal):
            raise TypeError('order amount must be decimal')
        amount_range = (product.min_amount, product.max_amount)
        amount_check = [amount.is_nan(),
                        amount < 0,
                        amount < amount_range[0],
                        amount > amount_range[1]]
        if any(amount_check):
            raise OutOfRangeError(amount, amount_range)
示例#13
0
    def test_migrate(self, rsyslog):
        old_user = self.add_account('*****@*****.**', 'foobaz', 'foo')
        assert not Identity.get(old_user.id_)
        assert not has_real_identity(self.user)

        old_profile = OldHoardProfile.add(old_user.id_)
        old_profile.person_name = u'谢逊'
        old_profile.person_ricn = u'44011320141005001X'

        identity = Identity.get(old_user.id_)
        assert rsyslog.send.called
        assert identity and identity.id_ == old_user.id_
        assert identity.person_name == u'谢逊'
        assert identity.person_ricn == u'44011320141005001X'

        # migrated automatically
        old_profile.person_name = ''
        old_profile.person_ricn = ''
        identity = Identity.get(old_user.id_)
        assert identity and identity.id_ == old_user.id_
        assert identity.person_name == u'谢逊'
        assert identity.person_ricn == u'44011320141005001X'
示例#14
0
 def dispatch_request(self):
     if not g.user:
         return redirect(url_for('accounts.login.login', next=request.url))
     if has_real_identity(g.user):
         return redirect(self.next_url)
     return self.render_template()
示例#15
0
def check_identity():
    if not has_real_identity(g.user):
        return redirect(url_for('wallet.mine.auth', next=request.path))
示例#16
0
文件: order.py 项目: c1xfr2e/soledad
    def check_before_adding(cls,
                            user_id,
                            bankcard_id,
                            product_id,
                            amount,
                            wrapped_product_id=None):
        product = ZhiwangProduct.get(product_id)
        wrapped_product = ZhiwangWrappedProduct.get(
            wrapped_product_id) if wrapped_product_id else None

        # check the product and wrapped_product
        if wrapped_product_id is not None and not wrapped_product:
            raise NotFoundError(wrapped_product_id, ZhiwangWrappedProduct)
        if wrapped_product and wrapped_product.raw_product.product_id != product_id:
            raise UnknownProductInheritance(product_id, wrapped_product_id)
        if wrapped_product and not wrapped_product.is_qualified(user_id):
            raise IneligiblePurchase(user_id, wrapped_product_id)

        product = wrapped_product if wrapped_product else product
        bankcard = BankCard.get(bankcard_id)
        local_account = Account.get(user_id)
        zhiwang_account = ZhiwangAccount.get_by_local(user_id)

        # checks the related entities
        if not bankcard:
            raise NotFoundError(bankcard_id, BankCard)
        if not local_account:
            raise NotFoundError(local_account, Account)
        if not zhiwang_account:
            raise UnboundAccountError(user_id)

        # checks the identity
        if not has_real_identity(local_account):
            raise InvalidIdentityError

        # 产品是否处于可售状态
        if product.is_either_sold_out:
            raise SoldOutError(product_id, wrapped_product_id)
        # 产品是否处于正常销售状态
        if product.is_taken_down:
            raise SuspendedError(product_id, wrapped_product_id)
        # 产品是否处于在售状态
        if not product.in_stock:
            raise OffShelfError(product_id, wrapped_product_id)

        # checks the product amount limit
        if not isinstance(amount, Decimal):
            raise TypeError('order amount must be decimal')
        amount_range = (product.min_amount, product.max_amount)
        amount_check = [
            amount.is_nan(), amount < 0, amount < amount_range[0],
            amount > amount_range[1]
        ]
        if any(amount_check):
            raise OutOfRangeError(amount, amount_range)

        # checks the bank amount limit
        bank_limit = bankcard.bank.zwlib_amount_limit
        bank_limit = max(bank_limit) if cls.is_bankcard_swiped(
            bankcard) else min(bank_limit)
        if amount > bank_limit:
            raise ExceedBankAmountLimitError(amount, bank_limit)
示例#17
0
 def test_create_by_old_user(self):
     Identity.save(self.old_user.id_, u'张无忌', u'44011320141005001X')
     assert not has_real_identity(self.user)