Example #1
0
    def post(self):
        err = JsOb()
        user_id = self.current_user_id
        content = self.json
        if not content.slotType:
            err.slotType = u'SlotType can\'t be empty!'
        if not content.name:
            err.name = u'Slot Name can\'t be empty!'
        elif Slots.count(dict(name=content.name, appId=int(user_id))):
            err.name = u'The slot name {} has been used!'.format(content.name)

        if not err:
            user_id = self.current_user_id
            slot = Slots.edit(user_id, None, content.slotType, content.name)
            ps_network = NetWork.pingstart(user_id)
            adapter = ps_network.adapter_model.get(
                TYPE_MAP.get(content.slotType))
            network = [
                dict(network_id=ps_network._id,
                     network_name=ps_network.name,
                     is_auth=True,
                     placement_id='publisher_id={user_id};slot_id={slot_id}'.
                     format(user_id=user_id, slot_id=slot._id),
                     is_paused=False,
                     adapter=adapter,
                     priority=0)
            ]
            slot.network = network
            slot.save()

        self.render(err)
Example #2
0
    def post(self):
        err = JsOb()
        if not self.json._ids:
            err.apply = u'offer can\'t be Null!'

        if not err:
            offers = []
            for offer_id in self.json._ids:
                affiliate_id = self.current_user_id
                off_aff = OfferAffiliate.find_one(
                    dict(offer_id=int(offer_id),
                         affiliate_id=int(affiliate_id),
                         deleted=False))
                offer = Offers.find_one(dict(_id=int(offer_id)))
                status = '1' if offer.access_status == '1' else '2'
                if not off_aff:
                    off_aff = OfferAffiliate._save(
                        **dict(offer_id=int(offer_id),
                               affiliate_id=int(affiliate_id),
                               status=status,
                               payout=offer.payment))
                else:
                    off_aff.payout = offer.payment
                    off_aff.status = status
                    off_aff.save()
                offers.append(offer)
            self.finish(dict(offers=offers, err=False))
        else:
            self.render(err)
Example #3
0
 def post(self):
     err = JsOb()
     post_back_id = self.json._id
     res = PBack.delete(post_back_id)
     if not res:
         err.delete = u'delete _id=%s failure' % post_back_id
     self.render(err)
Example #4
0
    def post(self):
        err = JsOb()
        user_id = self.current_user_id
        content = self.json
        slot_id = content.slot_id
        slot_name = content.slot_name
        network = content.network
        app_black_list = content.appBlackList
        model = content.model
        slot = Slots.find_one(dict(_id=int(slot_id)))
        if slot_name != slot.name and Slots.count(
                dict(name=slot_name, appId=int(user_id), deleted=False)):
            err.name = u'This Slot Name has been used!'

        if not err:
            slot.name = slot_name
            for n in network:
                net_id = n.get('network_id')
                net = NetWork.find_one(dict(_id=int(net_id)))
                if n.get('auth_manager'):
                    auth_manager = n.pop('auth_manager')
                    net.auth_manager = auth_manager
                    net.save()
                n['network_id'] = int(n['network_id'])
                n['adapter'] = net.adapter_model.get(
                    TYPE_MAP.get(slot.slotType))
            slot.network = network
            slot.model = model
            slot.appBlackList = app_black_list.split('\n')
            slot.last_operated = DateTime().today
            slot.save()

        self.render(err)
Example #5
0
    def post(self):
        err = JsOb()
        if not self.json.email:
            err.email = 'Please input email'
        elif not is_email(self.json.email):
            err.email = 'Email not valid'
        if not self.json.password:
            err.password = '******'
        if not self.json.captcha_code:
            err.captcha_code = 'Please input captcha code'
        elif not captcha_verify(self.json.captcha_key, self.json.captcha_code):
            err.captcha_code = 'captcha code incorrect'

        if not err:
            try:
                user = User.verify(self.json.email, self.json.password)
                if user:
                    if user._role == 'Affiliate' or user._role == 'Advertiser':
                        err.email = u'You don\'t have a login permissions!'
                    else:
                        self._session_new(self.json.email, user._id)
                        user.last_login = DateTime().current_time
                        user.save()
            except UserNotFoundError:
                err.email = "email not found"
            except PasswordNotMatchError:
                err.password = "******"

        self.render(err)
Example #6
0
    def post(self):
        err = JsOb()
        email = self.json.email
        if not email:
            err.email = 'Email not found!'

        code_list = random.sample(range(10), 6)
        captcha_code = ''.join(map(str, code_list))
        email_data = dict(
            email_server=EMAIL.get('email_server'),
            email_server_port=EMAIL.get('email_server_port'),
            username=EMAIL.get('user_name'),
            password=EMAIL.get('password'),
            sender=EMAIL.get('sender'),
            receiver=email,
            msg=dict(
                text=captcha_code,
                subject='PingStart Captcha for reset password',
            ),
        )

        send_status = send_email(email_data)
        if send_status != True:
            err.send_status = send_status
        else:
            cpatcha = Captcha.create(email=email, captcha_code=captcha_code)
        self.render(err)
Example #7
0
    def post(self):
        err = JsOb()
        pause_date = self.json.pause_date
        if not pause_date:
            err.pause_date = u'pause_date cat\'t be empty!'
        elif Tool.str_datetime(pause_date,
                               '%Y-%m-%d %H:%M:%S') <= datetime.datetime.now():
            err.pause_date = u'The pause time can\'t less than Now!'

        if not err:
            self.offer_id = self.json.offer_id
            job_type = 'date'
            store_executor_alias = 'offer'
            process_count = 5
            max_instances = 100
            scheduler = ScheInterface(job_type, store_executor_alias,
                                      process_count)
            res = scheduler.add_date_job(pause, [self.offer_id], pause_date,
                                         max_instances, self.job_listener)
            if res:
                scheduler.sche.start()
                self.send_email(pause_date, self.offer_id)
                offer = Offers.find_one(dict(_id=int(self.offer_id)))
                offer.pause_job_set = True
                offer.last_update = DateTime().current_time
                offer.save()
            else:
                err.pause_date = 'Add pause job failure!'

        self.render(err)
Example #8
0
    def post(self):
        err = JsOb()
        user_id = self.current_user_id
        content = self.json
        network_id = content._id
        network = NWork.find_one(dict(_id=int(network_id)))
        name = content.name
        if name != network.name and NWork.count(
                dict(name=name, user_id=int(user_id))):
            err.name = u'This name has been used!'

        if not err:
            network.name = name
            network.auth_manager = content.auth_manager
            network.save()

            spec = dict(
                network={'$elemMatch': dict(network_id=int(network._id))},
                deleted=False,
            )
            slots = Slots.find(spec)
            for s in slots:
                for n in s.network:
                    if n.get('network_id') == int(network._id):
                        n['network_name'] = name
                s._id = int(s._id)
                s.save()

        self.render(err)
Example #9
0
    def post(self):
        err = JsOb()
        form = self.json

        if not form.email:
            err.email = 'Please input email'
        elif not is_email(form.email):
            err.email = 'Email not valid'
        elif User.count(dict(email=form.email)):
            err.email = "email already in use"

        if not form.password:
            err.password = '******'
        elif not is_valid_password(form.password):
            err.password = '******'
        elif form.password != form.password2:
            err.password2 = 'Password not match'

        if not form.captcha_code:
            err.captcha_code = 'Please input captcha code'
        elif not captcha_verify(form.captcha_key, form.captcha_code):
            err.captcha_code = 'captcha code incorrect'

        if not err:
            user = User.regist(form.email, form.password, form.password2,
                               form.company)
            NetWork._init(user._id)
            self._session_new(user.email, user._id)

        self.render(err)
Example #10
0
 def post(self):
     err = JsOb()
     content = loads(self.request.body)
     off_aff_id = content.get('_id')
     res = OAffiliates._update(**content)
     if not res:
         err.error = u'update OfferAffiliate failure! ID={}'.format(
             off_aff_id)
Example #11
0
    def post(self):
        err = JsOb()
        url = self.json.url
        res = PBack.add(self.current_user_id, url)

        if not res:
            err.save = u'save url=%s failure' % url

        self.render(err)
Example #12
0
    def post(self):
        err = JsOb()
        new_password = self.json.new_password
        if not new_password:
            err.new_password = '******'
        elif not is_valid_password(new_password):
            err.new_password = '******'

        self.render(err)
Example #13
0
    def post(self):
        err = JsOb()
        post_back_id = self.json._id
        post_back_url = self.json.url
        try:
            res = PBack.update(post_back_id, post_back_url)
        except PostBackNotFound:
            err.update = u'update _id=%s failure' % post_back_id

        self.render(err)
Example #14
0
    def post(self):
        err = JsOb()
        user_id = self.json.user_id

        if not user_id:
            err.user_error = u'user_id can\'t be empty!'
            self.render(err)
        if not err:
            user = User._delete(user_id)
            self.finish(dict(user=user))
Example #15
0
    def post(self):
        err = JsOb()
        if not self.json.email:
            err.email = 'Please input email'
        elif not is_email(self.json.email):
            err.email = 'Email not valid'
        if not self.json.password:
            err.password = '******'
        if not self.json.captcha_code:
            err.captcha_code = 'Please input captcha code'
        elif not captcha_verify(self.json.captcha_key, self.json.captcha_code):
            err.captcha_code = 'captcha code incorrect'

        if not err:
            try:
                user = User.verify(self.json.email, self.json.password)
                if user:
                    self._session_new(user.email, user._id)
                    # user.last_login = DateTime().current_time
                    # user.save()
            except UserNotFoundError:
                err.email = "email not found"
            except PasswordNotMatchError:
                err.password = "******"

        self.render(err)
Example #16
0
    def post(self):
        form = loads(self.request.body)
        err = JsOb()
        user = self.current_user
        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.email and User.count(dict(email=e, deleted=False)):
                    err.email = "email %s already be used!" % e

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

        if not form.get('password'):
            err.password = '******'
        elif form.get('password') != user.password and not is_valid_password(form.get('password')):
            err.password = '******'
        if not err:
            user = User._update_account(form.get('user_id'), **dict(
                email=form.get('email').replace(' ', '').split(';'),
                password=form.get('password'),
                account=form.get('name'),
                skype_id=form.get('skype_id'),
                phone=form.get('phone'),
                role_id=Role.affiliate()._id
            ))
            Affiliate._update(form.get('_id'), **form)
        self.render(err)
Example #17
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)
Example #18
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)
Example #19
0
 def get(self, aff_id):
     err = JsOb()
     aff = Affiliate.find_one(dict(_id=int(aff_id)))
     if not aff:
         err.ad_info = "not found!"
     if err:
         self.render(err)
     else:
         aff.deleted = True
         aff._id = int(aff._id)
         aff.save()
     self.redirect("/affilicates/manage")
Example #20
0
 def get(self, offer_id):
     err = JsOb()
     offer = Offers.find_one(dict(_id=int(offer_id)))
     if not offer:
         err.ad_info = "not found!"
     if err:
         self.render(err)
     else:
         offer.deleted = True
         offer._id = int(offer._id)
         offer.save()
     self.redirect("/offers/manage")
Example #21
0
    def post(self):
        err = JsOb()
        user = self.current_user
        old_password = self.json.old_password
        if not old_password:
            err.old_password = '******'
        elif not is_valid_password(old_password):
            err.old_password = '******'
        elif user.encrypt_pwd(old_password) != self.current_user.password:
            err.old_password = '******'

        self.render(err)
Example #22
0
 def get(self, ad_id):
     err = JsOb()
     ad = Advertisers.find_one(dict(_id=int(ad_id)))
     if not ad:
         err.ad_info = "not found!"
     if err:
         self.render(err)
     else:
         ad.status = '0'
         ad._id = int(ad._id)
         ad.save()
     self.redirect("/advertisers/manage")
Example #23
0
    def post(self):
        err = JsOb()
        form = self.json

        if not form.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 User.count(dict(email=e, deleted=False)):
                    err.email = "email %s already in use" % e

        if not form.account:
            err.account = 'Pleast input your account'

        if not form.password:
            err.password = '******'
        elif not is_valid_password(form.password):
            err.password = '******'

        kw = dict(email=emails,
                  password=form.password,
                  account=form.account,
                  role_id=form.role_id,
                  skype_id=form.skype_id,
                  phone=form.phone)

        if not err:
            user = User._create(**kw)

        self.render(err)
Example #24
0
    def post(self):
        err = JsOb()
        form = self.json
        if not form.new_password:
            err.password = u'Please input password'
        elif not is_valid_password(form.new_password):
            err.password = u'Password not valid'
        new_password = User.encrypt_pwd(self.json.new_password)

        if not err:
            self.current_user.password = new_password
            self.current_user._id = int(self.current_user_id)
            self.current_user.save()

        self.render(err)
Example #25
0
    def post(self):
        err = JsOb()
        email = self.json.email
        captcha_code = self.json.captcha_code

        if not captcha_code:
            err.captcha_code = u'captcha code can\'t be empty!'

        if not err:
            captcha = Captcha.find_one(dict(email=email, code=captcha_code))
            if not captcha:
                err.captcha_code = u'captcha code not match!'

            elif (datetime.datetime.now() - Tool.str_datetime(
                    captcha.create_time, "%Y-%m-%d %H:%M:%S")).seconds > 300:
                err.captcha_code = u'captcha code expired!'

        self.render(err)
Example #26
0
    def post(self):
        err = JsOb()
        user_id = self.current_user_id
        placement_id = self.json.placement_id
        network_id = self.json.network_id
        spec = dict(
            appId=int(user_id),
            network={
                '$elemMatch':
                dict(placement_id=placement_id, network_id=int(network_id))
            },
            deleted=False,
        )
        slot = Slots.find_one(spec)
        if slot:
            err.placement = u'The placement_id has been used!'

        self.render(err)
Example #27
0
    def post(self):
        err = JsOb()
        user_id = self.current_user_id
        content = self.json
        name = content.name
        if NWork.count(dict(name=name, user_id=int(user_id))):
            err.name = u'This NetWork Name has been used!'

        if not err:
            adapter = content.adapter
            auth_manager = content.auth_manager
            sdk = content.sdk
            NWork.create(user_id=user_id,
                         name=name,
                         adapter=adapter,
                         auth_manager=auth_manager,
                         sdk=sdk)

        self.render(err)
Example #28
0
def _load(local, *args):
    self = JsOb()

    prepare_list = []
    finish_list = []
    dirpath = dirname(local['__file__'])
    sys.path.insert(0, dirpath)
    global CONFIG_LOADED

    def _load(name):
        if not exists(join(dirpath, '%s.py' % name.replace('.', '/'))):
            return
        try:
            mod = _import(name)
        except ImportError:
            logging.warning('ImportError %s' % name)
            import traceback
            logging.warning(traceback.format_exc())
            return

        if mod is None:
            return

        if mod in CONFIG_LOADED:
            CONFIG_LOADED.pop(CONFIG_LOADED.index(mod))
        CONFIG_LOADED.append(mod)

        mod.__file__.rsplit('.', 1)[0]

        prepare = getattr(mod, 'prepare', None)
        if prepare:
            prepare_list.append(prepare)

        finish = getattr(mod, 'finish', None)
        if finish:
            finish_list.append(finish)

    for i in args:
        _load(i)

    funclist = prepare_list + list(reversed(finish_list))
    for _ in funclist:
        _(self)
    local.update(self.__dict__)
    sys.path.pop(0)
    return self
Example #29
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)
Example #30
0
    def post(self):
        err = JsOb()
        new_password = self.json.new_password
        confirm_password = self.json.confirm_password
        if not new_password:
            err.new_password = '******'
        elif not is_valid_password(new_password):
            err.new_password = '******'

        if not confirm_password:
            err.confirm_password = '******'
        elif not is_valid_password(confirm_password):
            err.confirm_password = '******'

        if new_password != confirm_password:
            err.confirm_password = '******'

        self.render(err)