예제 #1
0
def password(request):
    '''
    Password change / set form.
    '''
    if settings.DEMO_SERVER and request.user.username == 'demo':
        return deny_demo(request)

    do_change = False

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

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

            # Clear flag forcing user to set password
            redirect_page = '#auth'
            if 'show_set_password' in request.session:
                del request.session['show_set_password']
                redirect_page = ''

            request.user.set_password(
                form.cleaned_data['password1']
            )
            request.user.save()

            # Update session hash
            update_session_auth_hash(request, request.user)

            messages.success(
                request,
                _('Your password has been changed.')
            )
            return redirect_profile(redirect_page)
    else:
        form = PasswordForm()

    return render(
        request,
        'accounts/password.html',
        {
            'title': _('Change password'),
            'change_form': change_form,
            'form': form,
        }
    )
예제 #2
0
def password(request):
    '''
    Password change / set form.
    '''
    if appsettings.DEMO_SERVER and request.user.username == 'demo':
        return deny_demo(request)

    do_change = False

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

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

            # Clear flag forcing user to set password
            redirect_page = '#auth'
            if 'show_set_password' in request.session:
                del request.session['show_set_password']
                redirect_page = ''

            request.user.set_password(
                form.cleaned_data['password1']
            )
            request.user.save()

            # Update session hash
            update_session_auth_hash(request, request.user)

            messages.success(
                request,
                _('Your password has been changed.')
            )
            return redirect_profile(redirect_page)
    else:
        form = PasswordForm()

    return render(
        request,
        'accounts/password.html',
        {
            'title': _('Change password'),
            'change_form': change_form,
            'form': form,
        }
    )
예제 #3
0
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,
            }
        )
    )
예제 #4
0
파일: views.py 프로젝트: D-storm/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(
        request,
        'accounts/password.html',
        {
            'title': _('Change password'),
            'change_form': change_form,
            'form': form,
        }
    )
예제 #5
0
def password(request):
    """Password change / set form."""
    if settings.DEMO_SERVER and request.user.username == 'demo':
        return deny_demo(request)

    do_change = False

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

    if request.method == 'POST':
        form = SetPasswordForm(request.user, request.POST)
        if form.is_valid() and do_change:

            # Clear flag forcing user to set password
            redirect_page = '#auth'
            if 'show_set_password' in request.session:
                del request.session['show_set_password']
                redirect_page = ''

            # Change the password
            user = form.save()

            # Updating the password logs out all other sessions for the user
            # except the current one.
            update_session_auth_hash(request, user)

            # Change key for current session
            request.session.cycle_key()

            messages.success(request, _('Your password has been changed.'))
            notify_account_activity(request.user, request, 'password')
            return redirect_profile(redirect_page)
    else:
        form = SetPasswordForm(request.user)

    return render(request, 'accounts/password.html', {
        'title': _('Change password'),
        'change_form': change_form,
        'form': form,
    })
예제 #6
0
파일: views.py 프로젝트: josben77/weblate
def password(request):
    """
    Password change / set form.
    """
    if appsettings.DEMO_SERVER and request.user.username == "demo":
        return deny_demo(request)

    do_change = False

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

    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()

            # Update session hash for Django 1.7
            if update_session_auth_hash:
                update_session_auth_hash(request, request.user)

            messages.success(request, _("Your password has been changed."))
            return redirect("profile")
    else:
        form = PasswordForm()

    return render(
        request, "accounts/password.html", {"title": _("Change password"), "change_form": change_form, "form": form}
    )