예제 #1
0
    def post(self):
        err = JsOb()
        name = self.json.name
        if not name:
            err.name = u'Advertiser name can\'t be empty!'
        elif User.count(dict(account=name)):
            err.name = u'The name has been used!'
        emails = self.json.email
        if not emails:
            err.email = u'email can\'t be empty!'
        else:
            emails = emails.replace(' ', '').split(',')
            for e in emails:
                if not is_email(e):
                    err.email = u'Email not valid, email=%s' % e
                elif User.count(dict(email=e, deleted=False)):
                    err.email = u"email %s already be used!" % e

        password = self.json.password
        if not is_valid_password(password):
            err.password = u'The password not Valid!'
        skype_id = self.json.skype_id
        country = self.json.country
        account_manager = self.json.account_manager
        if not account_manager:
            err.account_manager = u'BD must selected!'
        pm = self.json.pm
        if not pm:
            err.pm = u'PM must selected!'
        status = self.json.status
        white_list = self.json.white_list
        white_list = white_list.split(',') if white_list else None

        if not err:
            user = User._create(**dict(email=emails,
                                       password=password,
                                       account=name,
                                       role_id=Role.advertiser()._id,
                                       skype_id=skype_id))

            kw = dict(
                user_id=user._id,
                country=country,
                account_manager=int(account_manager)
                if account_manager else None,
                pm=int(pm) if pm else None,
                offer_count=0,
                white_list=white_list,
                status=status,
            )
            advertiser = Advertisers._save(**kw)
            self.finish(dict(advertiser_id=user._id, err=False))
        else:
            self.render(err)
예제 #2
0
    def post(self, ad_id):
        err = JsOb()
        content = self.json
        ad = User.find_one(dict(_id=int(content.user_id)))
        if not content.name:
            err.name = u'Advertiser name can\'t be empty!'
        elif content.name != ad.account and User.count(
                dict(account=content.name)):
            err.name = u'The name has been used!'

        if not content.email:
            err.email = u'email can\'t be empty!'
        else:
            emails = content.email.replace(' ', '').split(',')
            for e in emails:
                if not is_email(e):
                    err.email = u'Email not valid, email=%s' % e
                elif e not in ad.email and User.count(
                        dict(email=e, deleted=False)):
                    err.email = u"email %s already be used!" % e

        if content.password != ad.password and not is_valid_password(
                content.password):
            err.password = u'The password not Valid!'

        if not content.account_manager:
            err.bd = u'BD must selected!'

        if not content.pm:
            err.pm = u'PM must selected!'

        if not err:
            user = User._update(
                content.user_id,
                **dict(email=emails,
                       password=content.password,
                       account=content.name,
                       skype_id=content.skype_id,
                       role_id=Role.advertiser()._id))

            kw = dict(
                country=content.country,
                account_manager=int(content.account_manager)
                if content.account_manager else None,
                pm=int(content.pm) if content.pm else None,
                white_list=content.white_list.split(',')
                if content.white_list else None,
                status=content.status,
            )

            advertiser = Advertisers._update(ad_id, **kw)
            self.finish(dict(advertiser_id=user._id, err=False))
        else:
            self.render(err)