Ejemplo n.º 1
0
    def get(self):
        user_id = self.request.cookies.get('user_id')
        user_username = check_secure_val(user_id)
        if (user_username):
            self.response.out.write("Welcome, %s!" % user_username)
        else:
            self.redirect("/blog/signup")


###########################################################################################
Ejemplo n.º 2
0
 def render_secure(self, template, **kwargs):
     hashed_username = self.request.cookies.get('username')
     if hashed_username:
         username = hashing.check_secure_val(hashed_username)
         if username:
             kwargs['username'] = username
             self.write(self.render_str(template, **kwargs))
         else:
             self.redirect("/login")
     else:
         self.redirect("/login")
Ejemplo n.º 3
0
	def get(self):
		user_cookie = self.request.cookies.get('name')
		try:
			user_id = int(self.request.cookies.get('user_id'))
			entity = Users.get_by_id(user_id)
			valid_hash = hashing.check_secure_val(user_cookie, entity.username)
			if valid_hash:
				self.render("welcome.html", user = entity.username)
			else:
				self.redirect('/blog/signup')
		except :
			self.redirect('/blog/signup')
Ejemplo n.º 4
0
 def get(self):
     user_cookie = self.request.cookies.get('name')
     try:
         user_id = int(self.request.cookies.get('user_id'))
         entity = Users.get_by_id(user_id)
         valid_hash = hashing.check_secure_val(user_cookie, entity.username)
         if valid_hash:
             self.render("welcome.html", user=entity.username)
         else:
             self.redirect('/blog/signup')
     except:
         self.redirect('/blog/signup')
Ejemplo n.º 5
0
    def get(self, page):
        wiki_entries = getWikiEntries(page)
        user_id = self.request.cookies.get('user_id')
        username = check_secure_val(user_id)
        if len(wiki_entries) > 0:
            self.render("wiki_history.html",
                        wiki_entries=wiki_entries,
                        page=page,
                        username=username)
        else:
            self.redirect("/wiki/_edit%s" % page)


###########################################################################################
Ejemplo n.º 6
0
	def get(self, page):
		wiki_entry = getWikiEntry(page)
		content = ""
		if wiki_entry:
			content = wiki_entry.content
		user_id = self.request.cookies.get('user_id')
		username = check_secure_val(user_id)
		if username:
			self.write_form(error="", content=content, username=username)
		else:
			if (wiki_entry):
				self.redirect("/wiki%s" % page)
			else:
				self.redirect("/wiki/")
Ejemplo n.º 7
0
    def get(self, page):
        wiki_entry = getWikiEntry(page)
        user_id = self.request.cookies.get('user_id')
        username = check_secure_val(user_id)
        if wiki_entry:
            content = wiki_entry.content
            self.render("wiki_page.html",
                        content=content,
                        page=page,
                        username=username)
        else:
            self.redirect("/wiki/_edit%s" % page)


###########################################################################################
Ejemplo n.º 8
0
 def get(self):
     hashed_username = self.request.cookies.get('username')
     if hashed_username:
         username = hashing.check_secure_val(hashed_username)
         if username:
             page = Page.get_or_insert("/welcome", pagename="/welcome")
             if page.content is None:
                 page.content = ""
             self.response.headers['Content-Type'] = 'text/html'
             self.render_secure("welcome.html",
                         username=username,
                         page=page)
         else:
             self.redirect("/login")
     else:
         self.redirect("/login")
Ejemplo n.º 9
0
    def register(self, code, chat_id):
        user_id = check_secure_val(code)
        if not user_id:
            logging.info("register failed because code is not right")
            return False
        user = User.query.filter_by(user_id=user_id).first()
        if not user:
            logging.info("register failed because user is not right")
            return False
        if not user.chat_id or not user.previous:
            logging.info("initializing user: setting chat id and previous")
            user.chat_id = chat_id
            credentials = client.OAuth2Credentials.from_json(user.credentials)
            http = credentials.authorize(httplib2.Http())
            if credentials.access_token_expired:
                logging.info("credentials for %s has expired, refreshing",
                             u.email)
                credentials.refresh(http)
                user.credentials = credentials.to_json()
                db.session.commit()
                logging.info("successful refresh")
            service = discovery.build('gmail', 'v1', http=http)
            l = ListMessagesWithLabels(service, user.email, maxResults=1)
            mails = []
            for m in l:
                message = GetMessage(service, user.email, m['id'])
                msg_time = int(message['internalDate']) / 1000
                user.previous = msg_time
                mail = Mail()
                mail.snippet = message['snippet']
                mail.internal_time = datetime.datetime.utcfromtimestamp(
                    msg_time)
                for x in message['payload']['headers']:
                    if x['name'] == 'Subject':
                        mail.subject = x['value']
                    #elif x['name'] == 'Date':
                    #   mail.date = x['value']
                    elif x['name'] == 'From':
                        mail.from_ = x['value']
                self.bot.sendMessage(chat_id, createMessageFromMail(mail))

                #print 'previous id email', user.previous
            db.session.commit()
            logging.info("successful register of %s", user.email)
            return True
Ejemplo n.º 10
0
    def get(self):
        self.response.headers["Content-Type"] = 'text/plain'
        visits = 0
        visit_cookie_str = self.request.cookies.get("visits")

        if visit_cookie_str:
            cookie_val = hashing.check_secure_val(visit_cookie_str)
            if cookie_val:
                visits = int(cookie_val)


        visits += 1

        new_cookie_val = hashing.make_secure_val(str(visits))

        self.response.headers.add_header("Set-Cookie", 'visits=%s' % new_cookie_val)

        if visits > 20:
            self.write("You are the best ever")
        else:
            self.write("You've been here %s times!" % visits)
Ejemplo n.º 11
0
 def get(self):
     if self.request.cookies.get('username', '') == '':
         self.redirect('/signup')
     username = check_secure_val(str(self.request.cookies.get('username')))
     self.write('Welcome, %s!' %username)
     self.write('<br><a href="/">Return Home</a>')
Ejemplo n.º 12
0
 def test_check_secure_val(self):
     h = "test|cea6b92de1c15cfdbcf333982d340d3f"
     assert check_secure_val(h) == "test"
Ejemplo n.º 13
0
 def get(self):
     user_id = self.request.cookies.get('user_id')
     user_username = check_secure_val(user_id)
     self.response.out.write("Welcome, %s!" % user_username)