示例#1
0
 def post_login(self, userid, password, expiration):
     """登录"""
     try:
         user = db.get(userid)
     except NotFound:
         abort(403, "User Not Exists")
     if not check_password_hash(user["pwdhash"], password):
         abort(403, "Password Incorrect")
     auth_exp = expiration * 60
     return user, auth.gen_header({"userid": userid}, auth_exp=auth_exp)
示例#2
0
文件: user.py 项目: wangjun/purepage
 def post_login(self, userid, password, expiration):
     """登录"""
     try:
         user = db.get(userid)
     except NotFound:
         abort(403, "User Not Exists")
     if not check_password_hash(user["pwdhash"], password):
         abort(403, "Password Incorrect")
     auth_exp = expiration * 60
     return user, auth.gen_header({"userid": userid}, auth_exp=auth_exp)
示例#3
0
 def post(self, article, content):
     """发表评论"""
     try:
         db.get(article)
     except NotFound:
         abort(400, "Article Not Found")
     date = util.now()
     _id = '.'.join([article, date, g.userid])
     cmt = {
         "_id": _id,
         "type": "comment",
         "article": article,
         "date": date,
         "content": content,
         "userid": g.userid
     }
     db.put(cmt)
     cmt['user'] = g.user
     return cmt
示例#4
0
 def post_reset(self, token, password):
     """重置密码"""
     try:
         token = decode_token(token)
     except InvalidTokenError as ex:
         abort(400, str(ex))
     if token["type"] != "reset":
         abort(400, "Token Type Incorrect")
     user = db.get(token["userid"])
     if user is None:
         abort(400, "User Not Exists")
     user["pwdhash"] = gen_pwdhash(password)
     db.put(user)
     return "OK"
示例#5
0
文件: user.py 项目: wangjun/purepage
 def post_reset(self, token, password):
     """重置密码"""
     try:
         token = decode_token(token)
     except InvalidTokenError as ex:
         abort(400, str(ex))
     if token["type"] != "reset":
         abort(400, "Token Type Incorrect")
     user = db.get(token["userid"])
     if user is None:
         abort(400, "User Not Exists")
     user["pwdhash"] = gen_pwdhash(password)
     db.put(user)
     return "OK"
示例#6
0
 def post(self, catalog, article, **info):
     """创建或修改文章"""
     userid = g.user['_id']
     _id = '.'.join([userid, catalog, article])
     try:
         origin = db.get(_id)
     except NotFound:
         origin = {
             'type': 'article',
             '_id': _id,
             'userid': userid,
             'catalog': catalog,
             'article': article
         }
     origin.update(info)
     db.put(origin)
     return origin
示例#7
0
 def get(self, userid):
     """获取用户信息"""
     user = db.get(userid)
     return user
示例#8
0
 def get(self, userid, catalog, article):
     """获取一篇文章"""
     key = ".".join([userid, catalog, article])
     result = db.get(key)
     return result
示例#9
0
文件: user.py 项目: wangjun/purepage
 def get(self, userid):
     """获取用户信息"""
     user = db.get(userid)
     return user