Вопрос

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.

Это было полезно?

Решение

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.

Другие советы

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?

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top