Exemple #1
0
def _add_one_user(request):
    af = forms.AddUserForm(request, data=request.REQUEST)

    if af.is_valid():
        create_user(**af.clean())
        request.session['users_added'] = "Succesfully added user"
        return redirect(reverse(add))

    return forms.AddMultipleUsersForm(request), af
Exemple #2
0
def _add_one_user(request):
    af = forms.AddUserForm(request, data=request.REQUEST)

    if af.is_valid():
        create_user(**af.clean())
        request.session['users_added'] = "Succesfully added user"
        return redirect(reverse(add))

    return forms.AddMultipleUsersForm(request), af
Exemple #3
0
def register(request):
    """
    Let the user fill in a registration form or process such a form.
    """
    form = AddUserForm(request, data=request.POST or None)

    del form.fields['role']
    del form.fields['affiliation']

    user = None
    if form.is_valid():
        user = create_user(
            form.cleaned_data['username'],
            form.cleaned_data['first_name'],
            form.cleaned_data['last_name'],
            form.cleaned_data['email'],
            Affiliation.objects.all()[0],
            form.cleaned_data['language'],
            Role.objects.get(id=1)
        )

        form = AddUserForm(request)
        log.info(json.dumps({"action": "register", "user": user.username}))

    return render(request, "accounts/register.html", locals())
Exemple #4
0
 def create_user(self, user_form):
     return auth.create_user(
         username=user_form.cleaned_data['username'],
         email=user_form.cleaned_data['email'],
         first_name=user_form.cleaned_data['first_name'],
         last_name=user_form.cleaned_data['last_name']
     )
Exemple #5
0
def register(request):
    """
    Let the user fill in a registration form or process such a form.
    """

    if not settings.ALLOW_REGISTER:
        
        raise django.core.exceptions.PermissionDenied("Please use the admin dashboard to create users") 
        
    form_class = AddUserForm if settings.REGISTER_REQUIRE_VALIDATION else AddUserFormWithPassword
    form = form_class(request, data=request.POST or None)

    user = None
    if form.is_valid():
        user = create_user(
            form.cleaned_data['username'],
            form.cleaned_data['first_name'],
            form.cleaned_data['last_name'],
            form.cleaned_data['email'],
            password=form.cleaned_data.get('password'),
        )

        log_request_usage(request, "account" ,"register")
        if not settings.REGISTER_REQUIRE_VALIDATION:
            new_user = authenticate(username=user.username,
                                    password=form.cleaned_data['password'])
            auth_login(request, new_user)
            return HttpResponseRedirect("/")
        
    return render(request, "accounts/register.html", locals())
Exemple #6
0
def _add_multiple_users(request):
    amf = forms.AddMultipleUsersForm(request, data=request.REQUEST, files=request.FILES)

    if amf.is_valid():
        props = dict(
            affiliation=amf.cleaned_data['affiliation'],
            language=amf.cleaned_data['language'],
            role=amf.cleaned_data['role']
        )

        for user in amf.cleaned_data['csv']:
            create_user(**dict(itertools.chain(props.items(), user.items())))

        request.session['users_added'] = ("Succesfully added {} user(s)"
                                            .format(len(amf.cleaned_data['csv'])))

        # Users created
        return redirect(reverse(add))

    return amf, forms.AddUserForm(request)
Exemple #7
0
def _add_multiple_users(request):
    amf = forms.AddMultipleUsersForm(request, data=request.REQUEST, files=request.FILES)

    if amf.is_valid():
        props = dict(
            affiliation=amf.cleaned_data['affiliation'],
            language=amf.cleaned_data['language'],
            role=amf.cleaned_data['role']
        )

        for user in amf.cleaned_data['csv']:
            create_user(**dict(itertools.chain(props.items(), user.items())))

        request.session['users_added'] = ("Succesfully added {} user(s)"
                                            .format(len(amf.cleaned_data['csv'])))

        # Users created
        return redirect(reverse(add))

    return amf, forms.AddUserForm(request)
Exemple #8
0
def register(request):
    """
    Let the user fill in a registration form or process such a form.
    """
    form = AddUserForm(request, data=request.POST or None)

    del form.fields['role']
    del form.fields['affiliation']

    user = None
    if form.is_valid():
        user = create_user(
            form.cleaned_data['username'], form.cleaned_data['first_name'],
            form.cleaned_data['last_name'], form.cleaned_data['email'],
            Affiliation.objects.all()[0], form.cleaned_data['language'],
            Role.objects.get(id=1))

        form = AddUserForm(request)
        log_request_usage(request, "account", "register")

    return render(request, "accounts/register.html", locals())