def get(self, ad_id): advertiser = Advertisers.find_one(dict(user_id=int(ad_id))) white_list = advertiser.white_list advertiser.white_list = ','.join(white_list) if white_list else '' user = User._get(advertiser.user_id) spec = dict(deleted=False, role_id=Role.bd()._id) bds = User.find(spec) pms = User.find(dict(role_id=Role.pm()._id), deleted=False) if user: advertiser['name'] = user.account advertiser['email'] = ','.join(user.email) advertiser['skype_id'] = user.skype_id advertiser['password'] = user.password self.render(account_managers=bds, pms=pms, advertiser=advertiser)
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)
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)
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)
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))
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)
def data_init(): _t = DateTime() for r in ['AM', 'Affiliate', 'Advertiser', 'BD', 'PM']: role = Role( dict(_id=gid(GidKey.role_key), name=r, permission=[], createdTime=_t.current_time, last_update=_t.current_time, deleted=False)) role.save() user = User( dict(_id=gid(GidKey.user_key), account='admin', email=['*****@*****.**'], password=User.encrypt_pwd(u'chizicheng521'), role_id='', is_admin=True, createdTime=_t.current_time, last_update=_t.current_time, last_login=_t.current_time, deleted=False)) user.save()
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))
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))
def get(self): spec = dict(role_id=Role.bd()._id, deleted=False) account_managers = User.find(spec) pms = User.find(dict(role_id=Role.pm()._id, deleted=False)) self.render(account_managers=account_managers, pms=pms)
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)
def get(self): roles = Role.find({'_id': {'$ne': 1}}) self.finish(dict(roles=roles))
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)
def get(self): spec = dict(role_id=Role.am()._id, deleted=False) account_managers = User.find(spec) self.render(account_managers=account_managers, invoice_frequency=InvoiceFrequency)
def get(self): roles = Role.find(dict(name={"$nin": ['Affiliate', 'Advertiser']})) self.finish(dict(roles=roles))
def _role(self): if self.is_admin: return 'admin' role = Role.find_one(dict(_id=self.role_id)) return role.name