#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = 'Jiayi Li'

import time, hashlib

from flask import current_app

from app import db

class User(object):
    
    def __init__(self, **kw):
        self.name = kw.get('name')
        self.email = kw.get('email')
        self.password = kw.get('password')
        self.created = kw.get('created', int(time.time()))
        self.admin = kw.get('admin', False)
        self.image = kw.get('image', '/static/img/default.png')
        self.register()
    
    def register(self):
        sha1_password = self.password + self.email + 'the-Salt'
        self.password = hashlib.sha1(sha1_password.encode('utf-8')).hexdigest()
        db.users.insert_one(self.__dict__)
        
class Blog(object):
    
    def __init__(self, **kw):
        pass
    
class Comment(object):
    
    def __init__(self, **kw):
        pass
@@ -592,17 +592,40 @@
 he-Salt'
+ # secondary encryption
 %0A
-
         
@@ -739,24 +739,17 @@
 dict__)%0A
-        
+%0A
 %0Aclass B
@@ -808,17 +808,472 @@
     
-pass%0A    
+self.user_id = kw.get('user_id')%0A        self.user_name = kw.get('user_name')%0A        self.user_image = kw.get('user_image')%0A        self.title = kw.get('title')%0A        self.tag = kw.get('tag', %5B%5D)%0A        self.content = kw.get('content')%0A        self.summary = '%25s%25s' %25 (kw.get('content', '')%5B:140%5D, '...')%0A        self.created = kw.get('created', int(time.time()))%0A        self.lastModified = False%0A        db.blogs.insert_one(self.__dict__) # save to mongodb%0A%0A
 %0Acla

add Blog class