|
Posted by N8 |
|
|
Newbie need stuff. I am working on my first django site, so far all“s been smooth following the tutorials, the admin backend is all good for now, and now Im working on user authentication. I followed this tutorial: http://codingnstuff.com/2010/01/create-your-user-management-frontend-in-django/ which was full of little errors, but i managed to correct them for the most part. However, Im stuck on the user activation and login functions. I am looking for either simple tutorials or sample files to get me past these newbie hurdles. In other words, anyone have or know of other resources for creating a user authentication frontend? Of course Ive been going thru the documentation (http://docs.djangoproject.com/en/dev/topics/auth/), but an example of usage would really be nice to get me started.
Any advice would be much appreciated! |
|
|
Posted by Herbert Poul ![]() |
|
|
i think the example code in the tutorial does exactly what you are looking for: http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.login
from django.contrib.auth import authenticate, login
def my_view(request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
# Redirect to a success page.
else:
# Return a 'disabled account' error message
else:
# Return an 'invalid login' error message.
an example HTML frontend would look like: <form method="post" action="/myurl/my_view/"> Username: <input type="text" name="username" /> Password: <input type="password" name="password" /> <input type="submit" value="Login" /> </form> SCT - http://sct.sphene.net |
|
|
Posted by N8 |
|
|
Thanks for quick reply Herbert! Yea, Im making progress with the django documentation, and even more so the django book http://www.djangobook.com/en/1.0/chapter12/. Just looking for a something more tutorial-ish, since Im new at this. But I'll keep trudging along with the documentation, thanks again...
|
|
|
Posted by N8 |
|
|
Well it seems I managed to figure it all out after much reading and trial and error, ah yes love the first feeling of Noob success
Perhaps I should make a new thread for this, but I will ask here while Im at it. Now I would like to make user groups, but not necessarily in the manner of group permissions. What I need to do is basically make a sub-set of users under a main user profile, where the admin will assign and associate content with a set users (ie a group). For example, the admin creates/selects a group in the backend, and uploads a static media file, associating it with the group. Then a user within this group logs on and may access the media file. An example application could be a chain of restaurants that share the same base content, but each individual restaurant has it's own user to access and edit the content to their specific needs. Do you think I have to extend the user model to do this, or is there a way to make user groups or sub-users, or perhaps using django's group permission architecture can do this sufficiently? |
|
|
Posted by Herbert Poul ![]() |
|
|
i think you have to create your own system for this.. simply create a 'UserSet' model which has a n:m relation to django's 'User' object.. if what you need is that a user can only be in one group you could also create a model which mirrors the django User .. something like.. MyUser which as a 1:1 relation to django User model and a simple ForeignKey (1:n) relation to a UserSet.. 1:1 relations and 1:n relations are very easy to create in django and easy to work with..
hope this makes some kind of sense to you SCT - http://sct.sphene.net |
|
|
Posted by N8 |
|
|
Ok, yes I think I get the idea. Yea exactly, a user belongs only to one group, so the "mirror" option using a foreignkey relation seems like the way to go. Great, thanks for the advice, time to get crackin'.
|



