Пример #1
0
    def post(self, request, *args, **kwargs):
        password_form = EditPasswordForm(request.POST)

        if password_form.is_valid():
            new_password = password_form.cleaned_data.get('new_password')
            request.user.set_password(new_password)
            request.user.save()

            profile = ProfileUser.objects.get(user=request.user)
            profile.validation_hash = hashlib.md5(new_password+str(datetime.datetime.now())).hexdigest()
            profile.save()

            return redirect('/editar_perfil/')

        general_form = EditPersonalInformation()
        location_form = EditLocationForm()
        password_form = EditPasswordForm()
        action = 'password'
        error = u'A confirmação de senha está errada!'

        attrs = {'general_form': general_form, 'location_form': location_form, 'password_form': password_form,
                 'action': action, 'error': error}
        return render_to_response(self.template_name, attrs, RequestContext(request))
Пример #2
0
    def post(self, request, *args, **kwargs):
        form = SignInForm(request.POST)

        if form.is_valid():
            name = form.cleaned_data.get('name')
            surname = form.cleaned_data.get('surname')
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')

            user = User.objects.create(first_name=name, last_name=surname, username=email, email=email)
            user.set_password(password)
            user.save()

            profile = ProfileUser.objects.create(user=user)
            profile.validation_hash = hashlib.md5(password+str(datetime.datetime.now())).hexdigest()
            profile.save()

            user = authenticate(username=email, password=password)
            if user is not None:
                login(request, user)
                return redirect('/home')

        attrs = {'form': form}
        return render_to_response(self.template_name, attrs, RequestContext(request))