Пример #1
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)
Пример #2
0
    def post(self):
        status = self.get_argument('status', '')
        page = int(self.get_argument('page', '1'))
        limit = int(self.get_argument('limit', '100'))
        skip = (page - 1) * limit

        affs = Affiliate.find(
            dict(
                status={"$ne": '0'} if not status or status == '0' else status,
                # account_manager=int(self.current_user_id) if not self.current_user.is_admin else {'$ne': ''}
            ),
            limit=limit,
            skip=skip)
        for aff in affs:
            aff.status = 'Active' if aff.status == '1' else 'Pending'
            user = User._get(aff.user_id)
            if aff.account_manager:
                account_manager = User._get(aff.account_manager)
                aff.account_manager = account_manager.account
            aff['name'] = user.account
            aff['email'] = user.email
            aff['password'] = user.password
            aff['_id'] = user._id
            aff['skype_id'] = user.skype_id
            aff['phone'] = user.phone
            aff['offer_count'] = OAffiliate.count(
                dict(affiliate_id=int(aff._id)))
        affs_count = Affiliate.count(
            dict(
                status={"$ne": '0'} if not status or status == '0' else status,
                # account_manager=int(self.current_user_id) if not self.current_user.is_admin else {'$ne': ''}
            ))

        self.finish(dict(affs=affs, affs_count=affs_count))
Пример #3
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:
                    affiliate = Affiliate.find_one(dict(user_id=int(user._id)))
                    if affiliate:
                        if affiliate.status == '1':
                            self._session_new(self.json.email, user._id)
                            user.last_login = DateTime().current_time
                            user.save()
                        else:
                            err.application = 'The Account is Approving....'
                    else:
                        err.email = 'Affiliate not found, Please call the manager!'
            except UserNotFoundError:
                err.email = "email not found"
            except PasswordNotMatchError:
                err.password = "******"

        self.render(err)
Пример #4
0
    def post(self):
        start = self.json.start
        end = self.json.end
        query_fields = self.json.query_fields
        selected_filter = self.json.selected_filter or {}
        ams = selected_filter.get('ams_id', None)
        bds = selected_filter.get('bds_id', None)
        if ams:
            affiliates = Affiliate.find(
                dict(account_manager={"$in": [int(am_id) for am_id in ams]}))
            for aff in affiliates:
                selected_filter['affiliates_name'].append(aff.user_id)

        if bds:
            advertisers = Advertisers.find(
                dict(account_manager={"$in": [int(bd_id) for bd_id in bds]}))
            for ad in advertisers:
                selected_filter['advertisers_name'].append(ad.user_id)
        conversions_is_zero = self.json.conversions_is_zero
        limit = int(self.json.limit)
        page = int(self.json.page)
        hour = query_fields.get('hour')
        obj = ReportHour() if hour else ReportDay()

        data, data_count, total = yield self.get_data(obj, start, end,
                                                      query_fields, limit,
                                                      page, selected_filter,
                                                      conversions_is_zero)

        self.finish(dict(docs=data, doc_count=data_count, total=total[0]))
Пример #5
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))
Пример #6
0
 def post(self):
     email = self.get_argument('email')
     password = self.get_argument('password')
     user = User.find_one(dict(email=email, password=password))
     if user:
         affiliate = Affiliate.find_one(dict(user_id=int(user._id)))
         if affiliate:
             if affiliate.status == '1':
                 self._session_new(email, user._id)
                 self.redirect('/report')
Пример #7
0
    def get(self):
        status = {'0': 'Paused', '1': 'Active', '2': 'Pending'}
        offer_id = self.get_argument('offer_id')
        offer = Offers.find_one(dict(_id=int(offer_id)))
        if not offer:
            self.write(u'The offer is not exist!')
            return
        offer.status = status.get(offer.status)
        if offer.advertiser_id:
            ad = User._get(offer.advertiser_id)
            offer['advertiser'] = ad.account if ad else ''

        category = Category.find_one(
            _id=int(offer.category_id)) if offer.category_id else None
        offer['category'] = category.name if category else ''

        category = Category.find_one(
            _id=int(offer.category_id)) if offer.category_id else None
        offer['category'] = category.name if category else ''

        if offer.access_status == '1':
            offer.access_status = 'Public'
        elif offer.access_status == '2':
            offer.access_status = 'Need Approve'
        else:
            offer.access_status = 'Private'

        if offer.platform == '1':
            offer.platform = 'IOS'
        elif offer.platform == '2':
            offer.platform = 'ANDROID'
        elif offer.platform == '0':
            offer.platform = 'All'

        offer_affiliates = OAffiliate._query(offer_ids=[offer_id])
        for off_aff in offer_affiliates:
            affiliate = User.find_one(dict(_id=int(off_aff.affiliate_id)))
            affiliate_extend = Affiliate.find_one(
                dict(user_id=int(off_aff.affiliate_id)))
            if not affiliate_extend or not affiliate_extend.account_manager:
                off_aff['am_name'] = ''
            elif off_aff.status == '1':
                am = User.find_one(
                    dict(_id=int(affiliate_extend.account_manager)))
                off_aff['am_name'] = am.account
            off_aff['affiliate_name'] = affiliate.account if affiliate else ''
            if off_aff.status == '1':
                off_aff['application_status'] = 'Approved'
            elif off_aff.status == '2':
                off_aff['application_status'] = 'Pending'
            else:
                off_aff['application_status'] = 'Rejected'

        self.render(offer=offer, offer_affiliates=offer_affiliates)
Пример #8
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")
Пример #9
0
 def get(self):
     user_id = int(self.current_user_id)
     account = Affiliate.find_one(dict(user_id=user_id))
     user = User.find_one(dict(_id=user_id))
     account['name'] = user.account
     account['email'] = ';'.join(user.email)
     account['password'] = user.password
     account['phone'] = user.phone
     account['createdTime'] = user.createdTime
     account['last_login'] = user.last_login
     account['skype_id'] = user.skype_id
     self.render(account=account)
Пример #10
0
 def get(self):
     user_id = self.current_user_id
     affiliate = Affiliate.find_one(dict(user_id=int(user_id)))
     user = User.find_one(dict(_id=int(affiliate.account_manager)))
     lastest_offers = Offers.sort_limit(
         [('_id', -1)], 10, dict(status={'$ne': '0'}, is_api={'$ne': True}))
     deloffers = []
     for offer in lastest_offers:
         off_aff = OfferAffiliate.find_one(
             dict(offer_id=int(offer._id), affiliate_id=user_id, deleted=False))
         if off_aff:
             if off_aff.payout:
                 offer.payment = off_aff.payout
             if offer.access_status == '0' and off_aff.status != '1':
                 deloffers.append(offer)
         else:
             if offer.access_status == '0':
                 deloffers.append(offer)
     for i in deloffers:
         lastest_offers.remove(i)
     offer_infos = OfferInfo.sort_limit(
         [('amount', -1)], 10, dict(affiliate_id=user_id))
     # feature offers
     condition = []
     for i in offer_infos:
         condition.append({'_id': i.offer_id})
     if condition:
         high_income_offers = Offers.find(
             {'$or': condition, 'status': {'$ne': '0'}, 'is_api': {'$ne': True}})
         deloffers = []
         for offer in high_income_offers:
             off_aff = OfferAffiliate.find_one(
                 dict(offer_id=int(offer._id), affiliate_id=user_id, deleted=False))
             if off_aff:
                 if off_aff.payout:
                     offer.payment = off_aff.payout
                 if offer.access_status == '0' and off_aff.status != '1':
                     deloffers.append(offer)
             else:
                 if offer.access_status == '0':
                     deloffers.append(offer)
         for i in deloffers:
             high_income_offers.remove(i)
     else:
         high_income_offers = []
     self.render(
         account_manager=user,
         lastest_offers=lastest_offers,
         high_income_offers=high_income_offers,
     )
Пример #11
0
    def get(self, aff_id):
        affiliate = Affiliate.find_one(dict(user_id=int(aff_id)))
        user = User._get(affiliate.user_id)
        spec = dict(deleted=False, role_id=Role.am()._id)
        account_managers = User.find(spec)
        affiliate['account'] = user.account
        affiliate['email'] = user.email
        affiliate['skype_id'] = user.skype_id
        affiliate['phone'] = user.phone
        affiliate['password'] = user.password

        self.render(account_managers=account_managers,
                    affiliate=affiliate,
                    invoice_frequency=InvoiceFrequency)
Пример #12
0
    def get(self):
        offer_spce = dict(status={"$ne": 0}, is_api={"$ne": True})
        offers = Offers.find(offer_spce, dict(_id=1, title=1))

        affiliate_spec = dict(status={"$ne": 0})
        affiliates = Affiliate.find(affiliate_spec, dict(user_id=1))
        for aff in affiliates:
            user = User.find_one(dict(_id=int(aff.user_id)),
                                 dict(_id=1, account=1))
            if not user:
                continue
            aff['_id'] = user._id
            aff['name'] = user.account

        advertiser_spec = dict(status={"$ne": 0})
        advertisers = Advertisers.find(advertiser_spec, dict(user_id=1))
        for ad in advertisers:
            user = User.find_one(dict(_id=int(ad.user_id)),
                                 dict(_id=1, account=1))
            if not user:
                continue
            ad['_id'] = user._id
            ad['name'] = user.account

        categories = Category.find(dict(status={"$ne": 0}), dict(_id=1,
                                                                 name=1))

        ams = User.find(dict(role_id=Role.am()._id, deleted=False),
                        dict(_id=1, account=1, role_id=1))
        ams = [am for am in ams if am.role_id and am._role == 'AM']
        bds = User.find(dict(role_id=Role.bd()._id, deleted=False),
                        dict(_id=1, account=1, role_id=1))
        bds = [bd for bd in bds if bd.role_id and bd._role == 'BD']
        self.finish(
            dict(offers=offers,
                 affiliates=affiliates,
                 advertisers=advertisers,
                 categories=categories,
                 ams=ams,
                 bds=bds))
Пример #13
0
 def display_am(doc):
     if doc.get('affiliate_name'):
         affiliate_id = doc.get('affiliate_id')
         doc['AM'] = ''
         if affiliate_id:
             affiliate = Affiliate.find_one(
                 dict(user_id=int(affiliate_id)))
             if affiliate and affiliate.account_manager:
                 am = User.find_one(
                     dict(_id=int(affiliate.account_manager)))
                 doc['AM'] = am.account
     if doc.get('advertisers_name'):
         advertiser_id = doc.get('advertiser_id')
         doc['BD'] = ''
         if advertiser_id:
             advertiser = Advertisers.find_one(
                 dict(user_id=int(advertiser_id)))
             if advertiser and advertiser.account_manager:
                 bd = User.find_one(
                     dict(_id=int(advertiser.account_manager)))
                 doc['BD'] = bd.account
     return doc
Пример #14
0
    def post(self):
        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 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 User.count(dict(account=form.get('account'), deleted=False)):
            err['account'] = 'Account already be used!'

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

        if not form.get('account_manager'):
            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._create(**kw)
            form['user_id'] = user._id
            aff = Affiliate._save(**form)

        self.finish(dict(err=err if err else False))
Пример #15
0
    def get(self):
        affiliate_user_id = self.get_argument('affiliate_id')
        affiliate = Affiliate.find_one(dict(user_id=int(affiliate_user_id)))
        affiliate_user = User.find_one(dict(_id=int(affiliate_user_id)))
        if not affiliate or not affiliate_user:
            self.write(u'The affiliate is not exist!')
            return
        affiliate._id = affiliate.user_id
        affiliate['name'] = affiliate_user.account
        affiliate['email'] = affiliate_user.email
        affiliate['skype_id'] = affiliate_user.skype_id

        offer_affiliates = OAffiliate._query(affiliate_id=affiliate._id)
        for off_aff in offer_affiliates:
            offer = Offers.find_one(dict(_id=int(off_aff.offer_id)))
            off_aff['offer_title'] = offer.title if offer else ''
            if off_aff.status == '1':
                off_aff['application_status'] = 'Approved'
            elif off_aff.status == '2':
                off_aff['application_status'] = 'Pending'
            else:
                off_aff['application_status'] = 'Rejected'
        self.render(affiliate=affiliate, offer_affiliates=offer_affiliates)
Пример #16
0
    def get(self, action):
        obj_list = []
        if action == 'affiliate':
            offer_id = self.get_argument('offer_id')
            off_affs = OAffiliates._query(offer_ids=[offer_id])
            obj_ids = [off_aff.affiliate_id for off_aff in off_affs]
            affilate_extends = Affiliate.find(
                dict(account_manager={"$ne": ''}, status={'$ne': '0'}))
            objs = User.find(
                dict(_id={
                    "$in": [
                        int(aff.user_id) for aff in affilate_extends
                        if aff.account_manager
                    ]
                },
                     deleted=False))
            res = dict(affiliates=obj_list)

        elif action == 'offers':
            affiliate_id = self.get_argument('affiliate_id')
            off_affs = OAffiliates._query(affiliate_id=affiliate_id)
            obj_ids = [off_aff.offer_id for off_aff in off_affs]
            objs = Offers.find({
                'status': {
                    '$ne': '0'
                },
                'is_api': {
                    "$ne": True
                }
            })
            res = dict(offers=obj_list)

        for obj in objs:
            if int(obj._id) not in obj_ids:
                obj_list.append(obj)

        self.finish(res)
Пример #17
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 = '******'

        if form.password != form.confirmPassword:
            err.confirmPassword = '******'

        if not form.country:
            err.country = 'Please input Country'

        if not form.company:
            err.company = 'Please input Company'

        if not form.skype_id:
            err.skype = 'Please input Skype ID'

        if not form.phone:
            err.phone = 'Please input Phone'

        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:
            kw = dict(
                email=emails,
                password=form.password,
                account=form.account,
                role_id=Role.affiliate()._id,
                skype_id=form.skype_id,
                phone=form.phone,
            )
            user = User._create(**kw)
            payment = {
                'invoice_frequency': '',
                'threshold': '',
                'payment_method': '',
                'beneficiary': '',
                'account_number': '',
                'bank': '',
                'route': '',
                'paypal': ''
            }
            affiliate = Affiliate._save(**dict(user_id=int(user._id),
                                               country=form.country,
                                               status='2',
                                               company=form.company,
                                               payment=payment))

        self.render(err)
Пример #18
0
 def get(self):
     affiliates = Affiliate.find(dict(status={'$ne': '0'}))
     affiliate_user_ids = [a.user_id for a in affiliates if a]
     affiliates = User.find(dict(role_id=int(Role.affiliate()._id), _id={'$in': affiliate_user_ids}))
     self.render(affiliates=affiliates, currencys=CURRENCY_TYPES)
Пример #19
0
    def get(self):
        email = self.get_argument('email')
        pagenum = self.get_argument('pagenum', 100)
        page = self.get_argument('page', 1)
        status = self.get_argument('status', 'all',
                                   strip=True)  # myOffers # all
        user = User.find_one(dict(email=email, deleted=False))
        if user:
            aff = Affiliate.find_one(
                dict(user_id=user._id, status={'$ne': '0'}))
            if aff:
                url = "http://tracks.leadhug.com/lh/click?offer_id={0}&affiliate_id={1}&click_id={{clickid}}&aff_sub1={{aff_sub1}}"
                if status == "all":
                    spec = {'is_api': True, 'is_expired': False}
                    offers = Offers.find(spec,
                                         sort=[('_id', -1)],
                                         limit=int(pagenum),
                                         skip=(int(page) - 1) * int(pagenum))
                    if page == 1:
                        to_api_offers = Offers.find(dict(to_api=True,
                                                         status='1'),
                                                    sort=[('_id', -1)])
                    else:
                        to_api_offers = []
                    all_offers = offers + to_api_offers
                else:
                    spec = {"status": '1'}
                    off_affs = OfferAffiliate.find(
                        dict(affiliate_id=int(aff.user_id),
                             status='1',
                             deleted=False))
                    offer_ids = [int(off_aff.offer_id) for off_aff in off_affs]
                    spec.update(dict(_id={'$in': offer_ids}))
                    all_offers = Offers.find(spec, sort=[('_id', -1)])
                    for offer in all_offers:
                        off_aff = OfferAffiliate.find_one(
                            dict(offer_id=int(offer._id),
                                 affiliate_id=aff.user_id,
                                 deleted=False))
                        if off_aff.payout:
                            offer.payment = off_aff.payout
                for offer in all_offers:
                    offer['click_url'] = url.format(offer._id, aff.user_id)
                    offer['_id'] = int(offer['_id'])
                    if offer['platform'] == '1':
                        offer['platform'] = 'ios'
                    if offer['platform'] == '2':
                        offer['platform'] = 'android'
                    del offer['revenue']
                    del offer['clicks']
                    del offer['advertiser_id']
                    del offer['user']
                    del offer['conversions']
                    del offer['access_status']
                    del offer['last_update']
                    del offer['price_model']
                    del offer['status']
                    del offer['mini_version']
                    del offer['exclude_geo_targeting']
                    del offer['offer_type']
                    del offer['black_ip']
                    del offer['traffic_time']
                    del offer['create_time']
                    del offer['root']
                    del offer['is_api']
                    # del offer['offer_type']
                    del offer['category_id']
                    del offer['tag']
                    del offer['rating']
                    del offer['restrictions']
                    del offer['is_expired']
                    del offer['to_api']
                self.finish(json_encode(all_offers))

            else:
                self.finish('email invalid!')
        else:
            self.finish("email not found!")
Пример #20
0
    def get(self):
        cookie = self.get_cookie('S')
        query_fields = loads(self.get_argument('fields'))
        selected_filter = loads(self.get_argument('filter'))
        ams = selected_filter.get('ams_id', None)
        bds = selected_filter.get('bds_id', None)
        if ams:
            affiliates = Affiliate.find(
                dict(account_manager={"$in": [int(am_id) for am_id in ams]}))
            for aff in affiliates:
                selected_filter['affiliates_name'].append(aff.user_id)

        if bds:
            advertisers = Advertisers.find(
                dict(account_manager={"$in": [int(bd_id) for bd_id in bds]}))
            for ad in advertisers:
                selected_filter['advertisers_name'].append(ad.user_id)
        payout_is_zero = loads(self.get_argument('payout_is_zero'))
        time_range = loads(self.get_argument('time_range'))
        start = time_range.get('start')
        end = time_range.get('end')
        hour = query_fields.get('hour')
        obj = ReportHour() if hour else ReportDay()
        data, data_count, total = yield self.get_result(
            obj, start, end, query_fields, payout_is_zero, selected_filter)

        if isinstance(data, bool) and not data:
            self.write(u'The result exceeds maximum size!')
            self.finish()
            return

        _file_name = '{}_report.csv'.format(cookie)
        with open(_file_name, 'wb') as f:
            init_fieldnames = ['impressions', 'clicks', 'cost', 'conversions']
            fieldnames = [k.decode('utf-8') for k in query_fields.keys()]
            for i in ['hour', 'day', 'week', 'month', 'year']:
                if i in fieldnames:
                    fieldnames.remove(i)
                    fieldnames.insert(0, i)

            if 'affiliate_name' in fieldnames:
                fieldnames.extend(['affiliate_id', 'AM'])

            if 'advertiser_name' in fieldnames:
                fieldnames.extend(['advertiser_id', 'BD'])

            [
                fieldnames.append(i) for i in init_fieldnames
                if i not in fieldnames
            ]

            dict_writer = csv.DictWriter(f, fieldnames=fieldnames)
            dict_writer.writeheader()
            dict_writer.writerows(data)
            dict_writer.writerow(total)

        _file = file(_file_name, 'r')
        self.set_header('Content-Type', 'application/octet-stream')
        self.set_header('Content-Disposition',
                        'attachment; filename=report.csv')
        self.write(_file.read())
        self.finish()