예제 #1
1
파일: views.py 프로젝트: lucekdudek/embigo
def edit_user(request):
    """
    Display forms for edit user

    **Context**
        user
        set password form
        notification

    **Template:**
    :template:`edit_user.html`
    """
    user = User.objects.get(id=request.user.id)
    form = PasswordChangeForm(None)
    notification = None
    if request.method == 'POST':
        if request.POST.get('changePassword'):
            form = PasswordChangeForm(user, request.POST)
            if form.is_valid():
                form.save()
                notification = 'Hasło zostało zmienione! :)'
                update_session_auth_hash(request, form.user)
        elif request.POST.get('changeColor'):
            embigo_user = EmbigoUser.objects.get(user=user)
            embigo_user.color = request.POST.get('color')
            embigo_user.save()
            notification = 'Zmieniono kolor avatara! :)'
    context = {
        'user': request.user,
        'form': form,
        'notification': notification
    }
    return render(request, 'edit_user.html', context)
예제 #2
0
파일: views.py 프로젝트: emulbreh/ecs
def accept_invitation(request, invitation_uuid=None):
    try:
        invitation = Invitation.objects.new().get(uuid=invitation_uuid.lower())
    except Invitation.DoesNotExist:
        raise Http404

    form = PasswordChangeForm(invitation.user, request.POST or None)
    if form.is_valid():
        user = form.save()
        user.ecs_profile.last_password_change = datetime.now()
        user.ecs_profile.phantom = False
        user.ecs_profile.save()
        invitation.accepted = True
        invitation.save()
        user = auth.authenticate(username=invitation.user.username, password=form.cleaned_data['new_password1'])
        auth.login(request, user)
        return HttpResponseRedirect(reverse('ecs.users.views.edit_profile'))

    password = uuid4().get_hex()
    invitation.user.set_password(password)
    invitation.user.save()
    form.fields['old_password'].widget = forms.HiddenInput()
    form.fields['old_password'].initial = password

    return render(request, 'users/invitation/set_password_form.html', {
        'form': form,
    })
예제 #3
0
파일: password.py 프로젝트: bgroff/kala-app
class PasswordView(LoginRequiredMixin, TemplateView):
    template_name = 'accounts/settings/password.html'

    def get_context_data(self, **kwargs):
        return {
            'form': self.form,
            'user': self.user,
        }

    def dispatch(self, request, pk, *args, **kwargs):
        self.user = get_object_or_404(get_user_model().objects.all(), pk=pk)

        if not request.user.is_superuser and request.user != self.user:
            raise PermissionDenied(_('You do not have permission to edit this user.'))

        if request.user.is_superuser:
            self.form = SetPasswordForm(self.user, request.POST or None)
        else:
            self.form = PasswordChangeForm(self.user, request.POST or None)
        return super(PasswordView, self).dispatch(request, *args, **kwargs)

    def post(self, request, *args, **kwargs):
        if self.form.is_valid():
            user = self.form.save()
            update_session_auth_hash(request, user)
            messages.success(request, _('The password has been updated.'))
            return redirect(reverse('users:password', args=[self.user.pk]))
        return self.render_to_response(self.get_context_data())
예제 #4
0
파일: views.py 프로젝트: kpx13/vv
def lk(request):
    c = get_common_context(request)
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/')
    
    user_profile = request.user.get_profile()
    c['form'] = ProfileLKForm(instance=user_profile)
    c['passform'] = PasswordChangeForm(request.user)
    
    if request.method == 'POST':
        if request.POST.get('action', '') == 'data':
            form = ProfileLKForm(request.POST, instance=user_profile)
            u = request.user
            if form.is_valid():
                form.save()
            c['form'] = form
        if request.POST.get('action', '') == 'password':
            passform = PasswordChangeForm(request.user, request.POST)
            if passform.is_valid():
                passform.save()
                messages.success(request, u'Вы успешно сменили пароль.')
                return HttpResponseRedirect('/edu/cabinet/')
            else:
                c['passform'] = passform
    c['title'] = u'Личный кабинет'
    
    return render_to_response('lk.html', c, context_instance=RequestContext(request))
예제 #5
0
파일: views.py 프로젝트: KWMalik/codenode
def usersettings(request, template_name='usersettings/usersettings.html'):
    """Render a Users settings page.

    If this is the first time a user is visting the settings page,
    a default settings instance is created for this user.
    """
    try:
        profile = request.user.get_profile()
    except models.UserSettings.DoesNotExist:
        s = models.UserSettings(user=request.user)
        s.save()
        profile = request.user.get_profile()
    if request.method == "POST":
        userform = forms.UserForm(data=request.POST, instance=request.user)
        passform = PasswordChangeForm(request.user, data=request.POST)
        settingsform = forms.UserSettingsForm(data=request.POST, instance=profile)
        if userform.is_valid():
            userform.save()
        if passform.is_valid():
            passform.save()
        if settingsform.is_valid():
            settingsform.save()
        redirect = request.POST.get("referer")
        return HttpResponseRedirect(redirect)
    else:
        referer = urlparse(request.META.get('HTTP_REFERER', '')).path
        if referer == '':
            referer = "/bookshelf/"
        userform = forms.UserForm(instance=request.user)
        passform = PasswordChangeForm(request.user)
        settingsform = forms.UserSettingsForm(instance=profile)
        tmpl_args = {'userform':userform, 'passform':passform, 'settingsform':settingsform, 'user':request.user, 'referer':referer}
    return render_to_response(template_name, tmpl_args)
예제 #6
0
파일: views.py 프로젝트: tdsimao/tt
def change_password(request):
    form = PasswordChangeForm(data=request.POST or None, user = request.user)
    if request.method == 'POST' and form.is_valid():
        form.save()
        return HttpResponseRedirect('/accounts/my_account/')
    context = RequestContext(request, {'form': form})
    return render_to_response('account/change_password.html', context)    
예제 #7
0
def profile(request):
    '''
        Viewing of signup details and editing of password
    '''
    context = {}

    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            form.save()
            messages.info(request, 'Password Changed.')
    else:
        form = PasswordChangeForm(request.user)

    key = Key.objects.get(email=request.user.email)
    
    #analytics
    endpoint_q = key.reports.values('api__name', 'endpoint').annotate(calls=Sum('calls')).order_by('-calls')
    endpoints = [{'endpoint':'.'.join((d['api__name'], d['endpoint'])),
                  'calls': d['calls']} for d in endpoint_q]
    date_q = key.reports.values('date').annotate(calls=Sum('calls')).order_by('date')
    context['endpoints'], context['endpoint_calls'] = _dictlist_to_lists(endpoints, 'endpoint', 'calls')
    context['timeline'] = date_q

    context['form'] = form
    context['key'] = key
    context['password_is_key'] = request.user.check_password(key.key)
    return render_to_response('locksmith/profile.html', context,
                              context_instance=RequestContext(request))
예제 #8
0
def edit_profile_password(request, form=None):
    """
        Used to give Dajax(ice) the change password page
        Renders in : modal
        Refreshes : right_content
    """
    dajax = Dajax()
    
    errors = False
    userprofile = request.user.get_profile()
    fullname = userprofile.user.get_full_name()
    nickname = userprofile.nickname
    if request.method == 'POST' and form != None:
        form = PasswordChangeForm(userprofile.user, deserialize_form(form))
        
        if form.is_valid():
            form.save()
            dajax.remove_css_class('#profile_edit_form input', 'error')
            dajax.script('modal_hide()') # Hide modal
            show_alert(dajax, 'success', 'Password was changes successfully')
        else:
            errors = True
            dajax.remove_css_class('#profile_edit_form input', 'error')
            for error in form.errors:
                dajax.add_css_class('#id_%s' % error, 'error')
            print "errors :", [i for i in form.errors]
            #show_alert(dajax, 'error', "There were errors in the form") # as it is in modal, not req
    else:
        form = PasswordChangeForm ( userprofile.user )
        html_content = render_to_string("users/passwd_form.html", locals(), RequestContext(request))
        dajax.assign("#id_modal", "innerHTML", html_content) # Populate modal
    
    
    return dajax.json()
예제 #9
0
파일: views.py 프로젝트: mpants/villagescc
def edit_settings(request):
    if request.method == 'POST':
        if 'change_settings' in request.POST:
            old_email = request.profile.settings.email
            settings_form = SettingsForm(
                request.POST, instance=request.profile.settings)
            if settings_form.is_valid():
                settings_obj = settings_form.save()
                if settings_obj.email != old_email:
                    send_new_address_email(settings_obj)
                    messages.info(request, MESSAGES['email_updated'])
                else:
                    messages.info(request, MESSAGES['settings_changed'])
                return redirect(edit_settings)
        elif 'change_password' in request.POST:
            password_form = PasswordChangeForm(request.user, request.POST)
            if password_form.is_valid():
                password_form.save()
                messages.info(request, MESSAGES['password_changed'])
                return redirect(edit_settings)
        
    if 'change_settings' not in request.POST:
        settings_form = SettingsForm(instance=request.profile.settings)
    if 'change_password' not in request.POST:
        password_form = PasswordChangeForm(request.user)
    return locals()
예제 #10
0
파일: views.py 프로젝트: ezl/chromano_trial
def profile(request):
    """ Edit profile settings """
    profile = UserProfile.objects.get(user=request.user)
    
    if 'email' in request.POST:
        form = ProfileForm(request.POST)
        if form.is_valid():
            form.save_email(profile.user)
            form.save_phone(profile)
            return HttpResponseRedirect('?')
    else:
        form = ProfileForm()
        form.initial.update({
            'email': profile.user.email,
            'phone': profile.phone_number,
        })
        
    if 'old_password' in request.POST:
        form_p = PasswordChangeForm(request.user, request.POST)
        if form_p.is_valid():
            form_p.save()
            return HttpResponseRedirect('?pc=1')
    else:
        form_p = PasswordChangeForm(request.user)
    
    return {
        'user': request.user,
        'form': form,
        'form_p': form_p,
        'title': 'Settings',
        'profile': profile,
        'updated_pass': request.GET.get('pc'),
    }
예제 #11
0
파일: views.py 프로젝트: VinDuv/ponytracker
def profile(request):
    profileform = None
    passwordform = None

    if request.method == 'POST':
        if 'update-profile' in request.POST:
            profileform = ProfileForm(request.POST, instance=request.user)
            if profileform.is_valid():
                profileform.save()
                messages.success(request, 'Profile updated successfully.')
                return redirect('profile')
        elif 'update-password' in request.POST and not settings.EXTERNAL_AUTH:
            passwordform = PasswordChangeForm(user=request.user, data=request.POST)
            if passwordform.is_valid():
                passwordform.save()
                messages.success(request, 'Password updated successfully.')
                return redirect('profile')

    if not profileform:
        profileform = ProfileForm(None, instance=request.user)
    if not passwordform and not settings.EXTERNAL_AUTH:
        passwordform = PasswordChangeForm(None)

    return render(request, 'accounts/profile.html', {
        'profileform': profileform,
        'passwordform': passwordform,
    })
예제 #12
0
 def form_valid(self, form):
     form = PasswordChangeForm(user=self.request.user,
                               data=self.request.POST)
     if form.is_valid():
         form.save()
         update_session_auth_hash(self.request, form.user)
     return HttpResponseRedirect(reverse('password_change_done'))
예제 #13
0
def change_password(request):
    if not password_management_enabled():
        raise Http404

    can_change_password = request.user.has_usable_password()

    if can_change_password:
        if request.method == 'POST':
            form = PasswordChangeForm(request.user, request.POST)

            if form.is_valid():
                form.save()
                update_session_auth_hash(request, form.user)

                messages.success(request, _("Your password has been changed successfully!"))
                return redirect('wagtailadmin_account')
        else:
            form = PasswordChangeForm(request.user)
    else:
        form = None

    return render(request, 'wagtailadmin/account/change_password.html', {
        'form': form,
        'can_change_password': can_change_password,
    })
예제 #14
0
 def test_password_verification(self):
     # The two new passwords do not match.
     user = User.objects.get(username="******")
     data = {"old_password": "******", "new_password1": "abc123", "new_password2": "abc"}
     form = PasswordChangeForm(user, data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form["new_password2"].errors, [force_unicode(form.error_messages["password_mismatch"])])
예제 #15
0
파일: user.py 프로젝트: amarh/openPLM
def change_user_password(request, obj_ref):
    """
    Manage html page for the modification of the selected
    :class:`~django.contrib.auth.models.User` password.
    It computes a context dictionary based on

    :param request: :class:`django.http.QueryDict`
    :param obj_ref: :attr:`~django.contrib.auth.models.User.username`
    :return: a :class:`django.http.HttpResponse`
    """
    if request.user.username=='test':
        return HttpResponseRedirect("/user/%s/attributes/" % request.user)
    obj, ctx = get_generic_data(request, "User", obj_ref)
    if obj.object != request.user:
        raise PermissionError("You are not the user")

    if request.method == 'POST' and request.POST:
        modification_form = PasswordChangeForm(obj, request.POST)
        if modification_form.is_valid():
            obj.set_password(modification_form.cleaned_data['new_password2'])
            obj.save()
            messages.info(request, _(u"Your password has been modified successfully."))
            return HttpResponseRedirect("/user/%s/" % obj.username)
    else:
        modification_form = PasswordChangeForm(obj)

    ctx["modification_form"] = modification_form
    return r2r('users/password.html', ctx, request)
예제 #16
0
파일: views.py 프로젝트: SEJeff/snowy
def accounts_preferences(request, template_name='accounts/preferences.html'):
    user = request.user
    profile = user.get_profile()

    if 'password_form' in request.POST:
        password_form = PasswordChangeForm(user, data=request.POST)
        if password_form.is_valid():
            password_form.save()
    else:
        password_form = PasswordChangeForm(user)

    if 'email_form' in request.POST:
        email_form = EmailChangeForm(request.POST, instance=user)
        if email_form.is_valid():
            email_form.save()
    else:
        email_form = EmailChangeForm(instance=user)

    if 'i18n_form' in request.POST:
        i18n_form = InternationalizationForm(request.POST, instance=profile)
        if i18n_form.is_valid():
            i18n_form.save()
    else:
        i18n_form = InternationalizationForm(instance=profile)

    return render_to_response(template_name,
                              {'user': user, 'i18n_form': i18n_form,
                               'password_form': password_form,
                               'email_form' : email_form},
                              context_instance=RequestContext(request))
예제 #17
0
    def post(self, request, *args, **kwargs):
        password = PasswordChangeForm(data=request.POST, instance=self.get_object(), prefix="password")

        if password.is_valid():
            return self.form_valid(password)
        else:
            return self.form_invalid(password)
예제 #18
0
def user_profile(request):
    profile, created = UserProfile.objects.get_or_create(user=request.user)
    if request.method == 'POST':
        user_form = UserForm(request.POST,instance=request.user)
        profile_form = UserProfileForm(request.POST,instance=profile)
        password_form = PasswordChangeForm(request.user,request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()

            next = request.GET.get('next', '')
            if next:
                response = HttpResponseRedirect(next)
            else:
                response = HttpResponseRedirect(reverse('reviewapp.submissionlist'))

            if password_form.changed_data:
                if password_form.is_valid():
                    password_form.save()
                    return response
            else:
                return response
    else:
        user_form = UserForm(instance=request.user)
        profile_form = UserProfileForm(instance=profile)
        password_form = PasswordChangeForm(request.user)

    return render_to_response('reviewapp/user_profile.html', locals(),
        context_instance=RequestContext(request))
예제 #19
0
파일: views.py 프로젝트: GearL/landlord
 def post(self, request):
     form = PasswordChangeForm(request.user, request.POST)
     if not form.is_valid():
         return render(request, 'account/reset-password.html',
                       {'form': form})
     form.save()
     return HttpResponseRedirect(reverse('home'))
예제 #20
0
def my_change_password(request):
    try:
        if request.method == 'POST':
            form = PasswordChangeForm(data=request.POST, user=request.user)
            if form.is_valid():
                # change password
                #raise Exception("EL USUARIO: " + request.user.username)
                #raise Exception("EL pwd: " + str(request.POST['new_password1']).strip())
                u = User.objects.get(username=request.user.username)
                u.set_password(str(request.POST['new_password1']).strip())
                u.save()
                # logout
                logout(request)
                # return to index page
                return redirect('/index/')
            else:
                context = {'form': form, 'is_login':'******'}
                return TemplateResponse(request, 'crpt201511/change_password.html', context)
        else:
            form = PasswordChangeForm(request)
            context = {'form': form,
                       'is_login':'******',
                }
            return TemplateResponse(request, 'crpt201511/change_password.html', context)
    except:
        if debug_is_on():
            raise
        else:
            return redirect("/index/", context_instance=RequestContext(request))
예제 #21
0
파일: views.py 프로젝트: nickpegg/home
def profile(request):
    form = UserForm(instance=request.user)
    pwd_form = PasswordChangeForm(request.user)
    
    associations = {'twitter': False, 'google_oauth2': False, 'github': False}
    for association in request.user.social_auth.all():
        associations[association.provider.replace('-', '_')] = True
    
    if request.method == 'POST':
        if request.POST.get('do_password'):
            pwd_form = PasswordChangeForm(request.user, request.POST)

            if pwd_form.is_valid():
                pwd_form.save()
                messages.success(request, "Password successfully changed.")
            else:
                messages.error(request, "Could not update password. See errors below.")
        elif request.POST.get('do_profile'):
            form = UserForm(request.POST, instance=request.user)
        
            if form.is_valid():
                form.save()
                messages.success(request, 'Profile successfully updated.')
            else:
                messages.error(request, 'You have an error in your profile. See below errors.')
        else:
            messages.error(request, "Er, something weird happened. Contact the site admin.")
        
    
    return render(request, 'accounts/profile.html', locals())
예제 #22
0
파일: views.py 프로젝트: knagra/farnsworth
def my_profile_view(request):
    """ The view of the profile page. """
    page_name = "Profile Page"
    if request.user.username == ANONYMOUS_USERNAME:
        return red_home(request, MESSAGES["SPINELESS"])
    userProfile = UserProfile.objects.get(user=request.user)
    change_password_form = PasswordChangeForm(
        request.user, request.POST if "submit_password_form" in request.POST else None
    )
    update_email_form = UpdateEmailForm(
        request.POST if "submit_profile_form" in request.POST else None, instance=request.user, prefix="user"
    )
    update_profile_form = UpdateProfileForm(
        request.POST if "submit_profile_form" in request.POST else None, instance=userProfile, prefix="profile"
    )
    if change_password_form.is_valid():
        change_password_form.save()
        messages.add_message(request, messages.SUCCESS, "Your password was successfully changed.")
        return HttpResponseRedirect(reverse("my_profile"))
    if update_email_form.is_valid() and update_profile_form.is_valid():
        update_email_form.save()
        update_profile_form.save()
        messages.add_message(request, messages.SUCCESS, "Your profile has been successfully updated.")
        return HttpResponseRedirect(reverse("my_profile"))
    return render_to_response(
        "my_profile.html",
        {
            "page_name": page_name,
            "update_email_form": update_email_form,
            "update_profile_form": update_profile_form,
            "change_password_form": change_password_form,
        },
        context_instance=RequestContext(request),
    )
예제 #23
0
파일: views.py 프로젝트: hexuotzo/web2
def change_pwd(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('../login/')
    #superuser = request.user.is_superuser
    views = request.session.get('view', {})
    fav = request.session.get('fav', [])
    cname = "密码修改"
    if request.method == "POST":
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            form.save()
            success = "密码修改完成"
            try:
                log_id = "%s%05d" % (datetime.datetime.now().strftime("%Y%m%d%H%M%S"),random.randint(0,10000))
                log = "change_pwd|"
                tolog(request,log,log_id)
            except:
                pass
            return render_to_response('change_pwd.html', {'success':success,
                                            'form': form,
                                            'cname':cname, 
                                            'views': views, 
                                            'fav':fav,
                                            'version':WEB2_VERSION,
                                            },context_instance=RequestContext(request))
    else:
        form = PasswordChangeForm(request.user)
    return render_to_response('change_pwd.html', {'form': form,
                                            'cname': cname,
                                            'views': views, 
                                            'fav':fav,
                                            'version':WEB2_VERSION,
                                            },context_instance=RequestContext(request))
예제 #24
0
파일: views.py 프로젝트: nherson/farnsworth
def my_profile_view(request):
    ''' The view of the profile page. '''
    page_name = "Profile Page"
    if request.user.username == ANONYMOUS_USERNAME:
        return red_home(request, MESSAGES['SPINELESS'])
    user = request.user
    userProfile = UserProfile.objects.get(user=request.user)
    change_password_form = PasswordChangeForm(
        request.user,
        request.POST if "submit_password_form" in request.POST else None,
        )
    update_profile_form = UpdateProfileForm(
        request.POST if "submit_profile_form" in request.POST else None,
        user=request.user,
        initial={
            'former_houses': userProfile.former_houses,
            'email': user.email,
            'email_visible_to_others': userProfile.email_visible,
            'phone_number': userProfile.phone_number,
            'phone_visible_to_others': userProfile.phone_visible,
            },
        )
    if change_password_form.is_valid():
        change_password_form.save()
        messages.add_message(request, messages.SUCCESS, "Your password was successfully changed.")
        return HttpResponseRedirect(reverse('my_profile'))
    if update_profile_form.is_valid():
        update_profile_form.save()
        messages.add_message(request, messages.SUCCESS, "Your profile has been successfully updated.")
        return HttpResponseRedirect(reverse('my_profile'))
    return render_to_response('my_profile.html', {
        'page_name': page_name,
        'update_profile_form': update_profile_form,
        'change_password_form': change_password_form,
        }, context_instance=RequestContext(request))
예제 #25
0
파일: views.py 프로젝트: Nilix007/mafiasi
def account_settings(request):
    password_change_form = PasswordChangeForm(request.user)
    nick_change_form = NickChangeForm(request.user)
    email_change_form = EmailChangeForm(request.user)

    form = request.POST.get('form')
    if form == 'change_pw':
        password_change_form = PasswordChangeForm(request.user, request.POST)
        if password_change_form.is_valid():
            password_change_form.save()
            messages.success(request, _("Password was changed."))
            return redirect('registration_account')
    elif form == 'change_nick':
        nick_change_form = NickChangeForm(request.user, request.POST)
        if nick_change_form.is_valid():
            nick_change_form.save()
            messages.success(request, _('Your nickname is now {}.').format(
                nick_change_form.cleaned_data['nickname']))
            return redirect('registration_account')
    elif form == 'change_email':
        email_change_form = EmailChangeForm(request.user, request.POST)
        if email_change_form.is_valid():
            return _verify_email(request,
                                 email_change_form.cleaned_data['email'])
    
    return TemplateResponse(request, 'registration/account.html', {
        'password_change_form': password_change_form,
        'nick_change_form': nick_change_form,
        'email_change_form': email_change_form,
        'username': request.user.username,
    })
예제 #26
0
파일: views.py 프로젝트: bo4rd/boarddit
def change_profile(request, username):
    if username != request.user.get_username():
        return HttpResponseForbidden

    old_email = get_object_or_404(User, username=username).email
    profile_change_form = ProfileChangeForm(prefix='profile',
                                            initial={'email': old_email})
    passwd_change_form = PasswordChangeForm(username, prefix='passwd')

    if request.method == 'POST':
        if any(['profile' in key for key in request.POST.keys()]):
            profile_change_form = ProfileChangeForm(request.POST, prefix='profile')
            if profile_change_form.is_valid():
                user = request.user
                user.email = profile_change_form.cleaned_data['email']
                user.save()

        if any(['passwd' in key for key in request.POST.keys()]):
            passwd_change_form = PasswordChangeForm(data=request.POST,
                                                    user=request.user, prefix='passwd')
            if passwd_change_form.is_valid():
                passwd_change_form.save()
                auth.update_session_auth_hash(request, passwd_change_form.user)

    return render(request, 'profile_change.html', {'form_profile': profile_change_form,
                                                   'form_passwd': passwd_change_form})
예제 #27
0
파일: views.py 프로젝트: jradd/liquid
def recruiter_account(request):
    if request.method == "POST" and request.POST.get("password_change") == "yes":
        password_form = PasswordChangeForm(request.user, data=request.POST)
        if password_form.is_valid():
            password_form.save()
            messages.add_message(request, messages.SUCCESS, "Password changed")
    else:
        password_form = PasswordChangeForm(request.user)

    if request.method == "POST" and request.POST.get("email_change") == "yes":
        email_form = EmailChangeForm(request.POST, instance=request.user)
        if email_form.is_valid():
            email_form.save()
            messages.add_message(request, messages.SUCCESS, "Email changed")
    else:
        email_form = EmailChangeForm(instance=request.user)

    return render_to_response(
        "corporate/resume/recruiter_account.html",
        {
            "section": "corporate",
            "page": "account",
            "account": request.user,
            "password_form": password_form,
            "email_form": email_form,
        },
        context_instance=RequestContext(request),
    )
예제 #28
0
파일: views.py 프로젝트: levylll/NGBv1.0
    def changepassword(self,request):
        if not request.user.is_authenticated():
            logger.error(u'[UserControl]用户未登陆')
            raise PermissionDenied
        form = PasswordChangeForm(request.user,request.POST)

        errors = []
        #验证表单是否正确
        if form.is_valid():
            user = form.save()
            oprlog = OprLog.objects.create(
                name = 'VmaigUser',
                customer = request.user,
                opr_type = '修改',
                bak = '密码修改'
            )
            auth.logout(request)
        else:
            #如果表单不正确,保存错误到errors列表中
            for k,v in  form.errors.items():
                #v.as_text() 详见django.forms.util.ErrorList 中
                errors.append(v.as_text())

        mydict = {"errors":errors}
        return HttpResponse(json.dumps(mydict),content_type="application/json")
예제 #29
0
파일: views.py 프로젝트: Ogamedia/ipharm
 def post(self, request, *args, **kwargs):
     form = PasswordChangeForm(self.form_class(request.POST))
     if form.is_valid():
         form.save()
         return HttpResponseRedirect(reverse('pharmacies:pharmacy'))
     self.initial['errors'] = form.errors
     return HttpResponseRedirect(reverse('pharmacies:change'))
예제 #30
0
파일: user.py 프로젝트: nuannuanwu/weixiao
    def change_password(self, request):
        '''
        更改用户密码接口.

        ``POST`` `account/change_passwrod/ <http://192.168.1.222:8080/v1/account/change_password>`_

        :param old_password:
            旧密码

        :param new_password:
            新密码
        '''
        user = request.user
        old_password = request.POST.get("old_password")
        new_password = request.POST.get("new_password")

        data = {
            "old_password": old_password,
            "new_password1": new_password,
            "new_password2": new_password,
        }

        form = PasswordChangeForm(user=user, data=data)
        if form.is_valid():
            form.save()
            # Send a signal that the password has changed
            userena_signals.password_complete.send(sender=None,
                                                   user=user)
            return rc.accepted({"result": True})
        # return form.error_messages
        return rc.BAD_REQUEST
예제 #31
0
def change_password(request):
    if request.method == 'POST':
        form = PasswordChangeForm(data=request.POST, user=request.user)

        if form.is_valid():
            form.save()
            timer = metric.timer('password update')
            timer.start()
            update_session_auth_hash(request, form.user)
            messages.success(request, "Your Password has been updated!")
            logger.info("user updated the password")
            timer.stop()
            return redirect('profile')
        else:

            return render(request, 'users/change_password.html',
                          {'form': form})
    else:

        form = PasswordChangeForm(user=request.user)
        return render(request, 'users/change_password.html', {'form': form})
예제 #32
0
def change_password(request):
    variables = dict()
    if request.POST:
        try:
            configuration_form = PasswordChangeForm(user=request.user,
                                                    data=request.POST)
            if configuration_form.is_valid():
                configuration_form.save()
                messages.success(request, _('Password changed.'))
                return HttpResponseRedirect(reverse(admin_panel))
            else:
                messages.warning(request, _('Correct the errors bellow.'))
        except:
            messages.error(
                request, _('There was an error while changing the Password.'))
    else:
        configuration_form = PasswordChangeForm(user=request.user)
    variables['form'] = configuration_form
    t = get_template('admin/change-password.html')
    html = t.render(RequestContext(request, variables))
    return HttpResponse(html)
예제 #33
0
def change_password_view(request):
    if request.method == 'POST':
        form = PasswordChangeForm(user=request.user, data=request.POST)
        if form.is_valid():
            form.save()
            login(request, request.user)
            messages.success(request, _('Password successfully changed.'))
            return redirect('editor.users.detail', pk=request.user.pk)

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

    for field in form.fields.values():
        field.help_text = None

    return render(
        request, 'editor/account_form.html', {
            'title': _('Change password'),
            'back_url': reverse('site.account'),
            'form': form
        })
예제 #34
0
 def password_change(self,
                     request,
                     template_name='registration/password_change_form.html',
                     post_change_redirect=None):
     if post_change_redirect is None:
         post_change_redirect = reverse(self.password_change_done)
     if request.method == "POST":
         form = PasswordChangeForm(request.user, request.POST)
         if form.is_valid():
             form.save()
             return HttpResponseRedirect(post_change_redirect)
     else:
         form = PasswordChangeForm(request.user)
     context = self.context(
         request,
         title="password_change()",
         form=form,
     )
     return render_to_response(template_name,
                               context,
                               context_instance=RequestContext(request))
예제 #35
0
def change_password(request):
    if request.method == 'POST':
        form = PasswordChangeForm(data=request.POST, user=request.user)
        if form.is_valid():
            print("form accepted")
            form.save()
            print(".fds")
            update_session_auth_hash(request, form.user)
            print(".fd")
            messages.success(request,
                             'Your password was successfully updated!')
            print(".f")
            return redirect('profile')
        else:
            print("erjkevnjfnejnv")
            messages.error(request, 'Please correct the error below.')
            return redirect('profile')
    else:
        form = PasswordChangeForm(user=request.user)
        # args = {'form': form}
        return render(request, 'change_password.html', {'form': form})
예제 #36
0
def person(request, category_slug=None):

    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=request.user)
        # profile_form = ProfileForm(request.POST, instance=request.user.userprofile)

        if user_form.is_valid():
        # if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            # profile_form.save()
            messages.success(request, ('Ваш профиль был успешно обновлен!'))
            return HttpResponseRedirect('/personal-page')
        else:
            messages.success(request, ('Пожалуйста исправьте ошибки!'))

    else:
        user_form = UserForm(instance=request.user)
        # profile_form = ProfileForm(instance=request.user.userprofile)

    u = User.objects.get(username=request.user)
    listZakaz = Reception.objects.filter(person_id = request.user)
    # phone = u.userprofile.phone
    # imagePerson = u.userprofile.avatar
    # usl = MasterUsl.objects.filter(master=self.kwargs['master_id']);

    if request.method == "POST":
        formsPass = PasswordChangeForm(request.user, request.POST)
        if formsPass.is_valid():
            user = formsPass.save()
            update_session_auth_hash(request, user)
            messages.success(request, 'Ваш пароль успешно изменен')
            return HttpResponseRedirect('/')
        else:
            messages.error(request, 'Пожалуйста исправьте ошибки')
    else:
        formsPass = PasswordChangeForm(request.user)

    return render(request, 'pages/personal-page.html', {
        # 'phone': phone,
        # 'imagePerson': imagePerson,
        'formsPass': formsPass,
        'user_form': user_form,
        # 'profile_form': profile_form,
        'listZakaz': listZakaz,
    })
예제 #37
0
def change_password(request):
	if not request.user.is_authenticated():
		return redirect('/home')

	if request.method == 'POST':
		password_change_form = PasswordChangeForm(request.user, request.POST)

		if password_change_form.is_valid():
			password_change_form.save()
			update_session_auth_hash(request, password_change_form.user)  # Important!
			messages.success(request, 'Your password was successfully updated!')

			user_admin = User.objects.get(username='******')
			current_user = request.user

			notification = Notification.objects.create(
				sender = user_admin,
				receiver = current_user,
				subject = 'Password Change',
				content = "Hello " + current_user.first_name + ", you just recently changed your password!" 
			)

			notification.save()	

			return redirect('change_password')
		else:
			messages.error(request, 'Please correct the error below.')
	else:
		password_change_form = PasswordChangeForm(request.user)

	current_user = request.user	
	user_profile_form = AccountDetailsForm()

	context = {
		'user': current_user,
		'user_profile_form': user_profile_form,	
		'password_change_form': password_change_form,
	}

	return render(request, 'account/account_settings.html', context)
예제 #38
0
def settings(request):
    try:
        up = request.user.userpreference
    except UserPreference.DoesNotExist:
        up = None

    user_name_form = UserNameForm(instance=request.user)
    password_form = PasswordChangeForm(request.user)

    if request.method == "POST":
        if 'preference_form' in request.POST:
            form = UserPreferenceForm(request.POST, prefix='preference')
            if form.is_valid():
                if not up:
                    up = UserPreference(user=request.user)
                up.theme = form.cleaned_data['theme']
                up.nav_color = form.cleaned_data['nav_color']
                up.save()

        if 'user_name_form' in request.POST:
            user_name_form = UserNameForm(request.POST, prefix='name')
            if user_name_form.is_valid():
                request.user.first_name = user_name_form.cleaned_data[
                    'first_name']
                request.user.last_name = user_name_form.cleaned_data[
                    'last_name']
                request.user.save()

        if 'password_form' in request.POST:
            password_form = PasswordChangeForm(request.user, request.POST)
            if password_form.is_valid():
                user = password_form.save()
                update_session_auth_hash(request, user)

    if up:
        preference_form = UserPreferenceForm(instance=up)
    else:
        preference_form = UserPreferenceForm()

    return render(
        request, 'settings.html', {
            'preference_form': preference_form,
            'user_name_form': user_name_form,
            'password_form': password_form
        })
예제 #39
0
파일: views.py 프로젝트: rrash283/recipes
def user_settings(request):
    up = request.user.userpreference

    user_name_form = UserNameForm(instance=request.user)
    password_form = PasswordChangeForm(request.user)
    password_form.fields['old_password'].widget.attrs.pop("autofocus", None)

    if request.method == "POST":
        if 'preference_form' in request.POST:
            form = UserPreferenceForm(request.POST, prefix='preference')
            if form.is_valid():
                if not up:
                    up = UserPreference(user=request.user)

                up.theme = form.cleaned_data['theme']
                up.nav_color = form.cleaned_data['nav_color']
                up.default_unit = form.cleaned_data['default_unit']
                up.default_page = form.cleaned_data['default_page']
                up.show_recent = form.cleaned_data['show_recent']
                up.search_style = form.cleaned_data['search_style']
                up.plan_share.set(form.cleaned_data['plan_share'])
                up.ingredient_decimals = form.cleaned_data['ingredient_decimals']
                up.comments = form.cleaned_data['comments']
                up.save()

        if 'user_name_form' in request.POST:
            user_name_form = UserNameForm(request.POST, prefix='name')
            if user_name_form.is_valid():
                request.user.first_name = user_name_form.cleaned_data['first_name']
                request.user.last_name = user_name_form.cleaned_data['last_name']
                request.user.save()

        if 'password_form' in request.POST:
            password_form = PasswordChangeForm(request.user, request.POST)
            if password_form.is_valid():
                user = password_form.save()
                update_session_auth_hash(request, user)

    if up:
        preference_form = UserPreferenceForm(instance=up)
    else:
        preference_form = UserPreferenceForm()

    if (api_token := Token.objects.filter(user=request.user).first()) is None:
        api_token = Token.objects.create(user=request.user)
예제 #40
0
def account_settings(request):
	if request.user.is_superuser or request.user.is_staff:
		if request.method == 'POST':
			#User Details Update
			s_form = UpdateSalerDetailForm(request.POST, request.FILES, instance=request.user.salerdetail)
			u_form = UserUpdateForm(request.POST, instance=request.user)
			if s_form.is_valid() and u_form.is_valid():
				s_form.save()
				u_form.save()
				messages.success(request, f'Your Account has been Updated!')
				return redirect("saler_account_settings")

			#Change Password
			pass_change_form = PasswordChangeForm(request.user, request.POST)
			if pass_change_form.is_valid():
				user = pass_change_form.save()
				update_session_auth_hash(request, user)  # Important!
				messages.success(request, 'Your password was successfully updated!')
				return redirect('saler_account_settings')
			else:
				messages.error(request, 'Please correct the error below.')

			#Account Settings
			acc_form = UpdateSalerAccountDetailForm(request.POST, request.FILES, instance=request.user.salerdetail)
			if acc_form.is_valid():
				acc_form.save()
				messages.success(request, f'Account Settings has been Updated!')
				return redirect("saler_account_settings")

		else:
			s_form = UpdateSalerDetailForm(instance=request.user.salerdetail)
			u_form = UserUpdateForm(instance=request.user)
			acc_form = UpdateSalerAccountDetailForm(instance=request.user.salerdetail)
			pass_change_form = PasswordChangeForm(request.user)
		detl = {
			'u_form':u_form,
			's_form':s_form,
			'pass_change_form':pass_change_form,
			'acc_form':acc_form,
			'cart_element_no' : len([p for p in MyCart.objects.all() if p.user == request.user]),
			'title':'User Account Settings',
			}
		return render(request, 'saler/account_settings.html', detl)
	else:
		return redirect("/")
예제 #41
0
def get_evaluador_profile(request):
    """
    Recupera la informacion del Evaluador, y le permite modificador
    :param request:
    :return:
    """
    if request.user.is_authenticated:
        nombre = request.user.first_name
        apellido = request.user.last_name
        correo = request.user.email
        id = Evaluador.objects.get(correo=correo).id
        passwordForm = PasswordChangeForm(request.user)
        form = UpdateEvaluador({
            'ID': id,
            'nombre': nombre,
            'apellido': apellido,
            'correo': correo
        })
        return render(request, 'evaluadores/profile.html', {
            'form': form,
            'passwordForm': passwordForm
        })
    return HttpResponseRedirect('login')
예제 #42
0
def change_password(request):
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)  # Important!
            pro = request.user.id
            cc = Profile.objects.get(user=pro)
            cc.is_new = False
            cc.save()
            messages.success(request,
                             'Your password was successfully updated!')
            return redirect('log')
        else:
            messages.error(request, 'Please correct the error below.')
    else:
        form = PasswordChangeForm(request.user)
    return render(request, 'pv/change_password.html', {'form': form})
예제 #43
0
def password(request):
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)
            messages.success(request, 'Your password was successfully updated')
            return HttpResponseRedirect('/user/profile')
        else:
            messages.error(
                request,
                'Please correct the error below.<br>' + str(form.errors))
            return HttpResponseRedirect('/user/password')
    else:
        category = Category.objects.all()
        form = PasswordChangeForm(request.user)
        context = {'category': category, 'form': form}
        return render(request, 'user_password.html', context)
def change_password(request):
    if request.method == 'POST':
        # Envia para o form os dados do 'POST' e da instância do usuário atual
        form = PasswordChangeForm(request.user, request.POST)

        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request,
                                     user)  # Atualiza o hash da sessão
            messages.success(request, 'Sua senha foi atualizada com sucesso!')
            return redirect('index')
        else:
            messages.error(request, 'Houve um erro!')

    form = PasswordChangeForm(
        request.user
    )  # Envia para o template os dados da instância do usuário atual
    return render(request, 'registration/change_password.html', {'form': form})
예제 #45
0
def change_password(request):
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        print('form--', form)
        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)  # Important!
            messages.success(request,
                             'Your password was successfully updated!')
            print('form-valid-', form)
            #return redirect('msa_app:home')
            return HttpResponseRedirect('/password/success/')
        else:
            messages.error(request, 'Please correct the error below.')
    else:
        form = PasswordChangeForm(request.user)
        print('form-new-', form)
    return render(request, 'registration/change_password.html', {'form': form})
예제 #46
0
def change_password(request):
    if request.user.is_authenticated:
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            user = form.save(commit=True)
            update_session_auth_hash(request, user)  # Important!
            messages.success(request,
                             'تم تغيير كلمة السر',
                             extra_tags='changed')
            return HttpResponseRedirect('/')
        else:
            messages.success(request,
                             'تأكد من كلمة السر المدخلقة ...شكرا.',
                             extra_tags='error')
            return HttpResponseRedirect('/')
    else:
        form = PasswordChangeForm(request.user)
    return render(request, 'home/profile.html', {"form": form})
예제 #47
0
def change_password(request):
    object = request.user.get_username()
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)  # Important!
            messages.success(request,
                             'Your password was successfully updated!')
            return redirect('accounts:change_password')
        else:
            messages.error(request, 'Please correct the error below.')
    else:
        form = PasswordChangeForm(request.user)
    return render(request, 'accounts/setting/account-dashboard.html', {
        'object': object,
        'form': form
    })
예제 #48
0
def change_password(request):
    if request.method == 'POST':
        form = PasswordChangeForm(data=request.POST, user=request.user)

        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, form.user)
            if user.is_student:
                return redirect(reverse('main:student'))
            else:
                return redirect(reverse('main:employer'))
        else:
            return redirect(reverse('main:change_password'))
    else:
        form = PasswordChangeForm(user=request.user)

        args = {'form': form}
        return render(request, 'main/change_password.html', args)
예제 #49
0
def update_password(request, *args, **kwargs):
    if request.method == 'POST':
        form = PasswordChangeForm(user=request.user, data=request.POST)
        if form.is_valid():
            form.save()
            update_session_auth_hash(request, form.user)
            messages.success(request, f'Password updated successfully')
            return HttpResponseRedirect('logout')
        else:
            messages.warning(
                request,
                f"Passwords doesn't pass the required criteria or doesn't match.Please check"
            )
            return render(request, template_name='users/profile.html')
    else:
        password_form = PasswordChangeForm(request.user)
        context = {'password_form': password_form, 'title': 'Change Password'}
    return render(request, 'users/profile.html', context=context)
예제 #50
0
def cambiarPassword(request):
    if not request.user.is_authenticated:
        return redirect('login')
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)
            messages.success(
                request, 'Clave actualizada!')
            return redirect("/login")
        else:
            messages.error(request, 'No fue posible cambiar su password')
    else:
        form = PasswordChangeForm(request.user)
    return render(request, "CambiarPassword.html", {
        'form': form
    })
예제 #51
0
def change_password(request):

    if not request.user.is_authenticated:
        return redirect('login')

    if request.method == 'POST':
        form = PasswordChangeForm(data=request.POST, user=request.user)

        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)
            return redirect('/accounts/profile/')
        else:
            return render(request, 'accounts/change_password.html',
                          {'form': form})

    form = PasswordChangeForm(user=request.user)
    return render(request, 'accounts/change_password.html', {'form': form})
예제 #52
0
def user_change_password(request):
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)  # Important!
            messages.success(request,
                             'Your password was successfully updated!')
            return HttpResponseRedirect('user_change_password')
        else:
            messages.error(request, 'Please correct the error below.')
    else:
        form = PasswordChangeForm(request.user)
    context = {
        'page': 'user',
        'form': form,
    }
    return render(request, "inside/user_change_password.html", context)
예제 #53
0
def user_password(request):
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)  # Important!
            messages.success(request, 'Parola Değiştirildi.!')
            return HttpResponseRedirect('/user')
        else:
            messages.error(request, 'Hata oluştu..<br>')
            return HttpResponseRedirect('/user/password')
    else:
        category = Category.objects.all()
        form = PasswordChangeForm(request.user)
        return render(request, 'user_password.html', {
            'form': form,
            'category': category
        })
예제 #54
0
def user_password(request):
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)  # Important!
            messages.success(request,
                             'Your password was successfully updated!')
            return HttpResponseRedirect('/user/password')
        else:
            error_message = 'Please correct the error below.<br>'
            for prop in form.errors:
                error_message += prop + ': ' + form.errors[prop][0] + '<br>'
            messages.error(request, error_message)
            return HttpResponseRedirect('/user/password')
    else:
        form = PasswordChangeForm(request.user)
        return render(request, 'user_password.html', {'form': form})
예제 #55
0
def changePassword(request):
    if request.method == 'POST':
        form = PasswordChangeForm(user=request.user, data=request.POST)

        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)
            messages.success(request,
                             'your password has changeed successfully!')
            return redirect('updateUserPassword')
        else:
            messages.error(request, 'please correct the following errors!')
            return redirect('updateUserPassword')

    else:
        form = PasswordChangeForm(request.user)
        context = {'form': form}
        return render(request, 'changePassword.html', context)
예제 #56
0
def change_password(request):
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)

        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)  # Important!
            messages.success(request,
                             'Your password was successfully updated!')
            return redirect('logout')

        else:
            messages.error(request, 'Please correct the error below.')

    else:
        form = PasswordChangeForm(request.user)

    return render(request, 'users/change_password.html', {'form': form})
예제 #57
0
def change_password(request):
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)  # Important!
            messages.success(request,
                             'Пароль успешно изменен',
                             extra_tags='alert-success')
            return redirect('members:change_password')
        else:
            messages.error(request,
                           'Ошибка. Пожалуйста, \
                           проверьте введённую информацию.',
                           extra_tags='alert-danger')
    else:
        form = PasswordChangeForm(request.user)
    return render(request, 'members/change_password.html', {'form': form})
예제 #58
0
def change_password(request):
    error = ''
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)
            messages.success(request,
                             "Your password has been successfully changed.")
            return redirect('change_password')
        else:
            error = "Please enter correct below."
    else:
        form = PasswordChangeForm(request.user)
    return render(request, 'mysite/registration/change_password.html', {
        'error': error,
        'form': form
    })
예제 #59
0
def upassword(request):
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)  # Important!
            messages.success(
                request,
                'Your password updated successfully! Sign-in again with new credentials.'
            )
            logout(request)
            return HttpResponseRedirect(reverse('uauth:home'))
        else:
            messages.error(request, 'Please correct the error below.')
    else:
        form = PasswordChangeForm(request.user)

    return render(request, 'uauth/password.html', {'form': form})
예제 #60
0
def change_password(request):
    di = {'title': 'Password Change'}
    di['noti_b_object'] = Notification.objects.all().order_by('-timestamp')
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)  # Important!
            messages.success(request,
                             'Your password was successfully updated!')
            return redirect('profile')
        else:
            messages.error(request, 'You Entered a Wrong Password')
            return redirect('profile')
    else:
        form = PasswordChangeForm(request.user)
        di['form'] = form
    return render(request, 'change-password.html', di)