def acceptedTerms(webin): pcn = json.loads(webin.content()) vprint("acceptedTerms", pcn) utopic = pcn["user"] email = pcn["email"] user = models.loadUserD(utopic, webin.pageStore) if user == None: return failResponse("noSuchUser") rss = None if email: vcode = models.genId("register") user.validation_code = vcode user.validated = 0 user.email = email vprint("sending validating email to ", email) rss = ses.sendValidationEmail(user, True) user.accepted_terms = 1 user.dynsave(False) s = user.newSession() stp = s.topic sid = misc.pathLast(stp) rs = {"sessionId": sid} if not rss: vprint("emailFailed") rs["emailFailed"] = 1 return okResponse(rs)
def sendForgotPasswordEmail(user): tp = user.topic uid = misc.pathLast(tp) code = user.validation_code msg = """<p>To reset your password at ImageDiver, please click on the link below, or paste it into your browser's address bar:</p> <p>http://imagediver.org/reset_password?user={0}&code={1}""".format( uid, code) subject = "Reset Password" return sendEmail(user, subject, msg)
def externalize(self): snap = self.__dict__.copy() snap["type"] = "/type/Snap" misc.removeProp(snap,"shares_coverage") misc.removeProp(snap,"current_item_create_time") ord = snap["ordinal"] snap["coverage"] = misc.reduceRectDigits(snap["coverage"]) if ord < 0: id = int(misc.pathLast(snap["topic"])) snap["ordinal"] = id return snap
def sendValidationEmail(user, forTumblrOrTwitter=False): tp = user.topic uid = misc.pathLast(tp) code = user.validation_code if forTumblrOrTwitter: msg = """<p>To verify this email address for ImageDiver, please click on the link below, or paste it into your browser's address bar:</p>""" else: msg = """<p>To complete your registration at ImageDiver, please click on the link below, or paste it into your browser's address bar:</p>""" url = "http://imagediver.org/verify_email?user={0}&code={1}".format( uid, code) msg += """<p><a href="{0}">{0}</a>""".format(url) subject = "Email Verification for ImageDiver" return sendEmail(user, subject, msg)
def authorizeTumblr(user,topic): tk = oauth_tumblr.requestToken() if topic: tk["topic"] = topic tkj = json.dumps(tk) #print "TKJ",tkj " the token needs to be saved for a few minutes: until the user authorizes or declines the app " dir = "/mnt/ebs1/imagediver/tokens/" uname = misc.pathLast(user) fln = dir+uname f = open(fln,'w') f.write(tkj) f.close() return tk #localStorage.tumblrToken = tkj tktk = tk["oauth_token"] url = 'http://tumblr.com/oauth/authorize?oauth_token='+str(tktk) return url
def drawRect(self): area = 250000 cv = self.coverage cvr = image.dictToRect(cv) alb = self.album tpo = misc.topicOb(alb) imt = tpo.imageTopic() im = image.loadImageD(imt) dm = im.dimensions # determine scaling to the 250000 area ua = dm["x"] * dm["y"] ssq = ua/float(area) sc = math.sqrt(ssq) isc = 1/sc wx = isc * dm["x"] # width of the 250000 area rect = cvr.scale(wx) tp = self.topic snapnum = int(misc.pathLast(tp)) im.drawRect(snapnum,rect,area) return im
def updateUser(webin): Logr.log("test", "TEST CONSTANT " + str(getattr(constants, "testvar", None))) pcn = json.loads(webin.content()) uname = pcn["userId"] vprint("uname", uname) cks = webin.checkSessionResponse() if cks: return cks session = webin.session suserId = misc.pathLast(session.user) if suserId != uname: return failResponse("wrongUser") pw = pcn.get("password", None) name = pcn["name"] email = pcn["email"].strip() u = models.loadUserD("/user/" + uname, webin.pageStore) if u == None: return failResponse() oldemail = getattr(u, "email", "") if email and (oldemail != email): eu = dynamo.emailToUser(pcn["email"]) if eu != None: return failResponse("emailInUse") nu = models.UserD(None) nu.topic = '/user/' + uname nu.name = name if pw: nu.setPassword(pw) nu.email = email vprint("old email", oldemail, "new ", email) if (oldemail != email): rs = ses.sendEmailChangedEmail(nu) if rs: nu.dynsave(False) if oldemail: dynamo.deleteEmailToUserEntry(oldemail) return okResponse() else: return failResponse("Unable to send email to " + email) nu.dynsave(False) return okResponse()
def setTumblrToken(webin): cn = webin.content() #print "CONTENT",cn cob = json.loads(cn) token = cob["oauth_token"] token_secret = cob["oauth_token_secret"] verifier = cob["verifier"] signingIn = cob.get("signingIn", False) if not signingIn: cks = webin.checkSessionResponse() if cks: return cks access_token = oauth_tumblr.getAccessToken(verifier, token, token_secret) #print "ACCESS TOKEN ",access_token atkj = json.dumps(access_token) if signingIn: uinfj = oauth_tumblr.getUserInfo(access_token["oauth_token"], access_token["oauth_token_secret"]) #print "UINFJ",uinfj uinf = json.loads(uinfj) tuname = uinf["response"]['user']['name'] vprint("TUNAME", tuname) exu = models.loadUserDbyTumblr(tuname) rs = {"tumblr_name": tuname} if exu: vprint("Existing tumblr user") exu.tumblr_token = atkj exu.dynsave(False) tac = getattr(exu, "accepted_terms", 0) #tac = 1 rs["accepted_terms"] = tac utp = exu.topic uid = misc.pathLast(utp) rs["userId"] = uid if tac: # go ahead and generate a new session for this fellow s = exu.newSession() stp = s.topic sid = misc.pathLast(stp) rs["sessionId"] = sid return okResponse(rs) else: vprint("NEW TUMBLR USER") ucnt = dynamo.getCount("/user/count") if ucnt >= constants.maxUsers: rs["hit_limit"] = 1 return okResponse(rs) uid = dynamo.genNewUserId() nu = models.UserD(None) nu.topic = '/user/' + uid nu.name = tuname nu.tumblr_name = tuname nu.storage_allocation = constants.initial_storage_allocation nu.bandwidth_allocation = constants.initial_bandwidth_allocation nu.accepted_terms = 0 nu.tumblr_token = atkj nu.dynsave(True) dynamo.bumpCount("/user/count") vprint("NEW TUMBLR USER SAVED") rs["accepted_terms"] = 0 rs["userId"] = uid return okResponse(rs) """ getting a access token in the course of a post to tumblr """ sess = webin.session user = sess.user userD = models.loadUserD(user) atkj = json.dumps(access_token) userD.tumblr_token = atkj userD.dynsave(False) return okResponse()
def tumblrPost1(user, params): cob = params userD = models.loadUserD(user) uid = misc.pathLast(user) ttk = getattr(userD, 'tumblr_token', None) if not ttk: return failResponse("noToken") tko = json.loads(ttk) token = tko["oauth_token"] token_secret = tko["oauth_token_secret"] vprint("Token", token) vprint("Token_secret", token_secret) topic = cob["topic"] blog = cob["blog"] imageSource = cob["imageSource"] linkTo = cob["linkTo"] tags = cob["tags"] caption = cob["caption"].encode("utf_8", "ignore") """ topicsp = topic.split("/") kind = topicsp[1] # snap or album ownr = topicsp[2] ownerName = None if ownr != uid: ownru = models.loadUserD("/user/"+ownr) ownerName = ownru.name imname = topicsp[3] albumNum = topicsp[4] imageTitle = cob["imageTitle"] imageAuthor = cob["imageAuthor"] imageSource = cob["imageSource"] linkTo = cob["linkTo"] if kind=="snap": snap = cob["snap"] #print "snap",snap #cropId = snap["cropid"] #snapId = misc.pathLast(topic) scaption = snap.get("caption",None) sdes = snap.get("description",None) caption = "Click on the image to see the detail in a zoomable context\n\nDetail" tags = [] if imageTitle: caption += " from *"+imageTitle+"*" if imageTitle.find(",") < 0: tags.append(imageTitle) if imageAuthor: caption += ", "+imageAuthor if imageAuthor.find(",") < 0: tags.append(imageAuthor) caption += "\n\n" if scaption: caption += scaption if sdes: if scaption: caption += "\n\n" caption += sdes.decode("utf8","ignore") if ownerName: caption += "\n\n From "+ownerName+" at [Imagediver](http://imagediver.org)" #http://static.imagediver.org/images/4294b0e/van_eyck_arnolfini/snap/12.jpg?album=4294b0e.1 #http://s3.imagediver.org/topic/album/4294b0e/van_eyck_arnolfini/1/index.html#snap=9 cropUrl = "http://static.imagediver.org/images/"+ownr+"/"+imname+"/snap/"+str(cropId)+".jpg" clickThru = "http://s3.imagediver.org/topic/album/"+ownr+"/"+imname+"/"+albumNum+"/index.html#snap="+str(snapId) """ params = { "type": "photo", "format": "markdown", "state": "draft", "link": linkTo, "source": imageSource } if caption: params["caption"] = caption if len(tags) > 0: params["tags"] = ",".join(tags) #params = {"type":"text","state":"draft","body":"Second TEST post"} #print "DESC",sdes #vprint("CAPTION",caption) #print "params",params try: oauth_tumblr.post(token, token_secret, blog, params) except Exception as ex: vprint("FAILED TO POST", ex) return False vprint("post complete") return True