def post(self, request):
     username = request.POST['UserName']
     password = request.POST['Password']
     permission = request.POST['Permission']
     email = request.POST['Email']
     firstName = request.POST['FirstName']
     lastName = request.POST['LastName']
     contactPhone = request.POST['ContactPhone']
     officePhone = request.POST['OfficePhone']
     extension = request.POST['Extension']
     response = Terminal.createAccount(permission, username, password,
                                       email, firstName, lastName,
                                       contactPhone, officePhone, extension)
Esempio n. 2
0
 def post(self, request):
     username = request.POST['username']
     password = request.POST['password']
     permission = request.POST['permission']
     email = request.POST['email']
     firstName = request.POST['firstName']
     lastName = request.POST['lastName']
     contactPhone = request.POST['contactPhone']
     officePhone = request.POST['officePhone']
     extension = request.POST['extension']
     terminalInstance = Terminal()
     id = request.session['userid']
     user = USER.objects.get(id=id)
     terminalInstance.login(user.username, user.password)
     ret, success = terminalInstance.createAccount(permission, username,
                                                   password, email,
                                                   firstName, lastName,
                                                   contactPhone,
                                                   officePhone, extension)
     if success is True:
         request.method = 'get'
         return redirect('/commands/')
     else:
         return render(request, '/error/', {"message": ret})
Esempio n. 3
0
    def test_createAccount(self):
        userdata = USER.objects.get(username="******")
        user = User.User(userdata.permission, userdata.username,
                         userdata.password, userdata.id, userdata.email,
                         userdata.firstName, userdata.lastName,
                         userdata.contactPhone, userdata.officePhone,
                         userdata.extension)
        userdata2 = USER.objects.get(username="******")
        user2 = User.User(userdata2.permission, userdata2.username,
                          userdata2.password, userdata2.id, userdata2.email,
                          userdata2.firstName, userdata2.lastName,
                          userdata2.contactPhone, userdata2.officePhone,
                          userdata2.extension)
        userdata3 = USER.objects.get(username="******")
        user3 = User.User(userdata3.permission, userdata3.username,
                          userdata3.password, userdata3.id, userdata3.email,
                          userdata3.firstName, userdata3.lastName,
                          userdata3.contactPhone, userdata3.officePhone,
                          userdata3.extension)
        self.user = user2
        self.assertTrue(user.permission[1] == '1')
        self.assertTrue(user2.permission[1] != '1')
        self.assertTrue(user2.permission[1] == '2',
                        "Not Authorized To Use This Command")
        self.assertTrue(user3.permission[1] != '1')

        self.assertEquals(
            Terminal.createAccount(self, '2', 'jjj', '123', '*****@*****.**',
                                   'John', 'Aponte', '2011111111',
                                   '2012222222', '47'), "New user created")

        self.assertEqual(
            Terminal.createAccount(self, '3', 'jjj', 'aaa', '*****@*****.**',
                                   'John', 'Aponte', '2011111111',
                                   '2012222222', '47'),
            "Account Already Exists")

        self.assertEqual(
            Terminal.createAccount(self, '4', 'bbb', 'ccc', '*****@*****.**',
                                   'John', 'Aponte', '2033333333',
                                   '2044444444', '48'), "New user created")

        self.assertEqual(
            Terminal.createAccount(self, '2', 'bbb', 'ccc', '*****@*****.**',
                                   'Hn', 'Te', '2055555555', '2066666666',
                                   '49'), "Username Already Exist")

        self.assertEqual(
            Terminal.createAccount(self, '1', 'eee', 'zzz', '*****@*****.**',
                                   'Jo', 'Ap', '2066666666', '207777777',
                                   '48'), "Email Already In Use")

        self.assertEqual(
            Terminal.createAccount(self, '3', 'hhh', 'yyy', '*****@*****.**',
                                   'Doom', 'Kek', '2066666666', '2044444444',
                                   '48'), "Phone Number Already in Use")

        self.assertEqual(
            Terminal.createAccount(self, '0', 'hhh', 'yyy', '*****@*****.**',
                                   'Doom', 'Kek', '2066666666', '2044444444',
                                   '48'), "Invalid Permission")

        self.assertEqual(
            Terminal.createAccount(self, '5', 'hhh', 'yyy', '*****@*****.**',
                                   'Doom', 'Kek', '2066666666', '2044444444',
                                   '48'), "Invalid Permission")

        self.assertEqual(
            Terminal.createAccount(self, '3', '', 'yyy', '*****@*****.**',
                                   'Doom', 'Kek', '2066666666', '2044444444',
                                   '48'), "Invalid Username")

        self.assertEqual(
            Terminal.createAccount(self, '3', 'hhh', '', '*****@*****.**',
                                   'Doom', 'Kek', '2066666666', '2044444444',
                                   '48'), "Invalid Password")

        self.assertEqual(
            Terminal.createAccount(self, '3', 'hhh', 'yyy', 'dfsiahfilnwefr',
                                   'Doom', 'Kek', '2066666666', '2044444444',
                                   '48'), "Invalid Email")

        self.assertEqual(
            Terminal.createAccount(self, '3', 'hhh', 'yyy', '', 'Doom', 'Kek',
                                   '2066666666', '2044444444', '48'),
            "Invalid Email")

        self.assertEqual(
            Terminal.createAccount(self, '3', 'hhh', 'yyy', '*****@*****.**',
                                   '', 'Kek', '2066666666', '2044444444',
                                   '48'), "Must Enter Valid Name")

        self.assertEqual(
            Terminal.createAccount(self, '3', 'hhh', 'yyy', '*****@*****.**',
                                   'Doom', '', '2066666666', '2044444444',
                                   '48'), "Must Enter Valid Name")

        self.assertEqual(
            Terminal.createAccount(self, '3', 'hhh', 'yyy', '*****@*****.**',
                                   'Doom', 'Kek', '4535387478347874878247',
                                   '2044444444', '48'), "Invalid Phone Number")

        self.assertEqual(
            Terminal.createAccount(self, '3', 'hhh', 'yyy', '*****@*****.**',
                                   'Doom', 'Kek', '12334', '2044444444', '48'),
            "Invalid Phone Number")

        # Instead of having a general error, have the errors listed by the order of their fault. ex: the username in the
        # first error so it would spit out "Invalid username", then once its fixed, it would spit out "Invalid Email"
        self.assertEqual(
            Terminal.createAccount(self, '3', ' ', 'yyy',
                                   '*****@*****.**',
                                   'Do2om', '11', '2063242342346666666',
                                   '204444444423244', '4238'),
            "Multiple Invalid Credentials")