Пример #1
0
    def post(self):
        args = self.reqparse.parse_args()
        #Taking the information from the registration form and assinging it to Python variables
        username = args['username']
        print("username is " + str(username))
        password = args['password']
        email = args['email']
        firstName = args['firstName']
        lastName = args['lastName']
        approved = False 
        print("approved " + str(password) + " " + str(firstName) + " " + str(lastName) + " " + str(approved))
        
        if args['type'] == "admin":
            accountType = "ADMIN"
        elif args['type'] == "requester":
            accountType = "REQUESTER"
        elif args['type'] == "taker":
            accountType = "TAKER"
        else: #this is how you set a response json and a response status code
            return {"error": "Account type is missing"}, 400

        userRepository = UserRepository()
        if userRepository.user_exists(username):
            return{"error": "An account with this username already exists"}, 400

        newUser = User(username, password, email, firstName, lastName, accountType, approved)
        print("new user created")
        userRepository.add_or_update(newUser)
        userRepository.save_changes()
        print("user has been added to the db!")
        session['username'] = username
        return {"message": "Post to database was successful. New user registered."}
Пример #2
0
def approve(username):
    username = username
    userRepository = UserRepository()
    user = userRepository.find(username)
    user.approved = 1
    userRepository.save_changes()
    return render_template('admin-approval.html', user=user)
Пример #3
0
def populate_users():
    try:
        userRepository = UserRepository()
        newAdmin = User('admin', '123', "*****@*****.**", 'George',
                        'Burdell', 'ADMIN', True)
        newNoteRequester = User('johndoe', '123', "*****@*****.**", 'John',
                                'Doe', 'REQUESTER', True)
        newNoteTaker = User('janedoe', '123', '*****@*****.**', 'Jane',
                            'Doe', 'TAKER', True)
        userRepository.add_or_update(newAdmin)
        userRepository.add_or_update(newNoteRequester)
        userRepository.add_or_update(newNoteTaker)
        userRepository.save_changes()
        print("All preset users added into database!")
    except:
        print("The database has already been populated with the preset users.")