def response(): today = datetime.now() tomorrow = today + timedelta(1) yesterday = today - timedelta(1) mems = Member.query().all() log("memscan! found %s members" % (len(mems), )) unregistered = [] expired = [] almost = [] for mem in mems: ex = mem.expiration if not ex: unregistered.append(mem) elif ex > yesterday: if ex < today: expired.append(mem) elif ex < tomorrow: almost.append(mem) log("%s unregistered" % (len(unregistered), )) log("%s expired" % (len(expired), )) log("%s almost exired" % (len(almost), )) for mem in expired: send_mail(to=mem.email, subject="your subscription", body=EMSG % ("just", )) for mem in almost: send_mail(to=mem.email, subject="your subscription", body=EMSG % ("almost", )) log("goodbye")
def remind(self): rpmail = self.person and self.person.get().email memship = self.membership.get() mpmail = memship.person.get().email pod = memship.pod.get() rkey = self.key.urlsafe() if self.change == "include": send_mail(to=rpmail, subject="pod membership nomination", body=APPLY % (mpmail, pod.name, rkey)) elif self.change == "exclude": self.notify( "pod membership exclusion proposal", lambda signer: EXCLUDE % (mpmail, rpmail, pod.name, rkey, signer.urlsafe())) elif self.change == "blurb": self.notify( "pod blurb update proposal", lambda signer: BLURB % (mpmail, pod.name, self.notes, rkey, signer.urlsafe())) elif self.change == "delivery": self.notify( "delivery request", lambda signer: DELIVERY % (mpmail, pod.name, self.notes, rkey, signer.urlsafe()), pod.drivers) else: # conversation / support self.notify( "%s request" % (self.change, ), lambda signer: CONVO % (mpmail, pod.name, self.notes, rkey, signer.urlsafe()))
def response(): log("initiating cronscan", important=True) az = Auction.query( Auction.settled == False, Auction.deadline <= datetime.now() ).all() log("found %s active auctions"%(len(az),)) for a in az: b = Bid.query( Bid.emailed == False, Bid.auction == a.key ).order("-amount").get() if b: u = b.user.get() log("emailing %s"%(u.email,), 1) cw = config.web send_mail( to = u.email, subject = "you won the auction!", body = CSB%("%s://%s:%s/_store?action=claim&bid=%s"%(cw.protocol, cw.host, cw.port, b.key.urlsafe()),) ) b.emailed = True b.put() log("cronscan succeeded -- goodbye!")
def oncreate(self): convo = Conversation(topic=self.subject) convo.put() self.conversation = convo.key if self.recipients: recipients = db.get_multi(self.recipients) else: recipients = Member.query().all() bod = UPDATE % (self.sender.get().email, self.message) for recip in recipients: send_mail(to=recip.email, subject=self.subject, body=bod)
def onsale(self, amount, errmsg=None): days = config.ctman.subs[amount] payment = Payment(member=self.key, amount=amount, duration=days) if errmsg: payment.message = errmsg return payment.put() payment.successful = True if not self.expiration: self.expiration = datetime.now() self.expiration += timedelta(days) db.put_multi([self, payment]) exp = str(self.expiration)[:19] send_mail(to=self.email, subject="your subscription", body="your subscription is good until %s" % (exp, )) email_admins( "new subscription", "\n".join([ "member: " + self.email, "amount: " + amount, "expires: " + exp ])) return exp
def response(): action = cgi_get("action") if action == "need": need = Need(**cgi_get("data")) need.put() succeed(need.data()) elif action == "offering": offering = Offering(**cgi_get("data")) offering.put() succeed(offering.data()) elif action == "close": need = db.get(cgi_get("need")) # need or offering.... need.closed = True need.put() elif action == "do": need = db.get(cgi_get("need")) # need or offering.... memkey = cgi_get("member", required=False) reminder = cgi_get("reminder", required=False) task = [need.description] if need.member: nmem = need.member.get() task.append("name: %s" % (nmem.firstName, )) task.append("email: %s" % (nmem.email, )) for item in ["name", "email", "phone", "address"]: val = getattr(need, item) if val: task.append("%s: %s" % (item, val)) task = "you agreed to do this:\n\n%s\n\nplease follow up!" % ( "\n\n".join(task), ) if reminder == "text message": send_sms(cgi_get("number"), "do this thing", task, cgi_get("carrier")) elif reminder == "email": send_mail(to=cgi_get("email"), subject="do this thing", body=task) elif reminder == "member": mem = db.get(memkey) send_mail(to=mem.email, subject="do this thing", body=task) mem.help_match(need) if not need.ongoing: need.closed = True need.put()
def invite(pw, emails, msg, template): import base64, json, time from urllib.parse import quote from cantools.web import getmem, send_mail from cantools import config show = getmem(pw, False) ts = "%s %s" % (show["ttl"].strftime("%A at %-I:%M%p"), time.tzname[time.daylight]) baseaddr = "%s://%s/stream/private.html#" % (config.web.protocol, config.web.domain) for email in emails: credz = quote( base64.b64encode( json.dumps({ "channel": show["token"], "user": email.split("@")[0] }).encode())) link = "%s%s" % (baseaddr, credz) body = msg and msg.format(link='<a href="%s">here</a>' % (link, ), password=pw, time=ts) or template["body"] % (ts, link, pw) send_mail(email, subject=template["subject"], body=body)
def fulfill(self): if self.passed or not self.verified(): return False payer = self.payer.get() memship = self.membership.get() recip = memship.person.get() pod = memship.pod.get() payer.wallet.get().debit(self.amount, pod, self, "payment to %s" % (recip.email, ), self.notes) memship.deposit(self.amount, self, "payment from %s" % (payer.email, ), self.notes, pay=True) self.passed = True self.put() body = PAID % (self.amount, payer.email, recip.email, pod.name, self.notes) for target in [payer, recip]: send_mail(to=target.email, subject="payment confirmation", body=body) return True
def response(): action = cgi_get("action", choices=["join", "activate", "login", "contact", "edit", "email"]) if action == "join": email = cgi_get("email") if CTUser.query(CTUser.email == email).get(): fail("this email is already in use") user_type = cgi_get("utype") u = db.get_model(user_type)(email=email, firstName=cgi_get("firstName"), lastName=cgi_get("lastName"), **cgi_get("extras")) u.put() # to generate created timestamp u.password = db.hashpass(cgi_get("password"), u.created) rule = config.ctuser.activation.get(user_type, config.ctuser.activation.ctuser) if rule == "auto": u.active = True else: # assumes config.mailer (otherwise, don't change activation "auto" default) usk = u.key.urlsafe() if rule == "confirm": send_mail(to=u.email, subject="activation required", body=JOIN%(usk,)) else: # email admin to handle it send_mail(to=rule, subject="activation required", body=JOINED%(email, usk)) u.put() succeed(u.data()) elif action == "activate": u = db.get(cgi_get("key")) if u and not u.active: # else, don't even trip u.active = True u.put() send_mail(to=u.email, subject="account activated", body=ACTIVATE) redirect("/", "you did it!") elif action == "login": u = CTUser.query(CTUser.email == cgi_get("email"), CTUser.active == True).get() if not u or u.password != db.hashpass(cgi_get("password"), u.created): fail() succeed(u.data()) elif action == "contact": sender = db.get(cgi_get("user")) message = cgi_get("message") convokey = cgi_get("conversation", required=False) if convokey: conversation = db.get(convokey) else: conversation = Conversation() conversation.topic = cgi_get("topic") conversation.participants = [sender.key, db.KeyWrapper(cgi_get("recipient"))] conversation.put() m = Message(sender=sender.key, conversation=conversation.key, body=message) m.put() for recipient in conversation.participants: if recipient != sender.key: send_mail(to=recipient.get().email, subject="message from %s"%(sender.firstName,), body=CONTACT%(sender.fullName(), message, sender.firstName, sender.key.urlsafe(), conversation.key.urlsafe())) succeed(convokey and m.key.urlsafe() or conversation.key.urlsafe()) elif action == "edit": changes = cgi_get("changes") changes["key"] = cgi_get("user") edit(changes) elif action == "email": sender = db.get(cgi_get("user")) if not sender.admin: fail() recips = cgi_get("recipients", default=[]) if not recips: if config.wpmail: log("no recipients specified -- WP mode enabled -- building recipient list...") recips = getWPmails() else: fail("no recipients specified -- can't email nobody") batch(recips, lambda chunk : send_mail(bcc=chunk, subject=cgi_get("subject"), body=cgi_get("body")), chunk=100)
def notify(self, subject, body): for signer in self.voters(): send_mail(to=signer.get().email, subject=subject, body=body(signer))
def invite(self): memship = self.membership.get() send_mail(to=self.email, subject="invitation", body=INVITATION % (memship.person.get().email, memship.pod.get().name))
def notify(self, item, etemp): bod = etemp % (self.name, item.description) for person in self.interested(item.tags): send_mail(to=person.email, subject="new %s" % (item.polytype, ), body=bod)
def unsteward(self, stewardship, verb="rescheduled"): # just a notifier send_mail(to=stewardship.steward.get().email, subject="commitment update", body=RESCHED % (self.name, verb))
def notify(self, subject, body, signers=None): for signer in (signers or self.signers()): if self.unverified(signer): send_mail(to=signer.get().email, subject=subject, body=body(signer))
def notify(self, podname, interested): bod = BOARD % (podname, self.name, self.description) for person in interested: send_mail(to=person.email, subject="new message board", body=bod)
def response(): action = cgi_get("action", choices=["view", "pay", "service", "commitment", "request", "invite", "expense", "verify", "unverify", "apply", "join", "pod", "membership", "person", "enroll", "manage", "confcode", "mint", "balance", "responsibilities"]) if action == "view": ip = local("response").ip user = cgi_get("user", required=False) # key if user: user = db.get(user) else: user = Person.query(Person.ip == ip).get() if not user: user = Person() user.ip = ip user.put() views(user) elif action == "mint": user = db.get(cgi_get("user")) amount = cgi_get("amount") user.wallet.get().mint(amount) elif action == "balance": user = db.get(cgi_get("user")) succeed(user.wallet.get().balance()) elif action == "pay": payer = db.get(cgi_get("payer")) memship = db.get(cgi_get("membership")) person = memship.person.get() pod = memship.pod.get() pment = Payment() pment.membership = memship.key pment.payer = payer.key pment.amount = cgi_get("amount") pment.notes = cgi_get("notes") if payer.key.urlsafe() == person.key.urlsafe(): fail("pay yourself?") if payer.wallet.get().outstanding < pment.amount: fail("you don't have enough in your account!") pment.put() pkey = pment.key.urlsafe() pment.notify("confirm payment", lambda signer : PAYMENT%(pment.amount, person.firstName, pod.name, pment.notes, pkey, signer.urlsafe())) succeed(pkey) elif action == "service": succeed(reg_act(cgi_get("membership"), cgi_get("service"), cgi_get("workers"), cgi_get("beneficiaries"), cgi_get("notes"))) elif action == "commitment": comm = Commitment() comm.membership = cgi_get("membership") comm.service = cgi_get("service") comm.estimate = cgi_get("estimate") comm.notes = cgi_get("notes") comm.put() comm.verify(comm.membership.get().person) # (submitter already agrees) ckey = comm.key.urlsafe() service = comm.service.get() memship = comm.membership.get() person = memship.person.get() pod = memship.pod.get() comm.notify("affirm commitment", lambda signer : COMMITMENT%(person.email, pod.name, comm.estimate, service.name, comm.notes, ckey, signer.urlsafe())) succeed(ckey) elif action == "request": req = Request() req.membership = cgi_get("membership") req.change = cgi_get("change") req.person = cgi_get("person", required=False) req.notes = cgi_get("notes") req.put() req.remind() succeed(req.key.urlsafe()) elif action == "invite": inv = Invitation() inv.membership = cgi_get("membership") inv.email = cgi_get("email").lower() inv.notes = cgi_get("notes") inv.put() inv.invite() elif action == "expense": exp = Expense() exp.membership = cgi_get("membership") exp.executor = cgi_get("executor", required=False) exp.variety = cgi_get("variety", choices=["dividend", "reimbursement"]) exp.amount = cgi_get("amount") exp.recurring = cgi_get("recurring") exp.notes = cgi_get("notes") exp.put() memship = exp.membership.get() mpmail = memship.person.get().email pod = memship.pod.get() variety = exp.variety amount = exp.amount if exp.executor: variety = "%s - executor: %s"%(variety, exp.executor.get().email) else: amount = "%s%%"%(amount * 100,) exp.notify("approve expense", lambda signer: EXPENSE%(mpmail, pod.name, variety, amount, exp.recurring, exp.notes, signer.urlsafe())) succeed(exp.key.urlsafe()) elif action == "verify": verifiable = db.get(cgi_get("verifiable")) # act/request/commitment/expense/appointment verifiable.verify(db.KeyWrapper(cgi_get("person"))) redirect("/comp/pods.html", "you did it!") elif action == "unverify": # commitment only!!!!??! vkey = cgi_get("verifiable") verifiable = db.get(vkey) verifiable.unverify() service = verifiable.service.get() memship = verifiable.membership.get() person = memship.person.get() pod = memship.pod.get() for signer in pod.members(): send_mail(to=signer.get().email, subject="affirm commitment - estimate adjustment", body=COMMITMENT%(person.email, pod.name, verifiable.estimate, service.name, vkey, signer.urlsafe())) elif action == "apply": db.get(cgi_get("request")).apply() redirect("/comp/pods.html", "you did it!") elif action == "join": # support only pod = db.get(cgi_get("pod")) if pod.variety != "support": fail() person = db.get(cgi_get("person")) succeed(person.enroll(pod).urlsafe()) elif action == "pod": pod = db.get(cgi_get("pod")) succeed({ "services": [a.data() for a in pod.acts()], "requests": [r.data() for r in pod.requests()], "proposals": [p.data() for p in db.get_multi(pod.proposals())], "commitments": [c.data() for c in pod.commitments()], "memberships": [m.data() for m in pod.members(True)], "people": [p.data() for p in db.get_multi(pod.members())], "codebases": [c.data() for c in pod.codebases()], "expenses": [e.data() for e in pod.expenses()] }) elif action == "membership": memship = db.get(cgi_get("membership")) succeed({ "content": [c.data() for c in Content.query(Content.membership == memship.key).fetch()], "products": [p.data() for p in db.get_multi(memship.products)] }) elif action == "person": person = db.get(cgi_get("person")) succeed({ "services": len(person.acts()), # more efficient way? "memberships": [m.data() for m in person.memberships()], "commitments": sum([c.estimate for c in person.commitments()]) }) elif action == "responsibilities": person = db.get(cgi_get("person")) succeed([t.data() for t in person.tasks()]) elif action == "enroll": succeed(enroll(cgi_get("agent"), cgi_get("pod"), cgi_get("person")).urlsafe()) elif action == "manage": succeed(manage(cgi_get("agent"), cgi_get("membership"), cgi_get("content")).key.urlsafe()) elif action == "confcode": send_mail(to=cgi_get("email"), subject="carecoin confirmation code", body=CONFCODE%(cgi_get("code"),))