from flask import Flask, jsonify, request
from modals.modals import User
from api import create_app, db
from validate_email import validate_email

app = create_app('DevelopmentEnv')


@app.route('/')
def index():
    response = jsonify({'Welcome Message': 'Hello'})
    response.status_code = 201
    return response


@app.route('/auth/register', methods=['POST'])
def register():
    request.get_json(force=True)
    try:
        name = request.json['name']
        email = request.json['email']
        password = request.json['password']

        if not name or not email or not password:
            response = jsonify({'Error': 'Missing Values'})
            response.status_code = 400
            return response

        if not validate_email(email):
            response = jsonify({'Error': 'Invalid Email'})
            response.status_code = 400
            return response

        if len(password) < 6:
            response = jsonify({'Error': 'Password is short'})
            response.status_code = 400
            return response

        user = User(email=email, password=password, name=name)
        res = user.get_all()

        if email in [r.email for r in res]:
            response = jsonify({'Error': 'Email Already exists'})
            response.status_code = 400
            return response

        user.save()
        response = jsonify({
            'Status': user.email + ' Successfully registered'
        })
        response.status_code = 201
        return response


    except KeyError:
        response = jsonify({'Error': 'Invalid Keys detected'})
        response.status_code = 500
        return response


if __name__ == '__main__':
    app.debug = True
    app.run()
    app.run(debug=True)

@@ -14,15 +14,8 @@
 port
- Flask,
  jso
@@ -32,39 +32,8 @@
 est%0A
-from modals.modals import User%0A
 from
@@ -58,54 +58,38 @@
 _app
-, db
 %0Afrom 
-validate_email import validate_email
+classes.user import User
 %0A%0Aap
@@ -485,513 +485,8 @@
 d'%5D%0A
-%0A        if not name or not email or not password:%0A            response = jsonify(%7B'Error': 'Missing Values'%7D)%0A            response.status_code = 400%0A            return response%0A%0A        if not validate_email(email):%0A            response = jsonify(%7B'Error': 'Invalid Email'%7D)%0A            response.status_code = 400%0A            return response%0A%0A        if len(password) %3C 6:%0A            response = jsonify(%7B'Error': 'Password is short'%7D)%0A            response.status_code = 400%0A            return response%0A%0A
     
@@ -510,14 +510,8 @@
 mail
-=email
 , pa
@@ -520,418 +520,46 @@
 word
-=password, name=name)%0A        res = user.get_all()%0A%0A        if email in %5Br.email for r in res%5D:%0A            response = jsonify(%7B'Error': 'Email Already exists'%7D)%0A            response.status_code = 400%0A            return response%0A%0A        user.save()%0A        response = jsonify(%7B%0A            'Status': user.email + ' Successfully registered'%0A        %7D)%0A        response.status_code = 201%0A        return response
+, name)%0A        return user.register()
 %0A%0A%0A 

Move register code to User class