def get_valid_emails(emails): valid_emails = [] for email in emails: if not email: continue elif is_email_address(email): valid_emails.append(email.strip().lower()) return list(set(valid_emails)) # 去重复
def get_error_info(self): # 确认请求行为是否合法 content_length = len(self.content) if content_length < 5: return u'min length of comment is 5!' if content_length > 5000: return u'max length of comment is 5000!' if not self.content: # 编译后的评论内容为None return #ignore if not is_email_address(self.email): # 邮箱地址是必填的 return u'email address missing.' if not self.is_site_url_allowed(): # 网站地址不对(如果填了的话) return u'site address format error!' v_code = (request.values.get('verification_code') or '').strip() if not v_code: return u'verification code is required' if len(v_code) != 4: return u'verification code length is 4' if not is_verification_code_correct(): # 验证码错误 return u'verification code is error' if not self.post_method_is_allowed: # 当前请求 return u'sorry, the comment system thought your behavior is like a robot. try again later?' blocked_info = u'sorry, this post is not allowed to post comment' # 很明显的 spam 特性 if u'平台' in self.author or u'澳门' in self.author: return blocked_info elif u'共' in self.content and u'产' in self.content and u'党' in self.content: return blocked_info elif u'法' in self.content and u'轮' in self.content and u'功' in self.content: return blocked_info # 同ip, 同 email, 但是 site 不一样, 批量发广告的 if self.email and self.ip and self.site: for old_comment in self.all_comments: if old_comment.get('ip') == self.ip and old_comment.get( 'email' ) == self.email and old_comment.get('site') != self.site: return blocked_info if self.all_comments: last_comment = self.all_comments[-1] last_comment_content = last_comment.get('content') or '' if smart_unicode(last_comment_content) == self.content: return "can't comment same contents..."
def set_bucket_email(): bucket = get_logined_bucket() if not bucket: return abort(404, "need login first") info = "" if request.method == "POST": email = request.values.get("email", "").strip() if email and not is_email_address(email): info = "email format is error" else: set_owner_email_to_bucket(bucket, email) return p_redirect("/admin") else: email = get_bucket_owner_email(bucket) return render_api_template_as_response("page_user_set_bucket_email.jade", info=info, email=email)
def set_owner_email_to_bucket(bucket, email): email = email.strip().lower() if email and not is_email_address(email): return else: update_bucket_private_configs(bucket, email=email)
def is_email(obj): # 是否是邮箱地址 if isinstance(obj, (str, unicode)) and is_email_address(obj): return True else: return False