コード例 #1
0
ファイル: views.py プロジェクト: ginking/gallery
def password_change(request):
    form = PasswordChangeForm(request.POST or None, instance=request.user)
    if form.is_valid():
        form.save()
        messages.success(request, PASSWORD_CHANGE_MESSAGE)
        return redirect(reverse('accounts:password_change'))
    context = {'form': form}
    return render(request, 'accounts/password_change.html', context)
コード例 #2
0
def PasswordChangeView(request, slug):
    user = get_object_or_404(UserModel, slug=slug)
    if request.method == 'POST':
        password_form = PasswordChangeForm(data=request.POST)
        if password_form.is_valid():
            current_password = password_form.cleaned_data.get(
                'current_password')
            logged_in = authenticate(request,
                                     username=user.username,
                                     password=current_password)

            if logged_in is not None:
                new_password = password_form.cleaned_data.get('new_password')
                try:
                    validate_password(new_password,
                                      user=user,
                                      password_validators=None)
                    user.set_password(new_password)
                    user.save()
                    if user.is_superuser:
                        return HttpResponseRedirect(
                            reverse('accounts:profile',
                                    kwargs={'slug': user.slug}))
                    if user.is_masteruser:
                        return HttpResponseRedirect(
                            reverse('masteruser:profile',
                                    kwargs={'slug': user.slug}))
                    if user.is_sportclub:
                        return HttpResponseRedirect(
                            reverse('sportclub:profile',
                                    kwargs={'slug': user.slug}))
                    if user.is_commonuser:
                        return HttpResponseRedirect(
                            reverse('commonuser:profile',
                                    kwargs={'slug': user.slug}))
                except:
                    error1 = 'کلمه عبور باید بیش از 6 کاراکتر باشد'
                    error2 = 'کلمه عبور باید نمیتواند شامل نام کاربری باشد'
                    error3 = 'کلمه عبور نمیتواند خیلی ساده باشد'
                    return render(
                        request, 'accounts/passwordchange.html', {
                            'form': password_form,
                            'error1': error1,
                            'error2': error2,
                            'error3': error3
                        })
            else:
                error4 = 'رمزعبور وارد شده صحیح نیست'
                return render(request, 'accounts/passwordchange.html',
                              {'error4': error4})
    else:
        password_form = PasswordChangeForm()
        return render(request, 'accounts/passwordchange.html',
                      {'form': password_form})
コード例 #3
0
ファイル: views.py プロジェクト: KdJohar/oposod
def change_password(request):
    form = PasswordChangeForm(request.user, request.POST or None)
    if form.is_valid():
        new_password = form.cleaned_data['new_password']
        User.objects.filter(id=request.user.id).update(password=make_password(new_password))
        messages.info(request, 'Your password has been change sucessfully.')
        return HttpResponseRedirect(reverse('accounts.views.change_password'))

    return render(request,
                  'accounts/change_password.html', {
                      'form': form,
                  }, )
コード例 #4
0
ファイル: views.py プロジェクト: PathosEthosLogos/teerace
def password_change(request):
    form = PasswordChangeForm(current_user=request.user)
    if request.method == 'POST':
        form = PasswordChangeForm(request.POST, current_user=request.user)
        if form.is_valid():
            form.save()
            messages.success(request, "Successfully changed your password.")
    messages.warning(request, "<b>Make sure you want to do this!</b>"
                     " No, really. This action will change your password.",
                     extra_tags="hide")
    return {
        'form': form,
    }
コード例 #5
0
ファイル: views.py プロジェクト: SushiTee/teerace
def password_change(request):
	form = PasswordChangeForm(current_user=request.user)
	if request.method == 'POST':
		form = PasswordChangeForm(request.POST, current_user=request.user)
		if form.is_valid():
			form.save()
			messages.success(request, "Successfully changed your password.")
	messages.warning(request, "<b>Make sure you want to do this!</b>"
		" No, really. This action will change your password.",
		extra_tags="hide")
	return {
		'form': form,
	}
コード例 #6
0
def password_change_view(request):
    if request.method == 'POST':
        form = PasswordChangeForm(data=request.POST, user=request.user)

        if form.is_valid():
            form.save()
            messages.success(request, 'You have changed your password...')
            return redirect('accounts:home')

    else:
        form = PasswordChangeForm(user=request.user)

    context = {'form': form}

    return render(request, 'accounts/password_change.html', context)
コード例 #7
0
ファイル: views.py プロジェクト: thanhhoangila/screenbird
def manage_account(request):
    """
    Updates the user's account information.
    If user is an oauth_user, user cannot update password.
    
    """
    user = request.user
    oauth_user = UserSocialAuth.objects.filter(user=user)
    if oauth_user.exists() and oauth_user.count() >= 1:
        oauth_user = oauth_user[0]
    else:
        oauth_user = None

    try:
        userprofile = UserProfile.objects.get(user=user)
    except UserProfile.DoesNotExist:
        userprofile = UserProfile(user=user)
        userprofile = userprofile.save()
    pass_form = PasswordChangeForm(user=user)
    userprof_form = UserProfileUpdateForm()
    user_form = UsernameChangeForm()
    context = {}
    if request.method == "POST":
        userprof_form = UserProfileUpdateForm(request.POST,
                                              instance=userprofile)
        user_form = UsernameChangeForm(request.POST, instance=user)
        pass_form = PasswordChangeForm(user=user, data=request.POST)
        if 'username_update' in request.POST:
            if user_form.is_valid():
                user_form.save()
                return redirect('account_info')
        elif 'userprofile' in request.POST:
            if userprof_form.is_valid():
                userprof_form.save()
                return redirect('account_info')
        elif 'change_password' in request.POST:
            if pass_form.is_valid():
                pass_form.save()
                return redirect('account_info')
    else:
        userprof_form = UserProfileUpdateForm(instance=userprofile)
        user_form = UsernameChangeForm(instance=user)
        pass_form = PasswordChangeForm(user=user)
    context['oauth_user'] = oauth_user
    context['pass_form'] = pass_form
    context['userprof_form'] = userprof_form
    context['user_form'] = user_form
    return render(request, 'account_manage.html', context)
コード例 #8
0
ファイル: views.py プロジェクト: 465060874/screenbird
def manage_account(request):
    """
    Updates the user's account information.
    If user is an oauth_user, user cannot update password.
    
    """
    user = request.user
    oauth_user = UserSocialAuth.objects.filter(user=user)
    if oauth_user.exists() and oauth_user.count() >= 1:
        oauth_user = oauth_user[0]
    else:
        oauth_user = None

    try:
        userprofile = UserProfile.objects.get(user=user)
    except UserProfile.DoesNotExist:
        userprofile = UserProfile(user=user)
        userprofile = userprofile.save()
    pass_form = PasswordChangeForm(user=user)
    userprof_form = UserProfileUpdateForm()
    user_form = UsernameChangeForm()
    context = {}
    if request.method == "POST":
        userprof_form = UserProfileUpdateForm(request.POST, instance=userprofile)
        user_form = UsernameChangeForm(request.POST, instance=user)
        pass_form = PasswordChangeForm(user=user, data=request.POST)
        if 'username_update' in request.POST:
            if user_form.is_valid():
                user_form.save()
                return redirect('account_info')
        elif 'userprofile' in request.POST:
            if userprof_form.is_valid():
                userprof_form.save()
                return redirect('account_info')
        elif 'change_password' in request.POST:
            if pass_form.is_valid():
                pass_form.save()
                return redirect('account_info')
    else:
        userprof_form = UserProfileUpdateForm(instance=userprofile)
        user_form = UsernameChangeForm(instance=user)
        pass_form = PasswordChangeForm(user=user)
    context['oauth_user'] = oauth_user
    context['pass_form'] = pass_form
    context['userprof_form'] = userprof_form
    context['user_form'] = user_form
    return render(request, 'account_manage.html', context)
コード例 #9
0
def change_password(request):
    if request.method == 'POST':
        form = PasswordChangeForm(data=request.POST, user=request.user)

        if form.is_valid():
            form.save()
            update_session_auth_hash(request, form.user)
            messages.success(request, "Password has changed successfully!")
            return redirect(reverse('profile'))
        else:
            messages.error(
                request, "There was something wrong with the given passwords!")
            return redirect('change_password')
    else:
        form = PasswordChangeForm(user=request.user)
        args = {'form': form}
        return render(request, 'change-password.html', args)
コード例 #10
0
ファイル: views.py プロジェクト: tysonblacker/econvenor
def password_change(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('index'))

    if request.method == "POST":
        form = PasswordChangeForm(request.user, request.POST, label_suffix='')
        if form.is_valid():
            form.save()
            snapshot_user_details(request.user, password='******')
            return HttpResponseRedirect(reverse('password-changed'))
    else:
        form = PasswordChangeForm(request.user, label_suffix='')

    menu = {'parent': 'account'}
    return render(request, 'password_change.html', {
                  'menu': menu,
                  'form': form,
                  })
コード例 #11
0
    def post(self, request, *args, **kwargs):
        form = PasswordChangeForm(request.POST, instance=request.user)

        if form.is_valid():
            request.user.set_password(form.cleaned_data['password'])
            request.user.save()

            messages.success(request, 'Password updated!', extra_tags='success')
            return HttpResponseRedirect(reverse('profile_settings_password_view'))
        else:
            context = {
                'page_title': 'Update Password',
                'location': 'profile_settings',
                'sublocation': 'password',
                'form': form
            }

            return render(request, 'neo/profile/settings/password.html', context)
コード例 #12
0
ファイル: views.py プロジェクト: unpatioli/realtors
def password_change(request):
    user = get_object_or_404(User, pk = request.user.pk)
    if request.method == "POST":
        form = PasswordChangeForm(request.POST, user=user)
        if form.is_valid():
            user.set_password(form.cleaned_data['password'])
            user.save()
            messages.success(request, u"Пароль изменен")
            return redirect('accounts_my_profile')
        else:
            messages.error(request, u"Пароль не изменен")
    else:
        form = PasswordChangeForm(user=user)
    
    return direct_to_template(
        request,
        template = "accounts/password_change_form.html",
        extra_context = {'form': form}
    )
コード例 #13
0
def password_change(request, user_id):
    if not request.user.is_authenticated:
        return JsonResponse({'code': 0, "message": "error"})
    curr_user = get_object_or_404(BlogUser, id=user_id)
    if request.method == 'POST':
        form = PasswordChangeForm(request.POST)
        if form.is_valid():
            password = form.cleaned_data.get('old_username')
            username = curr_user.username
            user = auth.authenticate(username=username, password=password)
            if user is not None:
                new_password = form.cleaned_data.get('password2')
                user.set_password(new_password)
                user.save()
                return JsonResponse({'code': 1, 'message': 'Password Change Success'})
            else:
                return render(request, 'accounts/password_change.html', {'form': form})
    else:
        form = PasswordChangeForm()
        return render(request, 'accounts/password_change.html', {'form': form})
コード例 #14
0
ファイル: views.py プロジェクト: spc-12/weblate
def password(request):
    """
    Password change / set form.
    """

    do_change = False

    if request.user.has_usable_password():
        if request.method == "POST":
            change_form = PasswordChangeForm(request.POST)
            if change_form.is_valid():
                cur_password = change_form.cleaned_data["password"]
                if request.user.check_password(cur_password):
                    do_change = True
                else:
                    messages.error(request, _("You have entered an invalid password."))
        else:
            change_form = PasswordChangeForm()
    else:
        do_change = True
        change_form = None

    if request.method == "POST":
        form = PasswordForm(request.POST)
        if form.is_valid() and do_change:

            # Clear flag forcing user to set password
            if "show_set_password" in request.session:
                del request.session["show_set_password"]

            request.user.set_password(form.cleaned_data["password1"])
            request.user.save()
            messages.info(request, _("Your password has been changed."))
            return redirect("profile")
    else:
        form = PasswordForm()

    return render_to_response(
        "accounts/password.html",
        RequestContext(request, {"title": _("Change password"), "change_form": change_form, "form": form}),
    )
コード例 #15
0
def PasswordChangeView(request,slug):
    user = get_object_or_404(UserModel,slug = slug)
    if request.method == 'POST':
        password_form = PasswordChangeForm(data = request.POST)
        if password_form.is_valid():
            current_password = password_form.cleaned_data.get('current_password')
            logged_in = authenticate(request, username=user.username, password=current_password)

            if logged_in is not None:
                if password_form.cleaned_data.get('new_password') == password_form.cleaned_data.get('confirm_password'):
                    new_password = password_form.cleaned_data.get('new_password')
                    try:
                        validate_password(new_password,user=user, password_validators=None)
                        user.set_password(new_password)
                        user.save()
                        return HttpResponseRedirect(reverse('login'))
                    except:
                        error1 ='کلمه عبور باید بیش از 6 کاراکتر باشد'
                        error2 ='کلمه عبور باید نمیتواند شامل نام کاربری باشد'
                        error3 ='کلمه عبور نمیتواند خیلی ساده باشد'
                        return render(request,'accounts/passwordchange.html',{'form':password_form,'error1':error1,'error2':error2,'error3':error3})
                else:
                    error4 = 'رمز های وارد شده با هم مطابقت ندارند'
                    password_form = PasswordChangeForm()
                    return  render(request,'accounts/passwordchange.html',
                                          {'error4':error4,'form':password_form})

            else:
                error4 = 'رمزعبور وارد شده صحیح نیست'
                password_form = PasswordChangeForm()
                return  render(request,'accounts/passwordchange.html',
                                      {'error4':error4,'form':password_form})
    else:
        password_form = PasswordChangeForm()
        return  render(request,'accounts/passwordchange.html',
                              {'form':password_form})
コード例 #16
0
 def test_form_error_not_required_fields(self):
     form = PasswordChangeForm(data={})
     self.assertFalse(form.is_valid())
コード例 #17
0
 def test_all_fields_are_required(self):
     form = PasswordChangeForm(self.user, data={'wrong': 'data'})
     form.is_valid()
     self.assertTrue(
         all([form.has_error(f, 'required') for f in form.fields]))
コード例 #18
0
ファイル: tests.py プロジェクト: AlinaSadovskaya/marshutka
 def test_password_change_form(self):
     user = User.objects.create_user('John', '*****@*****.**', 'johnpassword')
     user.save()
     data = {'old_password': "******", 'new_password1': "fdsgsdfgfdg", 'new_password2': "fdsgsdfgfdg"}
     form = PasswordChangeForm(user=user, data=data)
     self.assertTrue(form.is_valid())