Ejemplo n.º 1
0
def password_update(request, email):
    user = get_object_or_404(User, email=email)
    if request.user != user:
        raise PermissionDenied
    form = UserPasswordChangeForm(data=request.POST or None, user=user)
    if request.method == 'POST':
        if form.is_valid():
            form.save()
            return redirect('login')

    context = {'form': form}
    return render(request, 'profiles/edit.html', context)
Ejemplo n.º 2
0
 def dispatch(self, request, *args, **kwargs):
     action = request.POST.get('action')
     self.profile_form = UserProfileForm(
         (request.POST if action == 'profile' else None),
         (request.FILES if action == 'profile' else None),
         prefix='profile',
         instance=request.user)
     self.password_form = UserPasswordChangeForm(
         request.user, (request.POST if action == 'password' else None),
         prefix='password')
     self.email_form = UserEmailChangeForm(
         request.user, (request.POST if action == 'email' else None),
         prefix='email')
     return super(UserSettingsView, self).dispatch(request, *args, **kwargs)
Ejemplo n.º 3
0
 def get(self, request):
     user = request.user
     edit_user_form = EditUserProfileForm(instance=user)
     change_password_form = UserPasswordChangeForm(user)
     return render(request, 'edit_profile.html', {
         'edit_user_form': edit_user_form,
         'form': change_password_form
     })
Ejemplo n.º 4
0
class UserSettingsView(TemplateView):
    template_name = 'users/settings.html'

    @method_decorator(login_required)
    def dispatch(self, request, *args, **kwargs):
        action = request.POST.get('action')
        self.profile_form = UserProfileForm(
            (request.POST if action == 'profile' else None),
            (request.FILES if action == 'profile' else None),
            prefix='profile',
            instance=request.user)
        self.password_form = UserPasswordChangeForm(
            request.user, (request.POST if action == 'password' else None),
            prefix='password')
        self.email_form = UserEmailChangeForm(
            request.user, (request.POST if action == 'email' else None),
            prefix='email')
        return super(UserSettingsView, self).dispatch(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(UserSettingsView, self).get_context_data(**kwargs)
        context['profile_form'] = self.profile_form
        context['password_form'] = self.password_form
        context['email_form'] = self.email_form
        return context

    def post(self, request, *args, **kwargs):
        if self.profile_form.is_valid():
            self.profile_form.save()
            messages.success(request, _(u'Профиль успешно сохранен.'))
            return redirect(request.path)
        elif self.password_form.is_valid():
            self.password_form.save()
            request.user.backend = request.session[BACKEND_SESSION_KEY]
            login(request, request.user)
            messages.success(request, _(u'Пароль успешно изменен.'))
            return redirect(request.path)
        elif self.email_form.is_valid():
            self.email_form.save()
            messages.success(request, _(u'Email успешно изменен.'))
            return redirect(request.path)
        return self.get(request, *args, **kwargs)
Ejemplo n.º 5
0
 def dispatch(self, request, *args, **kwargs):
     action = request.POST.get('action')
     self.profile_form = UserChangeProfileForm(
             (request.POST if action == 'profile' else None),
             (request.FILES if action == 'profile' else None),
             instance=request.user, prefix='profile'
     )
     self.password_form = UserPasswordChangeForm(request.user, (request.POST if action == 'password' else None),
                                                 prefix='password')
     self.email_form = UserEmailChangeForm(request.user, request.POST if action == 'email' else None, prefix='email')
     return super(UserSettingsView, self).dispatch(request, *args, **kwargs)
Ejemplo n.º 6
0
 def post(self, request):
     user = request.user
     form = EditUserProfileForm(request.POST, instance=user)
     change_password_form = UserPasswordChangeForm(user)
     if form.is_valid():
         form.save()
         return redirect('user_profile')
     else:
         return render(request, 'edit_profile.html', {
             'edit_user_form': form,
             'form': change_password_form
         })
Ejemplo n.º 7
0
class UserSettingsView(TemplateView):
    template_name = 'users/settings.html'

    @method_decorator(login_required)
    def dispatch(self, request, *args, **kwargs):
        action = request.POST.get('action')
        self.profile_form = SettingsForm(
            (request.POST if action == 'profile' else None),
            (request.FILES if action == 'profile' else None),
            prefix='profile', instance=request.user
        )
        self.password_form = UserPasswordChangeForm(request.user, (request.POST if action == 'password' else None),
                                                    prefix='password')
        self.email_form = UserEmailChangeForm(request.user, (request.POST if action == 'email' else None),
                                              prefix='email')
        return super(UserSettingsView, self).dispatch(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(UserSettingsView, self).get_context_data(**kwargs)
        context['profile_form'] = self.profile_form
        context['password_form'] = self.password_form
        context['email_form'] = self.email_form
        return context

    def post(self, request, *args, **kwargs):
        if self.profile_form.is_valid():
            self.profile_form.save()
            messages.success(request, _(u'Profile success update.'))
            return redirect(request.path)
        elif self.password_form.is_valid():
            self.password_form.save()
            request.user.backend = request.session[BACKEND_SESSION_KEY]
            login(request, request.user)
            messages.success(request, _(u'Password success update.'))
            return redirect(request.path)
        elif self.email_form.is_valid():
            self.email_form.save()
            messages.success(request, _(u'Email success update.'))
            return redirect(request.path)
        return self.get(request, *args, **kwargs)