# Path: config/setting.py

# 
# Path: util/login.py
# def login(userid):
#     # 1. sha1(salt+ip+userid+now)
#     now=str(datetime.now())
#     userid=str(userid)
#     hash=sha1(salt+userid+now)
#     # 2. 储存hash id,userid,hash
#     db.insert("login",userid=userid,hash=hash,time=now,discard=0)
#     # 3. write cookie ua:sha1
#     web.setcookie('cu', hash, 3600*24*30)
#     return hash


from config import setting
from util import login
#encoding=utf-8

db = setting.db


def check(name,info):
    for key in ["name","avatar",name+"_id",name+"_access_token"]:
        if not info[key]:
            return "no "+key
    return True

def get_by_id(id):

# Path: config/setting.py

# 
# Path: util/login.py
# def login(userid):
#     # 1. sha1(salt+ip+userid+now)
#     now=str(datetime.now())
#     userid=str(userid)
#     hash=sha1(salt+userid+now)
#     # 2. 储存hash id,userid,hash
#     db.insert("login",userid=userid,hash=hash,time=now,discard=0)
#     # 3. write cookie ua:sha1
#     web.setcookie('cu', hash, 3600*24*30)
#     return hash


# Path: model/user.py
from config import setting
from util import login

#encoding=utf-8

db = setting.db


def check(name,info):
    for key in ["name","avatar",name+"_id",name+"_access_token"]:
        if not info[key]:
            return "no "+key
    return True

def get_by_id(id):

    rows = db.select(["user"],what="avatar,name,id",where="id=$id",vars={"id":id})