Beispiel #1
0
def response():
    entity = db.get(cgi_get("key"))
    if entity.polytype == "document":
        entity.pdf = build(entity)
        entity.put()
        succeed(entity.data())
    else:  # build fragment
        succeed(export(entity))
Beispiel #2
0
def get():
    token = ''
    username = request.json.get('username')
    password1 = request.json.get('password')
    get_student = db.get('student', username)
    if get_student is not None:
        password2 = get_student['student_password']
        if bcrypt.check_password_hash(password2, password1):
            token = create_access_token(identity=username)
    return jsonify({'token': token})
Beispiel #3
0
def response():
	action = cgi_get("action")
	vid = db.get(cgi_get("v")).video
	if not vid: # no vid to process
		succeed()
	vpath = vid.urlsafe()[1:]
	if action == "hls":
		succeed(hlsify(vpath, check=cgi_get("check", default=False)))
	elif action == "mp4":
		transcode(vpath, slow=True)
Beispiel #4
0
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()
Beispiel #5
0
def response():
	if config.memcache.db:
		clearmem()
	action = cgi_get("action", choices=["post", "videopost", "comment", "photo", "photoset", "md"])
	if action == "md":
		for dn, dz, fz in os.walk("md"):
			succeed([f[:-3] for f in fz])
	user = cgi_get("user")
	if action == "comment":
		ent = Comment(user=user, post=cgi_get("post"), body=cgi_get("body"))
	elif action == "photo":
		pkey = cgi_get("key", required=False)
		if pkey:
			ent = Photo.query(Photo.key == pkey).get()
		else:
			ent = Photo()
		capt = cgi_get("caption", required=False) # imgs uploaded separately
		if capt:
			ent.caption = capt
	else:
		blurb = cgi_get("blurb", required=False)
		pkey = cgi_get("key", required=False)
		tags = cgi_get("tags", required=False)
		pmod = db.get_model(action)
		if pkey:
			ent = pmod.query(pmod.key == pkey).get()
		else:
			ent = pmod(user=user)
		ent.title = cgi_get("title")
		ent.live = cgi_get("live")
		if blurb:
			ent.blurb = blurb
		if tags:
			ent.tags = tags
		if action == "post":
			ent.body = cgi_get("body")
	ent.put()
	if action == "photo": # get photoset
		psk = cgi_get("photoset", required=False)
		if psk:
			ps = db.get(psk) # these are hacky -- fix list ops in ct
			if cgi_get("remove", default=False):
#				ps.photos.remove(ent.key)
				ps.photos = [p for p in ps.photos if p != ent.key]
			else:
#				ps.photos.append(ent.key)
				ps.photos = ps.photos + [ent.key]
			ps.put()
	succeed(ent.id())
Beispiel #6
0
def response():
    action = cgi_get("action", choices=["edit", "style"])
    data = cgi_get("data", required=False)
    if action == "style":
        style = Style.query().get()
        if not style:
            style = Style()
            style.put()  # for key
        if data:
            for key, val in list(data.items()):
                setattr(style, key, val)
            style.put()
        succeed(style.data())
    if "key" in data:
        entity = db.get(data["key"])
    else:
        entity = PageEdit(**data)
    entity.content = data["content"]
    entity.put()
    succeed(entity.key.urlsafe())
Beispiel #7
0
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)
Beispiel #8
0
def cont(content, agent):
    return isinstance(content, string_types) and db.get(content) or hoc(
        content, agent)
Beispiel #9
0
 def test_modify(self, key):
     result = db.get(key)
     print "modifying "+result.cubmail+" with picture "
     result.picture = db.Blob(open("model/test.png","rb").read())
     db.put(result)
Beispiel #10
0
 def test_oked(self, key):
     print "testing ok with key "+str(key)
     result = db.get(key);
     result.registered = 2;
Beispiel #11
0
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"),))