def post(self): logging.info(self.request.params) body = self.request.get('body') body = body.encode('ascii', 'ingore') # assert False, self.request.params try: message = mail.AdminEmailMessage( sender='*****@*****.**', subject='Feedback', ) message.body = body message.check_initialized() message.send() except Exception, e: logging.critical('Feedback Message could not send') logging.critical(body) logging.critical(e)
def post(self): quotation = models.Quotation() quotation.Email = self.request.get('email') quotation.Request = self.request.get('request') quotation.ServiceType = self.request.get('type') quotation.Name = self.request.get('name') quotation.Contact_No = int(self.request.get('contact')) quotation.put() message = mail.AdminEmailMessage() message.sender = '*****@*****.**' message.body = """ testing quotation sender is: %s """ % quotation.Email message.Send() self.display_message( 'Your enquiry has been sent. We will get back to you within 3 working days' )
def post(self): comment = Comment( page=self.request.path) #use path_qs for dynamic sites # google account #if users.get_current_user(): # comment.user = users.get_current_user() if self.request.get('remmaps'): self.redirect('#commentform') return comment.author = self.request.get('author') url = self.request.get('url') if "://" not in url and "@" not in url and "." in url: url = "http://" + url comment.url = url content = cgi.escape(self.request.get('content')) if not content: self.redirect('#commentform') return r = "((?:ftp|https?)://[^ \t\n\r()\"']+)" content = re.sub(r, r'<a rel="nofollow" href="\1">\1</a>', content) content = content.replace("\n", "<br/>\n") comment.content = db.Text(content) comment.put() # Ask client to reload ASAP self.redirect('#commentform') # Send notification email notification = mail.AdminEmailMessage() notification.sender = "*****@*****.**" #TODO: don't hardcode notification.subject = (comment.author.encode("utf-8") or "anonymous") + '@' + self.request.host notification.body = 'http://' + self.request.host + self.request.path + '#comment-' + str( comment.key().id()) notification.send()
def _SendToAdmins(self, request, response, log=logging.info): """Implementation of MailServer::SendToAdmins(). Logs email message. Contents of attachments are not shown, only their sizes. Given the difficulty of determining who the actual sender is, Sendmail and SMTP are disabled for this action. Args: request: The message to send, a mail_service_pb.MailMessage. response: An unused api_base_pb.VoidProto. log: Log function to send log information. Used for dependency injection. """ self._ValidateExtensions(request) mime_message = mail.mail_message_to_mime_message(request) self._CacheMessage(mail.AdminEmailMessage(mime_message=mime_message)) self._GenerateLog('SendToAdmins', request, log) if self._smtp_host and self._enable_sendmail: log('Both SMTP and sendmail are enabled. Ignoring sendmail.')
def post(self, id, cursor=None): if self.GET['viewmode'] == 'mobile': error_page = message_page = 'message_mobile.html' else: error_page = 'error.html' message_page = 'message.html' is_ajax = self.request.is_xhr if is_ajax: self.set_content_type('json') user = self.request.current_user is_admin = self.request.is_admin if not (is_admin or user.flag & USER_FLAGS['active']): if is_ajax: self.write( simplejson.dumps({ 'status': 403, 'content': u'抱歉,您已被管理员禁言,无法发表评论。如有异议,请联系管理员。' })) else: self.echo( error_page, { 'page': 'error', 'title': '评论发表失败', 'h2': '抱歉,您已被管理员禁言,无法发表评论', 'msg': '如有异议,请联系管理员。' }) return comment = self.POST.get('comment').strip() if not comment: if is_ajax: self.write( simplejson.dumps({ 'status': 400, 'content': u'拜托,你也写点内容再发表吧' })) else: self.echo( error_page, { 'page': 'error', 'title': '评论发表失败', 'h2': '拜托,你也写点内容再发表吧', 'msg': '赶紧返回重新写吧…' }) return ua = [] browser, platform, os, os_version, vendor = self.request.ua_details if platform: if platform in ('iPhone', 'iPod Touch', 'iPad', 'Android'): ua.append(platform) elif self.request.is_mobile: ua.append('mobile') else: if self.request.is_mobile: ua.append('mobile') elif os and os in ('Windows', 'Mac OS', 'Linux', 'FreeBSD'): ua.append(os) if browser: if browser == 'Internet Explorer': ua.append('IE') elif browser in ('Firefox', 'Chrome', 'Safari', 'Opera'): ua.append(browser) elif browser == 'Mobile Safari': ua.append('Safari') elif browser in ('Opera Mini', 'Opera Mobile'): ua.append('Opera') id = int(id) article = Article.get_article_by_id(id) if id else None if article: def post_comment(article_key, email, content, format, ua): comment = Comment(parent=article_key, email=email, content=content, format=format, ua=ua) comment.put() article = Article.get(article_key) article.replies += 1 article.put() return comment email = user.key().name() format = CONTENT_FORMAT_FLAG['bbcode'] if self.POST[ 'bbcode'] == 'on' else CONTENT_FORMAT_FLAG['plain'] comment = db.run_in_transaction(post_comment, article.key(), email, comment, format, ua) if comment: if is_ajax: self.write( simplejson.dumps({ 'status': 200, 'comment': { 'user_name': user.name, 'url': user.site, 'img': user.get_gravatar(), 'ua': comment.ua, 'time': formatted_time(comment.time), 'id': comment.key().id(), 'content': comment.html_content() } })) else: self.echo( message_page, { 'page': 'message', 'title': '评论发表成功', 'h2': '评论发表成功', 'msg': '缓存更新后将会立即显示您的评论' }) try: clear_latest_comments_memcache(id) deferred.defer(ping_hubs, BLOG_COMMENT_FEED_URL) url = '' if NOTIFY_WHEN_REPLY and not is_admin and ( not SEND_INTERVAL or memcache.add('has_sent_email_when_reply', 1, SEND_INTERVAL)): url = u'%s%s%s' % (MAJOR_HOST_URL, BLOG_HOME_RELATIVE_PATH, article.quoted_url()) html_content = comment.html_content( )[: 4096] # maximum size of an AdminEmailMessage is 16 kilobytes html_body = u'%s 在 <a href="%s">%s</a> 评论道:<br/>%s' % ( escape( user.name), url, article.title, html_content) title = u'Re: ' + article.title mail.AdminEmailMessage(sender=ADMIN_EMAIL, subject=title, html=html_body).send() import gdata_for_gae deferred.defer(gdata_for_gae.send_sms, user.name, article.title) if MAX_SEND_TO and format != CONTENT_FORMAT_FLAG[ 'plain'] and (is_admin or user.flag & SEND_LEVEL): if not url: url = u'%s%s%s' % (MAJOR_HOST_URL, BLOG_HOME_RELATIVE_PATH, article.quoted_url()) html_content = comment.html_content( )[: 4096] # maximum size of parameters of a task queue is 10 kilobytes html_body = u'%s 在 <a href="%s">%s</a> 评论道:<br/>%s<hr/>您收到这封邮件是因为有人回复了您的评论。您可前往原文回复,请勿直接回复该邮件。<br/>若您不希望被打扰,可修改您的<a href="%s%sprofile/">账号设置</a>。' % ( escape(user.name), url, article.title, html_content, MAJOR_HOST_URL, BLOG_HOME_RELATIVE_PATH) title = u'Re: ' + article.title else: html_body = u'%s<hr/>您收到这封邮件是因为有人回复了您的评论。您可前往原文回复,请勿直接回复该邮件。<br/>若您不希望被打扰,可修改您的<a href="%s%sprofile/">账号设置</a>。' % ( html_body, MAJOR_HOST_URL, BLOG_HOME_RELATIVE_PATH) deferred.defer(send_reply_notification, html_content, html_body, title, id) except: logging.error(format_exc()) else: if is_ajax: self.write( simplejson.dumps({ 'status': 500, 'content': u'评论发表失败,原文不存在或数据库忙' })) else: self.echo( error_page, { 'page': 'error', 'title': '评论发表失败', 'h2': '糟糕', 'msg': '评论发表失败,原文不存在或数据库忙' }) else: if is_ajax: self.write( simplejson.dumps({ 'status': 404, 'content': u'评论发表失败,原文不存在' })) else: self.echo( error_page, { 'page': 'error', 'title': '评论发表失败', 'h2': '糟糕', 'msg': '评论发表失败,原文不存在' })
def post(self, *args, **kwargs): #@UnusedVariable ''' Checks for existing account with that business If the account exists, return true @attention: Only handles the case where a single account is tied to no more than one business @keyword email: required @keyword password: required @keyword business_name: required @keyword vicinity: required @keyword geo_point: required @keyword types: require @keyword development: optional @return: packaged_user with levrToken, packaged_business ''' # for invalid credential responses user_doesnt_own_business_message = 'User does not own that business' # for packaging private = True followers = False # input values email = kwargs.get('email') password = kwargs.get('pw') business_name = kwargs.get('businessName') vicinity = kwargs.get('vicinity') geo_point = kwargs.get('geoPoint') types = kwargs.get('types') development = kwargs.get( 'development', False ) # TODO: switch this to False by default when changing to live phone_number = kwargs.get('phoneNumber', '') try: # Convert input data password = enc.encrypt_password(password) types = types.split(',') logging.debug('{}\n{}\n{}\n{}'.format(repr(business_name), repr(vicinity), geo_point, repr(types))) # check for existing entities user = levr.Customer.all().filter('email', email).get() requested_business = levr.Business.all().filter( 'business_name', business_name).filter('vicinity', vicinity).get() if user: logging.info('User exists') # check password assert user.pw == password, 'Password does not match username' # user should have a business try: business = user.businesses.get() # if the user has a business, it should be the business that was requested assert business, 'User does not own any businesses yet' except: logging.debug( 'user does not have a business yet - create one') # if the user does not have a business yet, add this one. business = levr.create_new_business(business_name, vicinity, geo_point, types, phone_number, owner=user) # assert False, user_doesnt_own_business_message else: logging.debug('User owns a business') # logging.debug(levr.log_model_props(business.owner)) # logging.debug(levr.log_model_props(requested_business.owner)) # if requested_business: # assert business.key() == requested_business.key(), user_doesnt_own_business_message else: logging.debug('User does not exist. Create a new one!!') # Create an account for the user with that business user = levr.create_new_user( tester=development, pw=password, email=email, display_name=business_name, ) logging.debug(business_name) logging.debug(levr.log_model_props(user)) if not requested_business: logging.debug('requested business was not found') business = levr.create_new_business(business_name, vicinity, geo_point, types, phone_number, owner=user) else: logging.debug('requested business was found') business = requested_business # business.owner = user business.put() logging.debug('business: ' + repr(business)) #=================================================================== # # Send message to the founders that someone has signed up for the app #=================================================================== if not development: try: from google.appengine.api import mail message = mail.AdminEmailMessage( sender='*****@*****.**', subject='New Merchant', ) message.body = levr.log_model_props( user, [ 'email', 'display_name', ]) message.body += levr.log_model_props( business, ['business_name', 'vicinity']) message.check_initialized() message.send() except: levr.log_error() #=================================================================== # # package and send #=================================================================== packaged_user = api_utils.package_user(user, private, followers, send_token=True) packaged_business = api_utils.package_business(business) response = {'user': packaged_user, 'business': packaged_business} self.send_response(response) # TODO: Merchant connect - handle all cases - new and existing accounts except AssertionError, e: levr.log_error() self.send_error(e)
def post(self, *args, **kwargs): try: logging.info('uploadDeal\n\n\n') logging.info(kwargs) user = kwargs.get('actor') uid = user.key() #make sure than an image is uploaded logging.debug(self.get_uploads()) if self.get_uploads(): #will this work? upload = self.get_uploads()[0] blob_key = upload.key() img_key = blob_key upload_flag = True else: upload_flag = False raise KeyError('Image was not uploaded') params = { 'uid': uid, 'business_name': kwargs.get('businessName'), 'geo_point': kwargs.get('geoPoint'), 'vicinity': kwargs.get('vicinity'), 'types': kwargs.get('types'), 'deal_description': kwargs.get('description'), 'deal_line1': kwargs.get('dealText'), 'distance': kwargs.get('distance'), #is -1 if unknown = double 'shareURL': kwargs.get('shareURL'), 'development': kwargs.get('development'), 'img_key': img_key } #create the deal using the origin specified deal_entity = levr.dealCreate(params, 'phone_new_business', upload_flag) #fire off a task to rotate the image task_params = {'blob_key': str(deal_entity.img.key())} logging.info('Sending this to the task: ' + str(task_params)) taskqueue.add(url=IMAGE_ROTATION_TASK_URL, payload=json.dumps(task_params)) #give the user some karma user.karma += 5 #level check! user = api_utils.level_check(user) user.put() #go notify everyone that should be informed try: levr.create_notification('followedUpload', user.followers, user.key(), deal_entity) except: levr.log_error() #grab deal information for sending back to phone deal = api_utils.package_deal(deal_entity, True) response = {'deal': deal} #=================================================================== # Send notification to founders #=================================================================== try: # approve_link = 'http://www.levr.com/admin/deal/{}/approve'.format(enc.encrypt_key(deal_entity.key())) base_url = 'http://www.levr.com/admin/deal/{}/expiration?daysToExpire='.format( enc.encrypt_key(deal_entity.key())) today_only_link = base_url + '0' one_week_link = base_url + '7' one_month_link = base_url + '30' three_month_link = base_url + '90' six_month_link = base_url + '180' one_year_link = base_url + '360' never_link = base_url + '-1' reject_link = 'http://www.levr.com/admin/deal/{}/reject'.format( enc.encrypt_key(deal_entity.key())) message = mail.AdminEmailMessage() message.sender = '*****@*****.**' message.subject = 'New Upload' message.html = '<img src="{}"><br>'.format( deal.get('smallImg')) message.html += '<h2>{}</h2>'.format(deal_entity.deal_text) message.html += '<h3>{}</h3>'.format(deal_entity.description) message.html += '<h4>Uploaded by: {}</h4>'.format( user.display_name) message.html += '<h5>deal_status: {}</h5>'.format( deal_entity.deal_status) message.html += '<br/><p>Set deal expiration.</p>' message.html += '<br><a href="{}">Reject</a><br><br>'.format( reject_link) message.html += '<br><a href="{}">Today Only</a><br><br>'.format( today_only_link) message.html += '<br><a href="{}">One Week</a><br><br>'.format( one_week_link) message.html += '<br><a href="{}">One Month</a><br><br>'.format( one_month_link) message.html += '<br><a href="{}">Three Month</a><br><br>'.format( three_month_link) message.html += '<br><a href="{}">Six Month</a><br><br>'.format( six_month_link) message.html += '<br><a href="{}">One Year</a><br><br>'.format( one_year_link) message.html += '<br><a href="{}">Forever!!!</a><br><br>'.format( never_link) message.html += levr.log_dict(deal, None, '<br>') # message.body += '\n\n\n\n\n\nApprove: {}'.format(approve_link) message.check_initialized() message.send() except: levr.log_error() api_utils.send_response(self, response) except KeyError, e: logging.info('Key Error') logging.info(str(e)) levr.log_error() api_utils.send_error(self, str(e))