def signup():
    user = {
        "firstName": request.form["firstName"],
        "lastName": request.form["lastName"],
        "email": request.form["email"],
        "password": request.form["password"],
        "organization": request.form["organization"],
        "location": request.form["location"],
        "userType": request.form["userType"]
    }

    try:
        User.objects.get(email=user["email"])
        return Response("There's already an account with the provided email.",
                        status=400)
    except:
        try:
            AuthenticationService.signup(user)
            userConfirmationId = uuid4()
            user = User.objects.get(email=user["email"])
            AuthenticationService.setUserConfirmationId(
                user, userConfirmationId)
            sub = "Confirm Account"
            msg = f"<p>Congratulations, you've registered for Agriworks. Please click the link below to confirm your account.</p><p><a href=\"{app.rootUrl}/confirm-user/{userConfirmationId}\"> Confirm account </a></p>"
            MailService.sendMessage(user, sub, msg)
            return Response("Signup successful", status=200)
        except:
            return Response("Signup unsuccessful. Please try again.",
                            status=403)
    def post(self):
        user = {
            "firstName": request.form["firstName"],
            "lastName": request.form["lastName"],
            "email": request.form["email"],
            "password": request.form["password"],
            "organization": request.form["organization"],
            "location": request.form["location"],
            "userType": request.form["userType"]
        }

        try:
            User.objects.get(email=user["email"])
            return Response(
                "There's already an account with the provided email.",
                status=400)
        except:
            try:
                AuthenticationService.signup(user)
                userConfirmationId = uuid4()
                user = User.objects.get(email=user["email"])
                if AuthenticationService.isUserConfirmed(user):
                    sessionId = uuid4()
                    session = Session(user=user, sessionId=sessionId)
                    session.save()
                    data = {
                        "message": "Google authorized successful!",
                        "user": user.email
                    }
                    ret = make_response(data)
                    ret.set_cookie("SID",
                                   str(session.sessionId),
                                   expires=session.dateExpires)
                    return ret
                AuthenticationService.setUserConfirmationId(
                    user, userConfirmationId)
                sub = "Confirm Account"
                msg = f"<p>Congratulations, you've registered for Agriworks. Please click the link below to confirm your account.</p><p><a href=\"{app.rootUrl}/confirm-user/{userConfirmationId}\"> Confirm account </a></p>"
                MailService.sendMessage(user, sub, msg)
                return Response("Signup successful", status=200)
            except:
                return Response("Signup unsuccessful. Please try again.",
                                status=403)
def signup():
    user = {"firstName": request.form["firstName"],
            "lastName": request.form["lastName"],
            "email": request.form["email"],
            "password": request.form["password"]
            }

    if (not AuthenticationService.signup(user)):
        return Response("There's already an account with the provided email.", status=400)

    return Response("Signup successful", status=200)