Ejemplo n.º 1
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)
Ejemplo n.º 2
0
    def post(self, aff_id):
        affiliate_edit = Affiliate.find_one(dict(_id=int(aff_id)))
        user_edit = User._get(affiliate_edit.user_id)
        form = loads(self.request.body)
        err = {}
        if not form.get('email'):
            err['email'] = 'Please input email'
        else:
            emails = form['email'].replace(' ', '').split(',')
            for e in emails:
                if not is_email(e):
                    err['email'] = 'Email not valid, email=%s' % e
                elif e not in user_edit.email and User.count(
                        dict(email=e, deleted=False)):
                    err['email'] = "email %s already be used!" % e

        if not form.get('account'):
            err['account'] = 'Pleast input your account'
        elif form.get('account') != user_edit.account and User.count(
                dict(account=form.get('account'), deleted=False)):
            err['account'] = 'Account already be used!'

        if not form.get('password'):
            err['password'] = '******'
        elif form.get(
                'password') != user_edit.password and not is_valid_password(
                    form.get('password')):
            err['password'] = '******'

        if not form.get('account_manager') and form.get('status') != '0':
            err['account_manager'] = 'Please select Account Manager!'

        if not err:
            kw = dict(
                email=emails,
                password=form.get('password'),
                account=form.get('account'),
                role_id=Role.affiliate()._id,
                skype_id=form.get('skype_id'),
                phone=form.get('phone'),
            )
            user = User._update(user_edit._id, **kw)
            aff = Affiliate._update(aff_id, **form)

        self.finish(dict(err=err if err else False))
Ejemplo n.º 3
0
    def post(self):
        err = JsOb()
        user_id = self.json._id
        user_edit = User._get(user_id)
        if not self.json.account:
            err.account = u'Account not be empty!'
        elif self.json.account != user_edit.account and User.count(
                dict(account=self.json.account, deleted=False)):
            err.account = u'Account already in use!'

        if not self.json.email:
            err.email = u'Email not be empty!'
        else:
            emails = self.json.email.replace(' ', '').split(',')
            for e in emails:
                if not is_email(e):
                    err.email = 'Email not valid, email=%s' % e
                elif e not in user_edit.email and User.count(
                        dict(email=e, deleted=False)):
                    err.email = "email %s already in use" % e

        if self.json.password:
            if self.json.password != user_edit.password and not is_valid_password(
                    self.json.password):
                err.password = u'password not valid!'

        if not err:
            content = dict(account=self.json.account,
                           role_id=self.json.role_id,
                           email=emails,
                           password=self.json.password,
                           skype_id=self.json.skype_id,
                           phone=self.json.phone)
            res = User._update(user_id, **content)
            if not res:
                err.update = u'update user:{} failure'.format(user_id)

        self.render(err)