Exemplo n.º 1
0
def change_password(request,
                    domain,
                    login_id,
                    template="users/partials/reset_password.html"):
    # copied from auth's password_change

    commcare_user = CommCareUser.get_by_user_id(login_id, domain)
    json_dump = {}
    if not commcare_user or not user_can_access_other_user(
            domain, request.couch_user, commcare_user):
        raise Http404()
    django_user = commcare_user.get_django_user()
    if request.method == "POST":
        form = SetUserPasswordForm(request.project,
                                   login_id,
                                   user=django_user,
                                   data=request.POST)
        if form.is_valid():
            form.save()
            json_dump['status'] = 'OK'
            form = SetUserPasswordForm(request.project, login_id, user='')
    else:
        form = SetUserPasswordForm(request.project, login_id, user=django_user)
    context = _users_context(request, domain)
    context.update({
        'reset_password_form': form,
    })
    json_dump['formHTML'] = render_to_string(template, context)
    return HttpResponse(json.dumps(json_dump))
Exemplo n.º 2
0
 def form(self, password):
     return SetUserPasswordForm(self.project,
                                user_id=self.user.id,
                                user=self.user,
                                data={
                                    "new_password1": password,
                                    "new_password2": password,
                                })
Exemplo n.º 3
0
def change_password(request, domain, login_id, template="users/partial/reset_password.html"):
    # copied from auth's password_change

    commcare_user = CommCareUser.get_by_user_id(login_id, domain)
    json_dump = {}
    if not commcare_user:
        raise Http404()
    django_user = commcare_user.get_django_user()
    if request.method == "POST":
        form = SetUserPasswordForm(request.project, login_id, user=django_user, data=request.POST)
        if form.is_valid():
            form.save()
            json_dump['status'] = 'OK'
            form = SetUserPasswordForm(request.project, login_id, user='')
    else:
        form = SetUserPasswordForm(request.project, login_id, user=django_user)
    context = _users_context(request, domain)
    context.update({
        'reset_password_form': form,
    })
    json_dump['formHTML'] = render_to_string(template, context)
    return HttpResponse(json.dumps(json_dump))
Exemplo n.º 4
0
 def reset_password_form(self):
     return SetUserPasswordForm(self.request.project,
                                self.editable_user_id,
                                user="")