Example #1
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 #2
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 #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)
Example #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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)