Example #1
0
 def setupClass(self):
     app = createApp(True)
     app.app_context().push()
     db.create_all()
     self.user1 = User.createUser("*****@*****.**", "Michael", "hello",
                                  "Michael", "Shea")
     self.user2 = User.createUser("*****@*****.**", "kaitlyne", "hello",
                                  "Kaitlyne", "Chan")
     self.user3 = User.createUser("*****@*****.**", "hello", "hello",
                                  "helloe", "hello")
     self.group = Group.createGroup("My Apartment")
Example #2
0
 def setupClass(self):
     app = createApp(True)
     app.app_context().push()
     db.create_all()
     self.user1 = User.createUser("*****@*****.**", "Yanting", "hello",
                                  "Yanting", "Zeng")
     self.user2 = User.createUser("*****@*****.**", "Kaitlyne", "hello",
                                  "Kaitlyne", "Chan")
     self.user3 = User.createUser("*****@*****.**", "hello", "hello",
                                  "hello", "hello")
     self.user4 = User.createUser("*****@*****.**", "hi", "hi", "hi", "hi")
     self.addGroupToDB()
     self.addChoreToDB()
Example #3
0
def createUser():
    """
    Create a new user and add to the database, use Bcrypt to hash password

    :param email: the email of the user
    :param username: (optional) the username of the user
    :param password: the password of the user
    :param firstName: the first name of the user
    :param lastName: (optional) the last name of the user

    :type email: str
    :type username: str
    :type password: str
    :type firstName: str
    :type lastName: str

    :return: "User Successfully Created", status code
    :rtype: str, int

    :raises KeyError: if the input is not provided by the user
    :raises sqlalchemy.exc.IntegrityError: if the user already existed in the database
    """
    data = request.data
    dataDict = loads(data)

    try:
        userEmail = dataDict['email']
        userPassword = dataDict['password']
        userFirstName = dataDict['firstName']
    except KeyError:
        error = "Invalid input Parameters"
        return error, 400

    salt = bcrypt.gensalt()
    userPassword = bcrypt.hashpw(userPassword.encode(), salt)
    userName = dataDict.get('username', userEmail)

    if 'lastName' in dataDict:
        userLastName = dataDict['lastName']
    else:
        userLastName = None

    try:
        User.createUser(userEmail, userName, userPassword, userFirstName,
                        userLastName)
    except IntegrityError:
        error = "Failed to create new user"
        return error, 400

    return "User Successfully Created"
Example #4
0
 def setUp(self):
     db.create_all()
     self.user = User.createUser("*****@*****.**", "kaitlyne", "hello",
                                 "Kaitlyne", "Chan")
     self.group = Group.createGroup("My Apartment")
     self.group.addUser(self.user)