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')
Example #2
0
def change_password(request):
    print("dadda")
    next_page = request.GET.get('next')
    form = ChangePasswordForm()
    if request.method == "POST":
        print("adadad")
        form = ChangePasswordForm(data=request.POST)
        if form.is_valid():
            print("qwert")
            oldpassword = form.cleaned_data.get("oldpassword")
            if not request.user.check_password(oldpassword):
                messages.error(request, 'Old password is not True')
                return redirect('account:change_password')
            newpassword = form.cleaned_data.get("newpassword2")
            print(newpassword)
            request.user.set_password(newpassword)

            request.user.save()
            if next_page:
                return redirect(next_page)
            return redirect(reverse_lazy('product:product_list'))
    context = {
        "form": form,
    }
    return render(request, 'index.html', context)
Example #3
0
def change_password(request):

    if not request.user.is_authenticated():
        messages.error(request, "You must log in to change your password")
        return redirect("login")

    template_name = "change_password.html"
    form = ChangePasswordForm

    if not request.method == "POST":
        return render(request, template_name, {'form': form})

    form = ChangePasswordForm(request.POST)

    if not form.is_valid():
        return render(request, template_name, {'form': form})

    old_password = form.cleaned_data['old_password']
    new_password = form.cleaned_data['new_password2']

    # user = User.objects.get(id=request.user.id)

    if not request.user.check_password(old_password):
        messages.error(request, "Your old password didn't match")
        return render(request, template_name, {'form': form})
        # raise ValidationError('Your old password didnt match')

    request.user.set_password(new_password)
    request.user.save()

    return redirect("home")
Example #4
0
File: views.py Project: 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
Example #5
0
    def post(self, request):
        user = request.user
        form = ChangePasswordForm(user, request.POST)
        if form.is_valid():
            user.set_password(form.cleaned_data["password1"])
            user.save()

            return {"redirect": "/account/profile"}

        return {'form': form}
Example #6
0
    def post(self: object, request: object) -> object:
        """Post request password view."""
        change_password_form = ChangePasswordForm(request.POST)

        if change_password_form.is_valid():
            return AuthenticationHandler.change_password_handler(
                request, change_password_form)

        return JsonResponse({
            'message':
            AuthenticationHandler.form_erors(change_password_form)
        })
Example #7
0
def password(request):
    if request.method == 'GET':

        return render(request, 'account/pages/account.html',
                      {'form': ChangePasswordForm(request.user)})
    else:

        form = ChangePasswordForm(request.user, request.POST)

        if form.is_valid():
            user = request.user
            user.set_password(form.cleaned_data['new_password1'])
            user.save()
            return render(request, 'account/pages/account.html', {'form': form})
Example #8
0
def change_password(request):
    if request.method == 'POST':
        form = ChangePasswordForm(request.POST)
        if form.is_valid():
            request.user.set_password(form.cleaned_data['passwd'])
            request.user.save()
            return redirect(
                request,
                'src-home',
                query_string={request.url_name: 'True'}
            )
    else:
        form = ChangePasswordForm()
    params = {'form': form}
    params.update(csrf(request))
    return response(request, params)
Example #9
0
 def post(request):
     try:
         token = request.GET['token']
         account = Account.objects.get(forget_password_token=token)
         form = ChangePasswordForm(request.POST)
         if form.is_valid():
             password = form.cleaned_data['password1']
             account.user.set_password(password)
             account.user.save()
             messages.add_message(request, messages.SUCCESS,
                                  "رمز عبور شما تغییر کرد")
             return redirect(reverse('home'))
         return render(request, 'account/change_password.html',
                       {'form': form})
     except (Account.DoesNotExist, KeyError):
         return render(request, 'general/404.html', status=404)
Example #10
0
def change_password(request):

    user = User.objects.get(email=request.user.email)
    if request.method == 'POST':
        form = ChangePasswordForm(request.POST)
        if form.is_valid():
            if check_password(request.POST['password'],
                              user.password):  #현재 비밀번호 확인
                print('Okay')
                user.set_password(request.POST['password1'])  # 새로운 비밀번호 저장.
                user.save()
                return redirect('root')
            else:
                print('Fail to change password')  # message로 에러 발생 시키기
    else:
        form = ChangePasswordForm()

    return render(request, 'account/change.html', {'form': form})
Example #11
0
 def get(request):
     try:
         token = request.GET['token']
         Account.objects.get(forget_password_token=token)
         form = ChangePasswordForm()
         return render(request, 'account/change_password.html',
                       {'form': form})
     except (Account.DoesNotExist, KeyError):
         return render(request, 'general/404.html', status=404)
Example #12
0
def PasswordChange(request):
    user = request.user
    if request.method == 'POST':
        form = ChangePasswordForm(request.POST)
        if form.is_valid():
            new_password = form.cleaned_data.get('new_password')
            user.set_password(new_password)
            user.save()
            update_session_auth_hash(request, user)
            return redirect('change_password_done')
    else:
        form = ChangePasswordForm(instance=user)

    context = {
        'form': form,
    }

    return render(request, 'account/change_password.html', context)
Example #13
0
def change_password(request):
    form = ChangePasswordForm(request.POST)
    if not form.is_valid():
        return HttpResponse(status=400, content="Must fill in all fields")

    password = form.cleaned_data["password"]
    repassword = form.cleaned_data["repassword"]
    oldpassword = form.cleaned_data['oldpassword']

    if password != repassword:
        return HttpResponse(status=400, content="New passwords do not match")

    if not request.user.check_password(oldpassword):
        return HttpResponse(status=400, content="Old password is incorrect")

    request.user.set_password(password)
    request.user.save()
    return HttpResponse(status=200)
Example #14
0
def change_password(request):
    if request.user.is_authenticated:
        if request.method == 'POST':
            form = ChangePasswordForm(request.POST)
            if form.is_valid():
                print('1')
                cd = form.cleaned_data
                # if current user's password is same as old_password , return true
                user = request.user.check_password(cd['old_password'])
                if user:
                    if cd['new_password1'] == cd['new_password2']:
                        request.user.set_password(cd['new_password1'])
                        request.user.save()
                        return redirect('/login')
                return render(request, 'account/changepassword.html')

        return render(request, 'account/changepassword.html')

    return redirect('/login')
Example #15
0
def profile(request):
    """Render profile view."""
    user = request.user
    if request.method == 'POST':
        form = ChangePasswordForm(request.POST)

        if form.is_valid():
            new_password = form.cleaned_data.get('new_password')

            user.set_password(new_password)
            user.save()
            update_session_auth_hash(request, user)
            return redirect('profile')
        else:
            messages.error(request, _('No se pudo modificar su contraseña'))
    else:
        form = ChangePasswordForm(instance=user)

    return render(request, 'account/profile.html', {'form': form})
Example #16
0
def change_password_view(request):
    if request.POST:
        form = ChangePasswordForm(request.user, request.POST)
        if form.is_valid():
            data = form.cleaned_data
            request.user.set_password(data['confirm_new_password'])
            request.user.save()
            user = authenticate(usernname=request.user.username, password=data['confirm_new_password'])
            login(request, user)

            print('successfullllllllllll')
            return HttpResponseRedirect(reverse('account:change_password'))
        else:
            return render(request,
                          'account/change_password.html',
                          {'form': form})
    else:
        return render(request,
                      'account/change_password.html',
                      {'form': ChangePasswordForm(request.user)})
Example #17
0
def password(request):
    """Render view password view."""
    user = request.user
    if request.method == 'POST':
        form = ChangePasswordForm(request.POST)
        if form.is_valid():
            new_password = form.cleaned_data.get('new_password')

            user.set_password(new_password)
            user.save()
            update_session_auth_hash(request, user)

            messages.success(request,
                             _('Su contraseña se guardo correctamente.'))

            return redirect('account:password')
    else:
        form = ChangePasswordForm(instance=user)

    return render(request, 'account/password.html', {'form': form})
Example #18
0
def index(request):
    c = RequestContext(request)
    c["user"] = request.user
    c["form"] = {}

    c["form"]["addvideo"] = AddVideoForm()
    c["form"]["addtimestamp"] = AddTimestampForm()

    if request.user.id != None:
        t = get_template("loggedin.html")
        c["form"]["account"] = ChangePasswordForm()
    else:
        t = get_template("loggedout.html")
        c["form"]["login"] = LoginForm()
        c["form"]["register"] = RegisterForm()

    html = t.render(c)
    return HttpResponse(html)
Example #19
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)
Example #20
0
def get_change():
    return ChangePasswordForm()
Example #21
0
            pattern_kwargs={}),
 ViewConfig(pattern=r"^account/confirm_email/(?P<key>\w+)/$",
            template="account/email_confirm.html",
            name="account_confirm_email",
            pattern_kwargs={"key": "abc"},
            confirmation={
                "key": "foo",
                "email_address": {
                    "email": "*****@*****.**"
                }
            }),
 ViewConfig(pattern=r"^account/password/$",
            template="account/password_change.html",
            name="account_password",
            pattern_kwargs={},
            form=ChangePasswordForm(user=None)),
 ViewConfig(pattern=r"^account/password/reset/$",
            template="account/password_reset.html",
            name="account_password_reset",
            pattern_kwargs={},
            form=PasswordResetForm()),
 ViewConfig(
     pattern=
     r"^account/password/reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$",
     template="account/password_reset_token.html",
     name="account_password_reset_token",
     pattern_kwargs={
         "uidb36": "aaa",
         "token": "123"
     },
     form=PasswordResetTokenForm()),