0

I am working on a store based authentication system using Django, i am trying to make it so that the url is the one that specifies which store the user is trying to log in. Ex

login/store-name

then login the user in to the requested store. My question is, is there a way to do this using django's built in login form/mechanism or would i have to create my own login form and view.

1
  • You'll need to write your own view. Commented Nov 8, 2011 at 21:55

3 Answers 3

1

In my opinion you should create your own form and login view:

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  *** and user can login in this store ***:
            login(request, user)
            # Redirect to a success page.
        else:
            # Return a 'disabled account' error message
    else:
        # Return an 'invalid login' error message.

"and user can login in this store": get path from request and check it.

Sign up to request clarification or add additional context in comments.

1 Comment

i guess this is the best solution :)
1

I think you could do this just in urls.py

urlpatterns = patterns('',
    url(r'^login/store-name-1/$', login, name="login"),
    url(r'^login/store-name-2/$', login, name="login"),
    url(r'^accounts/logout/$', logout, {'next_page': '/',}, name='logout')
)

I'm not exactly clear on what you want to do?

1 Comment

im using a generic url pattern that takes a store name, and then logs the user in to that specific store
1

If you want separate logins for each store, you will need to customize the login form, since the django auth package will create users that are universal to all of your stores.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.