예제 #1
0
 def loginuser(self, data):
     userdb = self.db.userdb
     if 'password' in data and 'email' in data:
         record = dumps(userdb.find_one({"email": data["email"]}))
         record = json.loads(record)
         print(record)
         if record is None:
             return Codes.invalidEmail()
         elif data["password"] == record["password"]:
             return json.dumps({
                 "status": "success",
                 "message": {
                     "email": data["email"],
                     "name": record["name"]
                 }
             })
         else:
             return Codes.invalidPassword()
     else:
         return Codes.badRequest()
예제 #2
0
 def deductMoney(self, data):
     userdb = self.db.userdb
     if 'email' in data and 'amount' in data:
         id = dumps(
             userdb.update({"email": data["email"]},
                           {'$inc': {
                               'money': -int(data["amount"])
                           }}))
         id = json.loads(id)
         print(id)
         if id['updatedExisting'] == True:
             return json.dumps({
                 "status": "success",
                 "message": {
                     "email": data["email"]
                 }
             })
         else:
             return Codes.invalidEmail()
     else:
         return Codes.badRequest()