示例#1
0
def login(seq):
    if seq.req.session.get("uid"):
        return MakeResp("redirect", "/")

    context["LoginError"] = None

    if seq.req.method == "POST":
        uid = seq.req.post.get("Id")
        upw = seq.req.post.get("Pw")

        if uid and upw:
            from hashlib import sha1

            select = seq.db.SelectRow(
                "member", ["img"], "`uid`='%s' AND `pw`='%s'" % (uid, sha1(upw.encode()).hexdigest())
            )

            if len(select) == 1:
                resp = MakeResp("redirect", "/")
                resp["header"]["session"] = {"uid": uid, "img": select[0]["img"]}
                return resp

            else:
                context["LoginError"] = "ID 또는 비밀번호가 올바르지 않습니다."

        else:
            context["LoginError"] = "모든 항목을 입력해 주십시오."

    return render("login.html", context)
示例#2
0
def home(seq):
    context["ActiveMenu"] = "홈"

    session = seq.req.session.get
    context["user"] = {"Uid": session("uid"), "Img": session("img")}

    return render("index.html", context)
示例#3
0
def index(seq):
	uid = seq.req.session.get('uid')
	if not uid: return MakeResp('redirect', '/login')

	context['ActiveMenu'] = '업로드'
	context['UploadResult'] = None

	if seq.req.method == 'POST':
		file = seq.req.post.get('Pkm', {})
		secret = seq.req.post.get('Secret')
		content = file.get('content')

		if content:
			try:
				from hashlib import sha1
				filename = sha1(content).hexdigest()
				file = open('files/%s.pkm' % filename, 'wb')
				file.write(content)
				file.close()

				from parser import PkmLoader
				content = PkmLoader(content)
				content['uid'] = uid
				content['filename'] = filename
				if secret: secret = '1'
				else: secret = '0'
				content['secret'] = secret
				seq.db.InsertRow('upload', content)

				context['UploadResult'] = '.pkm 파일이 성공적으로 저장되었습니다.'
			except:
				context['UploadResult'] = """
					올바른 .pkm이 아니거나 파일을 저장하는 데 오류가 발생했습니다.
				""".strip()
		else:
			context['UploadResult'] = '파일이 선택되지 않았습니다.'

	return render('upload.html', context)