Example #1
0
    def post(self):
        data = UserRegistration.parser.parse_args()
        if UserModel.find_username(data['username']):
            return {"message": "user already exists"}, 400
        connection = sqlite3.connect('data16.db')
        c = connection.cursor()
        query = 'INSERT INTO users VALUES(NULL,?,?)'
        c.execute(query, (data['username'], data['password']))
        connection.commit()
        connection.close()

        return {"message": "user created succesfully"}, 201
Example #2
0
def authentication(username, password):
    user = UserModel.find_username(username)
    if user and user.password == password:
        return user
    else:
        return {'message': "error"}