[help] passing a md5 digest string into URL

ยอดดู 311 ครั้ง
ข้ามไปที่ข้อความที่ยังไม่อ่านรายการแรก

Giuseppe Franchi

ยังไม่อ่าน,
27 ก.พ. 2550 04:53:5427/2/50
ถึง Django users
Hello everyone... again. :)
As i said, i need to pass in my URL a <code> variable, wich is the
result of a md5 digest.
(no private information... only a validation key).

Obviously i tried with
(r'^users/activate_user/(?P<code>)/', 'views.register'),
(r'^users/activate_user/(?P<code>[a-zA-Z0-9%\-]+=)/',
'views.register'),
but it doesn't work: Django always return 404.

Is it an encoding problem or something? Any idea on how should i do?

Cheers (and grateful thanks, this group is greatly useful)

ScottB

ยังไม่อ่าน,
27 ก.พ. 2550 11:11:4027/2/50
ถึง Django users
Hi Giuseppe.

> As i said, i need to pass in my URL a <code> variable, wich is the
> result of a md5 digest.
> (no private information... only a validation key).
>
> Obviously i tried with
> (r'^users/activate_user/(?P<code>)/', 'views.register'),
> (r'^users/activate_user/(?P<code>[a-zA-Z0-9%\-]+=)/',
> 'views.register'),
> but it doesn't work: Django always return 404.

It works for me if the code ends with a single equals sign.
e.g.
http://localhost/users/activate_user/abc123=/

If you're stuck, maybe you could post a couple of example urls that
give you 404 errors.

Scott

Giuseppe Franchi

ยังไม่อ่าน,
1 มี.ค. 2550 09:38:351/3/50
ถึง Django users
Cheers, thanks a lot Scott, you were right and i resolved ^^

I post, maybe someone could find it useful.
In my view i used the base64 library.

import md5, base64
...
key = md5.new(string).digest()
key = base64.urlsafe_b64encode(key)
validation.md5_key = key
validation.save()


The URL is
(r'^users/activate_user/(?P<code>[a-zA-Z0-9%\-]+==)/',
'views.activate_user'),

the final '+==' make it works, as any key generated this way ends with
2 equal signs.

On 27 Feb, 17:11, "ScottB" <tepidr...@gmail.com> wrote:
> Hi Giuseppe.
>
> > As i said, i need to pass in my URL a <code> variable, wich is the
> > result of a md5 digest.
> > (no private information... only a validation key).
>
> > Obviously i tried with
> > (r'^users/activate_user/(?P<code>)/', 'views.register'),
> > (r'^users/activate_user/(?P<code>[a-zA-Z0-9%\-]+=)/',
> > 'views.register'),
> > but it doesn't work: Django always return 404.
>
> It works for me if the code ends with a single equals sign.

> e.g.http://localhost/users/activate_user/abc123=/

Bob

ยังไม่อ่าน,
1 มี.ค. 2550 12:52:311/3/50
ถึง Django users
You can also do this as:
(r^users/activate_user/(?P<code>[^/])/, views.activate_user')
which gets you away from relying on the final equal signs, though it
would allow any characters into the code other than a slash. That
should be okay since the code would not be correct in that case.
- Bob

James Bennett

ยังไม่อ่าน,
1 มี.ค. 2550 12:57:401/3/50
ถึง django...@googlegroups.com
On 2/27/07, Giuseppe Franchi <kors...@hotmail.com> wrote:
> Hello everyone... again. :)
> As i said, i need to pass in my URL a <code> variable, wich is the
> result of a md5 digest.
> (no private information... only a validation key).

An md5 hex digest is always 32 characters long, containing digits and
letters A through F, so something like

[a-fA-F0-9]{32}

is about as exact a regex for matching it as you'll find.

SHA1 has the same character range -- [a-fA-F0-9] -- but is forty
characters long.

--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

Jens Diemer

ยังไม่อ่าน,
2 มี.ค. 2550 02:31:422/3/50
ถึง django...@googlegroups.com
Giuseppe Franchi schrieb:

> As i said, i need to pass in my URL a <code> variable, wich is the
> result of a md5 digest.
> (no private information... only a validation key).

Look at this: http://code.google.com/p/django-registration/
and this: http://django-registration.googlecode.com/svn/trunk/urls.py

--
Mfg.

Jens Diemer


----
CMS in pure Python CGI: http://www.pylucid.org

ตอบทุกคน
ตอบกลับผู้สร้าง
ส่งต่อ
ข้อความใหม่ 0 รายการ