Пример #1
0
def deleteUser(username):
    usMgr = UserManager()
    user = usMgr.getOne(username)
    if user is None:
        raise MissingKey("no user with this username exists")
    success = usMgr.deleteOne(username)
    return {"success": success}
Пример #2
0
def register():
    usMgr = UserManager()
    newUserVal = request.json
    usrPK = usMgr.addOne(newUserVal)
    success = True if usrPK else False
    result = {"success": success}
    return result
 def setUp(self):
     logger = logging.getLogger(f"{__name__}.setUp")
     from app.UserManager import UserManager
     self.uMgr = UserManager()
     self.conn = self.uMgr.conn
     # clear table
     with self.conn.cursor() as cur:
         cur.execute(f"delete from {UserManager.TABLE_NAME}")
     self.conn.commit()
     # insert test user data
     self.uMgr.addOne(dict(zip(
         ["username", "password", "fName", "lName", "email"],
         ["stallylol", "123456", "Stally", "Duan", "*****@*****.**"]
     )))
     self.uMgr.addOne(dict(zip(
         ["username", "password", "fName", "lName", "email"],
         ["shiyugun", "abcdef", "Shiyu", "Gao", "*****@*****.**"]
     )))
     self.uMgr.addOne(dict(zip(
         ["username", "password", "fName", "lName", "email"],
         ["aspenrocks", "78910", "Aspen", "Forster", "*****@*****.**"]
     )))
     self.uMgr.addOne(dict(zip(
         ["username", "password", "fName", "lName", "email"],
         ["toBeDeleted", "wtfwtf", "Dummy", "Value", "*****@*****.**"]
     )))
     self.usernames = ["stallylol", "shiyugun", "aspenrocks", "toBeDeleted"]
Пример #4
0
def findUser():
    usMgr = UserManager()
    query = usMgr.keepValidFieldsOnly(request.json, throw=True)
    # ignore empty values
    query = {
        k: v
        for k, v in query.items() if v is not None and v != "" and v != []
    }
    users = usMgr.getMany(query)
    return users
Пример #5
0
def updateUser(username):
    usMgr = UserManager()
    newUserVal = usMgr.keepValidFieldsOnly(request.json, throw=True)
    # pop None / empty values
    newUserVal = {
        k: v
        for k, v in newUserVal.items() if v is not None and v != ""
    }
    success = usMgr.updateOne(username, newUserVal)
    result = {"success": success}
    return result
Пример #6
0
def addUser():
    usMgr = UserManager()
    newUserVal = usMgr.keepValidFieldsOnly(request.json, throw=True)
    # pop None / empty values
    newUserVal = {
        k: v
        for k, v in newUserVal.items() if v is not None and v != ""
    }
    usrPk = usMgr.addOne(newUserVal)
    success = True if usrPk else False
    result = {"success": success}
    return result
Пример #7
0
 def setUp(self):
     from app.BookingManager import BookingManager
     from app.UserManager import UserManager
     from app.CarManager import CarManager
     self.bkMgr = BookingManager()
     self.uMgr = UserManager()
     self.cMgr = CarManager()
     self.conn = self.bkMgr.conn
     self.bk_ids = [-1, -1, -1, -1, -1]
     self.car_ids = [-1] * 3
     self.usernames = []
     # firstly clear table
     with self.conn.cursor() as cur:
         cur.execute("delete from {}".format(BookingManager.TABLE_NAME))
         cur.execute("delete from {}".format(CarManager.TABLE_NAME))
         cur.execute("delete from {}".format(UserManager.TABLE_NAME))
     self.conn.commit()
     # insert test user data
     self._insertUsers()
     # insert test car data
     self._insertCars()
     # insert test booking data
     values = [[
         "stallylol", self.car_ids[0], '2020-05-01', '09:14:23',
         '2020-05-02', '09:15:00', "booked"
     ],
               [
                   "stallylol", self.car_ids[1], '2020-04-01', '09:14:23',
                   '2020-04-02', '09:15:00', "finished"
               ],
               [
                   "shiyugun", self.car_ids[2], '2020-04-23', '09:14:23',
                   '2020-04-25', '09:15:00', "cancelled"
               ],
               [
                   "shiyugun", self.car_ids[0], '2020-03-01', '05:20:00',
                   '2020-03-02', '06:15:00', "finished"
               ],
               [
                   'aspenrocks', self.car_ids[1], '2020-05-04', '11:14:23',
                   '2020-05-010', '12:15:00', "booked"
               ]]
     for i in range(5):
         self.bk_ids[i] = self.bkMgr.addOne(
             dict(
                 zip([
                     "username", "car_id", "date_booking", "time_booking",
                     "date_return", "time_return", "status"
                 ], values[i])))
 def __init__(self):
     self.public_exponent = 65537
     self.key_size = 512
     self.user_manager = UserManager()
     self.otp_length = 4
 def __init__(self):
     self.user_manager = UserManager()
Пример #10
0
 def __init__(self):
     super().__init__()
     self.order_manager = OrderManager()
     self.encryption_manager = EncryptionManager()
     self.otp_manager = OTPManager()
     self.user_manager = UserManager()