#!/usr/bin/env python
# coding=utf-8

import hashlib
import os

from webapp.web import BaseHandler
from model import dbapi


class UserHandler(BaseHandler):

    def check(self):
        email = self.get_secure_cookie("email")
        user = dbapi.User()
        if email and user.get_user(email) == 0:
            profile = user.get_user_all(email)
            if profile:
                self.time = profile[4]
                self.email = email
        else:
            self.clear_cookies()
            self.redirect("/")

    def get(self):
        self.check()

        m = hashlib.md5()
        m.update(self.email)
        email_md5 = m.hexdigest()
        fn = "images/" + email_md5
        if os.path.isfile(fn):
            imagetag =  """<img src="%s" height="400"  class="rounded" alt="Upload Image Below">""" % fn
        else:
            imagetag = """<p class="text-warning">Avatar Not Available. Upload One!</p>""" + \
                """<img src="static/default.jpg" height="400"  class="rounded" alt="Upload Image Below">"""
        params = {'name': self.email, 'time': self.time, 'image': imagetag}
        body = self.wrap_html('templates/user.html', params)
        self.write(body)

@@ -55,16 +55,32 @@
 mport os
+%0Aimport datetime
 %0A%0Afrom w
@@ -421,16 +421,23 @@
 ofile%5B4%5D
+.date()
 %0A       

change datetime