示例#1
0
文件: main.py 项目: benmao/v2ex
 def get(self):
     chtml = captcha.displayhtml(
         public_key = config.recaptcha_public_key,
         use_ssl = False,
         error = None)
     browser = detect(self.request)
     template_values = {}
     template_values['page_title'] = u'V2EX › 注册'
     template_values['system_version'] = SYSTEM_VERSION
     template_values['errors'] = 0
     template_values['captchahtml'] = chtml
     if browser['ios']:
         path = os.path.join(os.path.dirname(__file__), 'tpl', 'mobile', 'signup.html')
     else:
         path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'signup.html')
     output = template.render(path, template_values)
     self.response.out.write(output)
示例#2
0
文件: main.py 项目: qhm123/the10000
 def get(self):
     site = GetSite()
     member = False
     chtml = captcha.displayhtml(public_key=config.recaptcha_public_key, use_ssl=False, error=None)
     browser = detect(self.request)
     template_values = {}
     template_values["site"] = site
     template_values["page_title"] = site.title + u" › 注册"
     template_values["system_version"] = SYSTEM_VERSION
     template_values["errors"] = 0
     template_values["captchahtml"] = chtml
     l10n = GetMessages(self, member, site)
     template_values["l10n"] = l10n
     if browser["ios"]:
         path = os.path.join(os.path.dirname(__file__), "tpl", "mobile", "signup.html")
     else:
         path = os.path.join(os.path.dirname(__file__), "tpl", "desktop", "signup.html")
     output = template.render(path, template_values)
     self.response.out.write(output)
示例#3
0
 def get(self):
     site = GetSite()
     member = False
     chtml = captcha.displayhtml(
         public_key = config.recaptcha_public_key,
         use_ssl = False,
         error = None)
     browser = detect(self.request)
     template_values = {}
     template_values['site'] = site
     template_values['page_title'] = site.title + u' › 注册'
     template_values['system_version'] = SYSTEM_VERSION
     template_values['errors'] = 0
     template_values['captchahtml'] = chtml
     l10n = GetMessages(self, member, site)
     template_values['l10n'] = l10n
     if browser['ios']:
         path = os.path.join(os.path.dirname(__file__), 'tpl', 'mobile', 'signup.html')
     else:
         path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'signup.html')
     output = template.render(path, template_values)
     self.response.out.write(output)
示例#4
0
    def post(self):
        site = GetSite()
        member = False
        browser = detect(self.request)
        template_values = {}
        template_values['site'] = site
        template_values['page_title'] = site.title + u' › 注册'
        template_values['system_version'] = SYSTEM_VERSION
        l10n = GetMessages(self, member, site)
        template_values['l10n'] = l10n
        errors = 0
        # Verification: username
        member_username_error = 0
        member_username_error_messages = ['',
            l10n.username_empty,
            l10n.username_too_long,
            l10n.username_invalid,
            l10n.username_taken]
        member_username = self.request.get('username').strip()
        if (len(member_username) == 0):
            errors = errors + 1
            member_username_error = 1
        else:
            if (len(member_username) > 32):
                errors = errors + 1
                member_username_error = 2
            else:
                if (re.search('^[a-zA-Z0-9\_]+$', member_username)):
                    q = db.GqlQuery('SELECT __key__ FROM Member WHERE username_lower = :1', member_username.lower())
                    if (q.count() > 0):
                        errors = errors + 1
                        member_username_error = 4
                else:
                    errors = errors + 1
                    member_username_error = 3
        template_values['member_username'] = member_username
        template_values['member_username_error'] = member_username_error
        template_values['member_username_error_message'] = member_username_error_messages[member_username_error]
        # Verification: password
        member_password_error = 0
        member_password_error_messages = ['',
            u'请输入你的密码',
            u'密码长度不能超过 32 个字符'
        ]
        member_password = self.request.get('password').strip()
        if (len(member_password) == 0):
            errors = errors + 1
            member_password_error = 1
        else:
            if (len(member_password) > 32):
                errors = errors + 1
                member_password_error = 2
        template_values['member_password'] = member_password
        template_values['member_password_error'] = member_password_error
        template_values['member_password_error_message'] = member_password_error_messages[member_password_error]
        # Verification: email
        member_email_error = 0
        member_email_error_messages = ['',
            u'请输入你的电子邮件地址',
            u'电子邮件地址长度不能超过 32 个字符',
            u'你输入的电子邮件地址不符合规则',
            u'抱歉这个电子邮件地址已经有人注册过了']
        member_email = self.request.get('email').strip()
        if (len(member_email) == 0):
            errors = errors + 1
            member_email_error = 1
        else:
            if (len(member_email) > 32):
                errors = errors + 1
                member_email_error = 2
            else:
                p = re.compile(r"(?:^|\s)[-a-z0-9_.]+@(?:[-a-z0-9]+\.)+[a-z]{2,6}(?:\s|$)", re.IGNORECASE)
                if (p.search(member_email)):
                    q = db.GqlQuery('SELECT __key__ FROM Member WHERE email = :1', member_email.lower())
                    if (q.count() > 0):
                        errors = errors + 1
                        member_email_error = 4
                else:
                    errors = errors + 1
                    member_email_error = 3
        template_values['member_email'] = member_email
        template_values['member_email_error'] = member_email_error
        template_values['member_email_error_message'] = member_email_error_messages[member_email_error]
        # Verification: invitation
        invitation = self.request.get('invitation').strip()
        q = db.GqlQuery('SELECT * FROM Invitation WHERE code = :1', invitation)
        if q.count() > 0:
            invi = q[0]
            logging.info('invitation code %s used.' % invitation)
            template_values['invitation_error'] = 0
        else:
            errors = errors + 1
            template_values['invitation_error'] = 1
            template_values['invitation_error_message'] = "无效的邀请码"
        # Verification: reCAPTCHA
        challenge = self.request.get('recaptcha_challenge_field')
        response  = self.request.get('recaptcha_response_field')
        remoteip  = os.environ['REMOTE_ADDR']
        
        cResponse = captcha.submit(
                         challenge,
                         response,
                         config.recaptcha_private_key,
                         remoteip)

        if cResponse.is_valid:
            logging.info('reCAPTCHA verification passed')
            template_values['recaptcha_error'] = 0
        else:
            errors = errors + 1
            error = cResponse.error_code
            chtml = captcha.displayhtml(
                public_key = config.recaptcha_public_key,
                use_ssl = False,
                error = cResponse.error_code)
            template_values['captchahtml'] = chtml
            template_values['recaptcha_error'] = 1
            template_values['recaptcha_error_message'] = '请重新输入 reCAPTCHA 验证码'
        template_values['errors'] = errors
        if (errors == 0):
            member = Member()
            q = db.GqlQuery('SELECT * FROM Counter WHERE name = :1', 'member.max')
            if (q.count() == 1):
                counter = q[0]
                counter.value = counter.value + 1
            else:
                counter = Counter()
                counter.name = 'member.max'
                counter.value = 1
            q2 = db.GqlQuery('SELECT * FROM Counter WHERE name = :1', 'member.total')
            if (q2.count() == 1):
                counter2 = q2[0]
                counter2.value = counter2.value + 1
            else:
                counter2 = Counter()
                counter2.name = 'member.total'
                counter2.value = 1
            member.num = counter.value
            member.username = member_username
            member.username_lower = member_username.lower()
            member.password = hashlib.sha1(member_password).hexdigest()
            member.email = member_email.lower()
            member.auth = hashlib.sha1(str(member.num) + ':' + member.password).hexdigest()
            member.put()
            counter.put()
            counter2.put()
            invi.used = True
            invi.put()
            self.response.headers['Set-Cookie'] = 'auth=' + member.auth + '; expires=' + (datetime.datetime.now() + datetime.timedelta(days=365)).strftime("%a, %d-%b-%Y %H:%M:%S GMT") + '; path=/'
            self.redirect('/')
        else:
            if browser['ios']:
                path = os.path.join(os.path.dirname(__file__), 'tpl', 'mobile', 'signup.html')
            else:
                path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'signup.html')
            output = template.render(path, template_values)
            self.response.out.write(output)
示例#5
0
文件: main.py 项目: iksky/v2ex
    def post(self):
        site = GetSite()
        member = False
        browser = detect(self.request)
        template_values = {}
        template_values['site'] = site
        template_values['page_title'] = site.title + u' › 注册'
        template_values['system_version'] = SYSTEM_VERSION
        l10n = GetMessages(self, member, site)
        template_values['l10n'] = l10n
        errors = 0
        # Verification: username
        member_username_error = 0
        member_username_error_messages = ['',
            l10n.username_empty,
            l10n.username_too_long,
            l10n.username_invalid,
            l10n.username_taken]
        member_username = self.request.get('username').strip()
        if (len(member_username) == 0):
            errors = errors + 1
            member_username_error = 1
        else:
            if (len(member_username) > 32):
                errors = errors + 1
                member_username_error = 2
            else:
                if (re.search('^[a-zA-Z0-9\_]+$', member_username)):
                    q = db.GqlQuery('SELECT __key__ FROM Member WHERE username_lower = :1', member_username.lower())
                    if (q.count() > 0):
                        errors = errors + 1
                        member_username_error = 4
                else:
                    errors = errors + 1
                    member_username_error = 3
        template_values['member_username'] = member_username
        template_values['member_username_error'] = member_username_error
        template_values['member_username_error_message'] = member_username_error_messages[member_username_error]
        # Verification: password
        member_password_error = 0
        member_password_error_messages = ['',
            u'请输入你的密码',
            u'密码长度不能超过 32 个字符'
        ]
        member_password = self.request.get('password').strip()
        if (len(member_password) == 0):
            errors = errors + 1
            member_password_error = 1
        else:
            if (len(member_password) > 32):
                errors = errors + 1
                member_password_error = 2
        template_values['member_password'] = member_password
        template_values['member_password_error'] = member_password_error
        template_values['member_password_error_message'] = member_password_error_messages[member_password_error]
        # Verification: email
        member_email_error = 0
        member_email_error_messages = ['',
            u'请输入你的电子邮件地址',
            u'电子邮件地址长度不能超过 32 个字符',
            u'你输入的电子邮件地址不符合规则',
            u'抱歉这个电子邮件地址已经有人注册过了']
        member_email = self.request.get('email').strip()
        if (len(member_email) == 0):
            errors = errors + 1
            member_email_error = 1
        else:
            if (len(member_email) > 32):
                errors = errors + 1
                member_email_error = 2
            else:
                p = re.compile(r"(?:^|\s)[-a-z0-9_.]+@(?:[-a-z0-9]+\.)+[a-z]{2,6}(?:\s|$)", re.IGNORECASE)
                if (p.search(member_email)):
                    q = db.GqlQuery('SELECT __key__ FROM Member WHERE email = :1', member_email.lower())
                    if (q.count() > 0):
                        errors = errors + 1
                        member_email_error = 4
                else:
                    errors = errors + 1
                    member_email_error = 3
        template_values['member_email'] = member_email
        template_values['member_email_error'] = member_email_error
        template_values['member_email_error_message'] = member_email_error_messages[member_email_error]
        # Verification: reCAPTCHA
        challenge = self.request.get('recaptcha_challenge_field')
        response  = self.request.get('recaptcha_response_field')
        remoteip  = os.environ['REMOTE_ADDR']
        
        cResponse = captcha.submit(
                         challenge,
                         response,
                         config.recaptcha_private_key,
                         remoteip)

        if cResponse.is_valid:
            logging.info('reCAPTCHA verification passed')
            template_values['recaptcha_error'] = 0
        else:
            errors = errors + 1
            error = cResponse.error_code
            chtml = captcha.displayhtml(
                public_key = config.recaptcha_public_key,
                use_ssl = False,
                error = cResponse.error_code)
            template_values['captchahtml'] = chtml
            template_values['recaptcha_error'] = 1
            template_values['recaptcha_error_message'] = '请重新输入 reCAPTCHA 验证码'
        template_values['errors'] = errors
        if (errors == 0):
            member = Member()
            q = db.GqlQuery('SELECT * FROM Counter WHERE name = :1', 'member.max')
            if (q.count() == 1):
                counter = q[0]
                counter.value = counter.value + 1
            else:
                counter = Counter()
                counter.name = 'member.max'
                counter.value = 1
            q2 = db.GqlQuery('SELECT * FROM Counter WHERE name = :1', 'member.total')
            if (q2.count() == 1):
                counter2 = q2[0]
                counter2.value = counter2.value + 1
            else:
                counter2 = Counter()
                counter2.name = 'member.total'
                counter2.value = 1
            member.num = counter.value
            member.username = member_username
            member.username_lower = member_username.lower()
            member.password = hashlib.sha1(member_password).hexdigest()
            member.email = member_email.lower()
            member.auth = hashlib.sha1(str(member.num) + ':' + member.password).hexdigest()
            member.l10n = site.l10n
            member.put()
            counter.put()
            counter2.put()
            self.response.headers['Set-Cookie'] = 'auth=' + member.auth + '; expires=' + (datetime.datetime.now() + datetime.timedelta(days=365)).strftime("%a, %d-%b-%Y %H:%M:%S GMT") + '; path=/'
            self.redirect('/')
        else:
            if browser['ios']:
                path = os.path.join(os.path.dirname(__file__), 'tpl', 'mobile', 'signup.html')
            else:
                path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'signup.html')
            output = template.render(path, template_values)
            self.response.out.write(output)
示例#6
0
文件: main.py 项目: qhm123/the10000
    def post(self):
        site = GetSite()
        member = False
        browser = detect(self.request)
        template_values = {}
        template_values["site"] = site
        template_values["page_title"] = site.title + u" › 注册"
        template_values["system_version"] = SYSTEM_VERSION
        l10n = GetMessages(self, member, site)
        template_values["l10n"] = l10n
        errors = 0
        # Verification: username
        member_username_error = 0
        member_username_error_messages = [
            "",
            l10n.username_empty,
            l10n.username_too_long,
            l10n.username_invalid,
            l10n.username_taken,
        ]
        member_username = self.request.get("username").strip()
        if len(member_username) == 0:
            errors = errors + 1
            member_username_error = 1
        else:
            if len(member_username) > 32:
                errors = errors + 1
                member_username_error = 2
            else:
                if re.search("^[a-zA-Z0-9\_]+$", member_username):
                    q = db.GqlQuery("SELECT __key__ FROM Member WHERE username_lower = :1", member_username.lower())
                    if q.count() > 0:
                        errors = errors + 1
                        member_username_error = 4
                else:
                    errors = errors + 1
                    member_username_error = 3
        template_values["member_username"] = member_username
        template_values["member_username_error"] = member_username_error
        template_values["member_username_error_message"] = member_username_error_messages[member_username_error]
        # Verification: password
        member_password_error = 0
        member_password_error_messages = ["", u"请输入你的密码", u"密码长度不能超过 32 个字符"]
        member_password = self.request.get("password").strip()
        if len(member_password) == 0:
            errors = errors + 1
            member_password_error = 1
        else:
            if len(member_password) > 32:
                errors = errors + 1
                member_password_error = 2
        template_values["member_password"] = member_password
        template_values["member_password_error"] = member_password_error
        template_values["member_password_error_message"] = member_password_error_messages[member_password_error]
        # Verification: email
        member_email_error = 0
        member_email_error_messages = [
            "",
            u"请输入你的电子邮件地址",
            u"电子邮件地址长度不能超过 32 个字符",
            u"你输入的电子邮件地址不符合规则",
            u"抱歉这个电子邮件地址已经有人注册过了",
        ]
        member_email = self.request.get("email").strip()
        if len(member_email) == 0:
            errors = errors + 1
            member_email_error = 1
        else:
            if len(member_email) > 32:
                errors = errors + 1
                member_email_error = 2
            else:
                p = re.compile(r"(?:^|\s)[-a-z0-9_.]+@(?:[-a-z0-9]+\.)+[a-z]{2,6}(?:\s|$)", re.IGNORECASE)
                if p.search(member_email):
                    q = db.GqlQuery("SELECT __key__ FROM Member WHERE email = :1", member_email.lower())
                    if q.count() > 0:
                        errors = errors + 1
                        member_email_error = 4
                else:
                    errors = errors + 1
                    member_email_error = 3
        template_values["member_email"] = member_email
        template_values["member_email_error"] = member_email_error
        template_values["member_email_error_message"] = member_email_error_messages[member_email_error]
        # Verification: invitation
        invitation = self.request.get("invitation").strip()
        q = db.GqlQuery("SELECT * FROM Invitation WHERE code = :1", invitation)
        if q.count() > 0:
            invi = q[0]
            logging.info("invitation code %s used." % invitation)
            template_values["invitation_error"] = 0
        else:
            errors = errors + 1
            template_values["invitation_error"] = 1
            template_values["invitation_error_message"] = "无效的邀请码"
        # Verification: reCAPTCHA
        challenge = self.request.get("recaptcha_challenge_field")
        response = self.request.get("recaptcha_response_field")
        remoteip = os.environ["REMOTE_ADDR"]

        cResponse = captcha.submit(challenge, response, config.recaptcha_private_key, remoteip)

        if cResponse.is_valid:
            logging.info("reCAPTCHA verification passed")
            template_values["recaptcha_error"] = 0
        else:
            errors = errors + 1
            error = cResponse.error_code
            chtml = captcha.displayhtml(
                public_key=config.recaptcha_public_key, use_ssl=False, error=cResponse.error_code
            )
            template_values["captchahtml"] = chtml
            template_values["recaptcha_error"] = 1
            template_values["recaptcha_error_message"] = "请重新输入 reCAPTCHA 验证码"
        template_values["errors"] = errors
        if errors == 0:
            member = Member()
            q = db.GqlQuery("SELECT * FROM Counter WHERE name = :1", "member.max")
            if q.count() == 1:
                counter = q[0]
                counter.value = counter.value + 1
            else:
                counter = Counter()
                counter.name = "member.max"
                counter.value = 1
            q2 = db.GqlQuery("SELECT * FROM Counter WHERE name = :1", "member.total")
            if q2.count() == 1:
                counter2 = q2[0]
                counter2.value = counter2.value + 1
            else:
                counter2 = Counter()
                counter2.name = "member.total"
                counter2.value = 1
            member.num = counter.value
            member.username = member_username
            member.username_lower = member_username.lower()
            member.password = hashlib.sha1(member_password).hexdigest()
            member.email = member_email.lower()
            member.auth = hashlib.sha1(str(member.num) + ":" + member.password).hexdigest()
            member.put()
            counter.put()
            counter2.put()
            invi.used = True
            invi.put()
            self.response.headers["Set-Cookie"] = (
                "auth="
                + member.auth
                + "; expires="
                + (datetime.datetime.now() + datetime.timedelta(days=365)).strftime("%a, %d-%b-%Y %H:%M:%S GMT")
                + "; path=/"
            )
            self.redirect("/")
        else:
            if browser["ios"]:
                path = os.path.join(os.path.dirname(__file__), "tpl", "mobile", "signup.html")
            else:
                path = os.path.join(os.path.dirname(__file__), "tpl", "desktop", "signup.html")
            output = template.render(path, template_values)
            self.response.out.write(output)