Esempio n. 1
0
def create_user():
    try:
        username = raw_input("Username: "******"Email: ").strip()
        while True:
            password = getpass("Password: "******" (confirm): ")
            if password_confirm == password:
                break
            else:
                print("Passwords do not match... Try again...")
        u = User(username=username)
        u.email = email
        # check for org
        org = Organization.get_by_name("default")
        if not org:
            org = Organization()
            org.name = "default"
            org.owner = u.uuid
            org.save()
        u.organization = Organization.get_by_name("default").uuid
        u.set_password(password)
        u.add_role("admin")
        u.save()
        print("User created/updated successfully...")
    except KeyboardInterrupt:
        pass
Esempio n. 2
0
def connect_organization(request):
    """
    Connect organization and user
    :param request:
    :return:
    """

    user = request.user
    application_title = settings.APPLICATION_TITLE

    context = {"title": "My Organization",
               "user": user}

    DEBUG = settings.DEBUG_SETTINGS

    if DEBUG:
        print(application_title, "in accounts.views.connect_organization")
        print("request.method:")
        print(request.method)
        print(request.POST)

    if request.method == 'POST':
        form = OrganizationCheckForm(data=request.POST)

        if form.is_valid():
            if DEBUG:
                print("form is valid")
                print("form", form.cleaned_data['domain'])
            org = Organization()
            org.domain = form.cleaned_data['domain']
            org.site_url = "http://"+form.cleaned_data['domain']
            org.owner = user
            org.name = org.domain
            org.save()

            u = request.user
            if DEBUG:
                print("user", u)
            u.affiliated_to = org
            u.organization_role = "primary"
            u.save()

            return redirect(reverse_lazy('accounts:manage_account'))
        else:
            print("OrganizationCheckForm", request.POST, " NOT Valid")
    else:
        form = OrganizationCheckForm()

    context['form'] = form

    if DEBUG:
        print(context)

    return render_to_response('accounts/connect_organization.html',
                             context,
                              context_instance=RequestContext(request))
Esempio n. 3
0
def connect_organization(request):
    """
    Connect organization and user
    :param request:
    :return:
    """

    user = request.user
    application_title = settings.APPLICATION_TITLE

    context = {"title": "My Organization", "user": user}

    DEBUG = settings.DEBUG_SETTINGS

    if DEBUG:
        print(application_title, "in accounts.views.connect_organization")
        print("request.method:")
        print(request.method)
        print(request.POST)

    if request.method == 'POST':
        form = OrganizationCheckForm(data=request.POST)

        if form.is_valid():
            if DEBUG:
                print("form is valid")
                print("form", form.cleaned_data['domain'])
            org = Organization()
            org.domain = form.cleaned_data['domain']
            org.site_url = "http://" + form.cleaned_data['domain']
            org.owner = user
            org.name = org.domain
            org.save()

            u = request.user
            if DEBUG:
                print("user", u)
            u.affiliated_to = org
            u.organization_role = "primary"
            u.save()

            return redirect(reverse_lazy('accounts:manage_account'))
        else:
            print("OrganizationCheckForm", request.POST, " NOT Valid")
    else:
        form = OrganizationCheckForm()

    context['form'] = form

    if DEBUG:
        print(context)

    return render_to_response('accounts/connect_organization.html',
                              context,
                              context_instance=RequestContext(request))
Esempio n. 4
0
    async def post(self, *args, **kwargs) -> Response:
        json_body = await self.deserialize_body()
        organization = Organization()
        name = json_body.get('name')
        if name:
            organization.name = name
        contact_phone = json_body.get('contact_phone')
        if contact_phone:
            organization.contact_phone = contact_phone
        contact_url = json_body.get('contact_url')
        if contact_url:
            organization.contact_url = contact_url

        organization.save()

        response = await self.serialize(data=organization)
        return await self.to_response(response, status_code=201)
Esempio n. 5
0
def create_organization():
    org = Organization()
    org.name = request.form.get('name')
    org.owner = request.form.get('owner').lower()
    org.save()
    return redirect(url_for('accounts.organizations'))