def change_password(self, request, **kwargs):
        self.method_check(request, allowed=['post'])

        apikey_auth = ApiKeyAuthentication()
        if apikey_auth.is_authenticated(request) == True:
            data = self.deserialize(request, request.body,
                                    format=request.META.get('CONTENT_TYPE', 'application/json'))
            if request.user.has_usable_password():
                password_change_form = ChangePasswordForm(request.user, data)
            else:
                password_change_form = SetPasswordForm(request.user, data)

            if password_change_form.is_valid():
                password_change_form.save()
                response_data = {'status': "success"}
                if request.user.is_authenticated():
                    logout(request)
            else:
                if request.user.is_authenticated():
                    logout(request)
                return self.create_response(request, {
                    'error': password_change_form.errors,
                }, HttpBadRequest)

            return HttpResponse(json.dumps(response_data), mimetype='application/json')
예제 #2
0
파일: views.py 프로젝트: thoas/i386
def _password_change(request, oldpassword, password1, password2):
    if request.method == 'POST':
        password_change_form = ChangePasswordForm(request.user, request.POST)
        if password_change_form.is_valid():
            password_change_form.save()
            return request.user
        else:
            return password_change_form.errors['__all__']
    return False
예제 #3
0
def change_password(request):
    """
        Password changing
    :param request:
    :return:
    """
    user = request.user.get_profile()
    if request.method == "POST":
        data = request.POST.copy()
        change_password_form = ChangePasswordForm(user.user, data)
        if change_password_form.is_valid():
            change_password_form.save()
            messages.success(
                request,
                _('Password changed successfully.'),
                fail_silently=True
            )
            return redirect(reverse("profile"))
        else:
            change_password_form = ChangePasswordForm(user.user, data)
    else:
        change_password_form = ChangePasswordForm(user.user)
    c = {"form": change_password_form}
    return render(request, "change_password.html", c)