Ejemplo n.º 1
0
 def inviteusers_POST(self):
     """
     admin is sending out a number of invites to users
     """
     if 'emails' in request.POST:
         emails = request.POST['emails']
         delay = 4
         from demisauce.lib import scheduler
         for email in emails.split(','):
             email = email.strip().lower()
             user = Person.by_email(c.user.site_id,email)
             
             if user is None:
                 user = Person(site_id=c.site_id,email=email, displayname=email)
                 user.save()
                 #send emails
                 url2 = urllib.quote_plus('/account/viewh/%s' % (user.hashedemail))
                 dnew = {}
                 dnew['link'] = '%s/account/verify?unique=%s&node=%s&return_url=%s' %\
                     (base_url(),user.user_uniqueid,user.id,url2)
                 dnew['from'] = c.user.displayname
                 a = Activity(site_id=user.site_id,person_id=user.id,activity='sending email invite')
                 a.ref_url = 'account admin invite'
                 a.category = 'account'
                 a.save()
                 scheduler.add_interval_task(send_emails,0,('invitation_to_demisauce',[user.email],dnew) , initialdelay=delay)
                 delay += 3
             
         return 'from form %s' % emails
     return 'error'
Ejemplo n.º 2
0
 def enablesite(self,id=0):
     if not c.user.issysadmin:
         # Get Out Of Here
         return redirect_to(h.url_for(controller='home',action='index'))
         
     if 'siteid' in request.params and c.user and c.user.issysadmin:
         site = meta.DBSession.query(Site).get(request.params['siteid'])
         if site:
             site.enabled = True
             site.save()
             
             #TODO:  refactor out email send, do event observer type
             # now send email to user to create pwd etc
             user = meta.DBSession.query(Person).filter_by(email=site.email).first()
             if user:
                 url2 = urllib.quote_plus('/account/viewh/%s' % (user.hashedemail))
                 delay = 4
                 from demisauce.lib import scheduler
                 dnew = {}
                 dnew['link'] = '%s/account/site_signup?invitecode=%s&return_url=%s' %\
                     (base_url(),user.user_uniqueid,url2)
                 dnew['displayname'] = user.displayname
                 dnew['email'] = user.email
                 dnew['title'] = 'welcome'
                 scheduler.add_interval_task(send_emails,0,('welcome_to_demisauce',[user.email],dnew) , initialdelay=delay)
             
             return 'Enabled Site'
         
     return 'whoops, that didn\'t work'
Ejemplo n.º 3
0
 def interest(self):
     """
     User has selected to enter an email to be on waitinglist
     """
     if 'email' in request.POST:
         user = meta.DBSession.query(Person).filter_by(
                 email=request.POST['email'].lower()).first()
         
         if user is None:
             site = Site(name=self.form_result['email'],email=self.form_result['email'])
             site.save()
             user = Person(site_id=site.id,email=self.form_result['email'],
                           displayname=self.form_result['email'])
             user.slug = user.hashedemail
             user.save()
             a = Activity(site_id=user.site_id,person_id=user.id,activity='Signup Interest Form')
             #a.ref_url = 'comment url'
             a.category = 'account'
             a.save()
             #TODO:  refactor/extract email send to trigger event api
             #send emails
             url2 = urllib.quote_plus('/account/viewh/%s' % (user.hashedemail))
             delay = 4
             from demisauce.lib import scheduler
             dnew = {}
             dnew['link'] = '%s/account/verify?unique=%s&node=%s&return_url=%s' %\
                 (c.base_url,user.user_uniqueid,user.id,url2)
             dnew['displayname'] = user.displayname
             dnew['email'] = user.email
             dnew['title'] = 'welcome'
             scheduler.add_interval_task(send_emails,0,('thank_you_for_registering_with_demisauce',
                 [user.email],dnew) , initialdelay=delay)
             if 'demisauce.admin' in config:
                 scheduler.add_interval_task(send_emails,0,('a-new-user-has-registered',
                     [config['demisauce.admin']],dnew) , initialdelay=8)
         
         h.add_alert("Thank You!")
         return redirect_wsave(controller='home',action='index')
     
     else:
         h.add_error("You need to enter an email.")
     
     return render('/account/signup.html')
Ejemplo n.º 4
0
    def commentsubmitjsonp(self, id=""):
        site = Site.by_slug(str(id))
        if site:
            c.site = site
            item = Comment(site_id=site.id)
            if c.user:
                item.set_user_info(c.user)
                a = activity.Activity(site_id=c.user.site_id, person_id=c.user.id, activity="Commenting")
                # a.ref_url = 'comment url'
                a.category = "comment"
                a.save()
            else:
                if "authorname" in request.params:
                    item.authorname = sanitize(request.params["authorname"])
                if "blog" in request.params:
                    item.blog = sanitize(request.params["blog"])
                if "email" in request.params:
                    item.set_email(sanitize(request.params["email"]))
                if item.blog == "your blog url":
                    item.blog = ""

            # prod environment proxy: apache
            if "HTTP_X_FORWARDED_FOR" in request.environ:
                item.ip = request.environ["HTTP_X_FORWARDED_FOR"]
            elif "REMOTE_ADDR" in request.environ:
                item.ip = request.environ["REMOTE_ADDR"]

            if "comment" in request.params:
                item.comment = sanitize(request.params["comment"])
            if "type" in request.params:
                item.type = sanitize(request.params["type"])
            else:
                item.type = "blogentry"

            if "rid" in request.params:
                item.uri = urllib.unquote_plus(request.params["rid"].lower())

            item.save()

            # send emails
            from demisauce.lib import scheduler

            dnew = {
                "sitename": c.site.name,
                "displayname": item.authorname,
                "email": item.email,
                "url": "dest",
                "blog": item.blog,
            }
            scheduler.add_interval_task(send_emails, 0, ("comment-notification", [c.site.email], dnew), initialdelay=4)

            if "jsoncallback" in request.params:
                c.items = [item]
                data = {"success": True, "html": render("/comment/comment_nobody.html")}
                json = simplejson.dumps(data)
                response.headers["Content-Type"] = "text/json"
                return "%s(%s)" % (request.params["jsoncallback"], json)
        else:
            # TODO panic?
            raise "eh"
            pass
        return
Ejemplo n.º 5
0
    def commentsubmit(self, id=""):
        site = Site.by_slug(str(id))
        if site:
            c.site = site
            item = Comment(site_id=site.id)
            if c.user:
                item.set_user_info(c.user)
                a = activity.Activity(site_id=c.user.site_id, person_id=c.user.id, activity="Commenting")
                # a.ref_url = 'comment url'
                a.category = "comment"
                a.save()
            else:
                item.authorname = sanitize(self.form_result["authorname"])
                item.blog = sanitize(self.form_result["blog"])
                if self.form_result.has_key("email"):
                    item.set_email(sanitize(self.form_result["email"]))
                if item.blog == "your blog url":
                    item.blog = ""
            # prod environment proxy: apache
            if "HTTP_X_FORWARDED_FOR" in request.environ:
                item.ip = request.environ["HTTP_X_FORWARDED_FOR"]
            elif "REMOTE_ADDR" in request.environ:
                item.ip = request.environ["REMOTE_ADDR"]

            item.comment = sanitize(self.form_result["comment"])
            if self.form_result.has_key("type"):
                item.type = sanitize(self.form_result["type"])
            else:
                item.type = "blogentry"

            if self.form_result.has_key("goto"):
                dest = self.form_result["goto"]
                item.uri = dest
            elif c.user:
                dest = c.user.url
            else:
                # TODO panic?
                return

            if "rid" in self.form_result:
                item.uri = self.form_result["rid"].lower()

            item.save()

            # send emails
            from demisauce.lib import scheduler

            dnew = {
                "sitename": c.site.name,
                "displayname": item.authorname,
                "email": item.email,
                "url": dest,
                "blog": item.blog,
            }
            scheduler.add_interval_task(send_emails, 0, ("comment-notification", [c.site.email], dnew), initialdelay=4)
            # TODO  '?#demisauce-comments'
            c.goto_url = dest
            c.resource_id = ""
            if "rid" in self.form_result:
                c.resource_id = self.form_result["rid"]
            source = "js"
            if "source" in self.form_result:
                source = self.form_result["source"]
            if "jsoncallback" in request.params:
                data = {"success": True, "html": item.comment}
                json = simplejson.dumps(data)
                response.headers["Content-Type"] = "text/json"
                return "%s(%s)" % (request.params["jsoncallback"], json)
            # if source == 'js':
            #    return render('/refresh.html')
            # else:
            c.items = [item]
            # c.show_form = False
            return render("/comment/comment_nobody.html")
        else:
            # TODO panic?
            raise "eh"
            pass
        return