示例#1
0
文件: views.py 项目: robbie/anthill
def change_password(request):
    user = request.user
    password_form = PasswordForm(request.POST)
    form = _user_to_profileform(user)
    if password_form.is_valid():
        user.set_password(password_form.cleaned_data['password1'])
        user.save()
        user.message_set.create(message='Password changed.')
        password_form = PasswordForm()
    else:
        user.message_set.create(message='Passwords did not match.')
    return redirect('edit_profile')
示例#2
0
def change_password(request):
    """
        POST endpoint that validates password and redirects to edit_profile
    """
    user = request.user
    password_form = PasswordForm(request.POST)
    form = _user_to_profileform(user)
    if password_form.is_valid():
        user.set_password(password_form.cleaned_data['password1'])
        user.save()
        messages.success(request, 'Password changed.')
        password_form = PasswordForm()
    else:
        messages.success(request, 'Passwords did not match.')
    return redirect('edit_profile')
示例#3
0
def change_password(request):
    """
        POST endpoint that validates password and redirects to edit_profile
    """
    user = request.user
    password_form = PasswordForm(request.POST)
    form = _user_to_profileform(user)
    if password_form.is_valid():
        user.set_password(password_form.cleaned_data['password1'])
        user.save()
        messages.success(request, 'Password changed.')
        password_form = PasswordForm()
    else:
        messages.success(request, 'Passwords did not match.')
    return redirect('edit_profile')
示例#4
0
def edit_profile(request):
    """
        Edit profile (and User details) of logged in user.

        Template: people/edit_profile.html

        Context:
            form          - ``ProfileForm``
            password_form - ``anthill.people.forms.PasswordForm``
    """
    password_form = PasswordForm()

    if request.method == 'POST':
        form = ProfileForm(request.POST, request.FILES)
        if form.is_valid():
            user = request.user
            profile = user.profile
            user.first_name = form.cleaned_data['name']
            user.email = form.cleaned_data['email']
            profile.twitter_id = form.cleaned_data['twitter_id']
            profile.url = form.cleaned_data['url']
            profile.role = form.cleaned_data['position']
            profile.location = form.cleaned_data['location']
            profile.skills = form.cleaned_data['skills']
            profile.about = form.cleaned_data['about']
            user.save()
            profile.save()
            messages.success(request, 'Saved profile changes.')
    else:
        form = _user_to_profileform(request.user)
    return render_to_response('people/edit_profile.html', {
        'form': form,
        'password_form': password_form
    },
                              context_instance=RequestContext(request))