Пример #1
0
def create_user():
    data = request.get_json()
    user = user_schema.dump(User.query.filter_by(email=data['email']).first())
    if not data:
        return make_response(jsonify({'message': 'No input data provided'})), 400
    if user:
        return make_response(jsonify({'message': 'User with such email already exists!'})), 400

    hashed_password = bcrypt.generate_password_hash(data['password']).decode('UTF-8')

    new_user = User(
        contactName=data['contactName'],
        password=hashed_password,
        email=data['email'],
        phoneNumber=data['phoneNumber']
    )

    if 'imageFile' in request.files:
        file = request.files['imageFile']
        if file.filename == '':
            return redirect(request.url)
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_PROFPIC_FOLDER'], filename))
            new_user.imageFile = filename

    db.session.add(new_user)
    db.session.commit()
    result = user_schema.dump(new_user)
    return make_response(jsonify({'message': 'New user created!', 'user': result})), 201
Пример #2
0
 def test_file_endings(self):
     self.assertTrue(main.allowed_file('bob.wave'))
     self.assertTrue(main.allowed_file('bob.wav'))
     self.assertTrue(main.allowed_file('bob.aif'))
     self.assertTrue(main.allowed_file('bob.aiff'))
     self.assertFalse(main.allowed_file('derp.jpg'))
     self.assertFalse(main.allowed_file('.wav'))
     self.assertFalse(main.allowed_file('derp.mp3'))
 def test_file_endings(self):
     self.assertTrue(main.allowed_file('bob.wave'))
     self.assertTrue(main.allowed_file('bob.wav'))
     self.assertTrue(main.allowed_file('bob.aif'))
     self.assertTrue(main.allowed_file('bob.aiff'))
     self.assertFalse(main.allowed_file('derp.jpg'))
     self.assertFalse(main.allowed_file('.wav'))
     self.assertFalse(main.allowed_file('derp.mp3'))
Пример #4
0
def upload_image():
    if request.method == 'POST':
        if 'file' not in request.files:
            print("file not in post req")
            return "error"
        file = request.files['file']
        if file.filename == '':
            print('no filename')
            return "error"
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(UPLOAD_FOLDER, filename))
            return redirect(url_for('uploaded_file', filename=filename))
    if request.method == 'GET':
        return render_template('admin/upload.html')
Пример #5
0
    def test_allowed_file_true(self):
        good_filenames = ['img.jpg', 'img.png', 'img.jpeg', 'img.gif']
        results = [main.allowed_file(filename) for filename in good_filenames]

        self.assertEqual(results, [True, True, True, True])
Пример #6
0
    def test_allowed_file_false(self):
        bad_filenames = ['imgjpg', 'img.jp', 'imgpng']
        results = [main.allowed_file(filename) for filename in bad_filenames]

        self.assertEqual(results, [False, False, False])