Beispiel #1
0
 def post(self):
     username    = self.get_argument('username' , None) 
     passwd      = self.get_argument('passwd' , None)
     
     if username and passwd:
         #转码gb2312后md5 . 中文通用
         md5pass = hashlib.md5(passwd.encode(encoding="gb2312"))
         passwd  = md5pass.hexdigest() 
         db = database()
         if db!=None:
             cursor = db.cursor()
             cursor.execute("SELECT id,username,passwd FROM users WHERE username = %(username)s"  ,{"username":username} )
             row  = cursor.fetchone()
             if row != None and row[1] == passwd:
                 self.set_secure_cookie("user" , username)
                 self.redirect("/")
             elif(row == None):
                 self.form_error("username" , '用户名不能为空!')
             elif(row[1] != passwd ):
                 print( "%s :: %s " % (row[1] , passwd))
                 self.form_error("passwd" , '密码不正确')
         db.close()
     elif username == None:
         self.form_error('username' , '登陆名不能为空')
     elif passwd == None:
         self.form_error('passwd' , '密码不能为空')
     self.write(json.dumps(self._form_error)) 
Beispiel #2
0
 def get(self):
     db = database()
     cursor = db.cursor()
     cursor.execute("SELECT id,title,content FROM blog_content WHERE is_del=0 ORDER BY create_time DESC")
     rows = cursor.fetchall()
     cursor.close()
     db.close()
     self.render("edit_index.html"  , rows = rows)
Beispiel #3
0
 def delete(self):
     id      = self.get_argument("id" , None)
     sql     = "UPDATE  blog_content SET is_del=1 WHERE id=%(id)s"
     db      = database()
     cursor  = db.cursor()
     cursor.execute(sql,{'id':id})
     cursor.close()
     db.close()
     self.write(1)
Beispiel #4
0
 def post(self):
     title   = self.get_argument('title' , None)
     content = self.get_argument('content' , None)
     if title and content:
         db          = database()
         cursor      = db.cursor()
         insert_sql  =    ("INSERT INTO blog_content "
                         "(id,user_id , cate_id , title , content ,create_time,tags)"
                         "VALUES "
                         "(NULL,%(user_id)s , %(cate_id)s ,%(title)s , %(content)s , %(times)s , %(tags)s)")
         data        = {
                 'user_id':1,
                 'cate_id':1,
                 'title':title,
                 'content':content,
                 'times':datetime.datetime.now(),
                 'tags':'',
                 }
         cursor.execute(insert_sql,data)
         cursor.close()
         db.close()
         self.redirect("/blog_edit?t=%s" % (time.time(),) ,permanent=True)