def post(app): """ 포스팅을 합니다. 호출 http://localhost:8080/[email protected]&context="this is posting"&images=http://www.happ.kr/images/01.jpg,http://www.happ.kr/images/02.jpg&status=1 결과 {"code":0, "msg":""} : 성공 {"code":-1, "msg":"..."} : 필수 파라미터가 빠졌거나 잘못된 경우 """ try: req = get_request(req_proto) userid = req['userid'] context = req['context'] images = req['images'].split(",") status = req['status'] with app.postdb() as db: app.postmgr.post(db, userid, images, context, status) return get_response(res_proto, NoError()) except ApplicationError as e: logging.debug(e) return get_response(res_proto, e) except Exception as e: logging.exception(e)
def join(app): """ 가입을 처리 합니다. 호출 http://localhost:8080/[email protected]&nickname=MyNickname&password=1234 결과 {"code":0, "msg":""} : 성공 {"code":-1, "msg":"..."} : 필수 파라미터가 빠졌거나 잘못된 경우 {"code":-1020, "msg":"..."} : 이미 해당 아이디가 존재하는 경우 {"code":-1030, "msg":"..."} : 잘못된 아이디(길이, 형식) {"code":-1040, "msg":"..."} : 잘못된 비밀번호(길이, 형식) """ try: req = get_request(req_proto) userid = str(req['userid']) nickname = unicode(req['nickname']) password = req['password'] with app.userdb() as db: app.usermgr.join(db, userid, password, nickname) return get_response(res_proto, NoError()) except ApplicationError as e: logging.debug(e) return get_response(res_proto, e) except Exception as e: logging.exception(e)
def login(app): """ 로그인을 처리 합니다. 호출 http://localhost:8080/[email protected]&password=1234 결과 {"code":0, "msg":""} : 성공 {"code":-1, "msg":"..."} : 필수 파라미터가 빠졌거나 잘못된 경우 """ try: req = get_request(req_proto) userid = str(req['userid']) password = req['password'] with app.userdb() as db: user = app.usermgr.login(db, userid, password) session = req['session'] session['num'] = user.num session['userid'] = user.id session['nickname'] = user.nickname session['lastlogin'] = time.time() session['ip'] = request.remote_addr session.save() return get_response(res_proto, NoError()) except ApplicationError as e: logging.debug(e) return get_response(res_proto, e) except Exception as e: logging.exception(e)
def logout(app): """ 로그아웃 한다. 호출 http://localhost:8080/logout 결과 {"msg": "", "code": 0} : 성공 {"msg": "login required.", "code": -2} : 로그인 하지 않은 상태에서 로그아웃 요청 """ try: req = get_request(req_proto) session = req['session'] userid = session['userid'] session.delete() session.save() with app.userdb() as db: app.usermgr.logout(db, userid) return get_response(res_proto, NoError()) except ApplicationError as e: logging.debug(e) return get_response(res_proto, e) except Exception as e: logging.exception(e)
def show(app): """ 포스팅한 내용을 rss 형식으로 리턴 합니다. 호출 http://localhost:8080/show?num=1 결과 {"code":0, "msg":"", "num": 1, "wid":"*****@*****.**", "wnick":"test", "wtime":"2014-..", "status":1, "images":"http://...jpg,http://...jpg", "context": "bla, bla..."} : 성공 {"code":-1, "msg":"..."} : 필수 파라미터가 빠졌거나 잘못된 경우 """ try: req = get_request(req_proto) try: session = req['session'] readerid = str(session['userid']) except KeyError: # 세션이 없는 경우는 로그인 하지 않았으므로 public 글만 볼 수 있다. readerid = None num = int(req['num']) with app.postdb() as db: post = app.postmgr.get_post(db, num, readerid) res = NoError() if post: res.num = post.num res.wtime = post.wtime res.status = post.status res.images = post.images res.context = post.context res.wnick = post.wnick else: raise PostNotExistError( "post not exist. readerid=%s, post_num=%s" % (readerid, num)) return get_response(res_proto, res) except ApplicationError as e: logging.debug(e) return get_response(res_proto, e) except Exception as e: logging.exception(e)
def feed(app): """ rss link를 연결했을 때 화면을 보여 줍니다. 호출 http://localhost:8080/feed?num=1 결과 html 형식의 문서 """ try: req = get_request(req_proto) try: session = req['session'] readerid = str(session['userid']) except: # 세션이 없는 경우는 로그인 하지 않았으므로 public 글만 볼 수 있다. readerid = None num = int(req['num']) with app.postdb() as db: post = app.postmgr.get_post(db, num, readerid) response.content_type = 'text/html' if post: url = "http://{0}".format(app.publichost) html = _generate_html(url, post.num, post.wid, post.wnick, post.wtime, post.status, post.images, post.context) else: raise PostNotExistError( "post not exist. readerid=%s, post_num=%s" % (readerid, num)) return html except ApplicationError as e: logging.debug(e) return get_response(res_proto, e) except Exception as e: logging.exception(e)