0

我正在尝试登录用户。创建他的个人资料后。但是当他授权他时,他以匿名用户身份登录。

from django.contrib.auth import authenticate as authorise

def shopify_register(request):

    print "############*****GOT DETAILS*****############"
    password = request.POST['pass']


    subs, stat = Subscription.objects.get_or_create(validity=datetime.now()+timedelta(days=30))
    newuser, stat = User.objects.get_or_create(username=request.POST['email'])
    newuser.set_password(password)
    newuser.save()
    user, stat = UserProfile.objects.get_or_create(subscription=subs,user=newuser)
    domain, stat = Domain.objects.get_or_create(user_profile=user, shortname=request.POST['shop_name'], keywords=request.POST['keywords'])

    profile,stat = ShopifyUserProfile.objects.get_or_create(shop_user =user.. etc )
    username = request.POST['email']



    authuser = authorise(username=username, password=mdpass)
    domain = Domain.objects.get(user_profile=user)
    testimonies = Testimony.objects.filter(domain=domain).filter(show=0).order_by('-timestamp')
    c = RequestContext(request, {
        'user' : user,
        'testimonies': testimonies,
        'request': request,
        'mentions': 1,
        'domain': domain
    })
    return render_to_response('homepage.html', context_instance=c)

更新 :

authuser = authorise(username=username, password=mdpass)

这不授权用户。虽然用户已经创建。

它工作正常,但它将用户记录为匿名用户?这里有什么问题?

删除了 md5 散列,但仍然没有授权用户。

更新:2

ipdb> authuser = authorise(username=username, password=password)
ipdb> authuser
<User: ratan@kumar.com>
ipdb> temp=auth_login(request,authuser)
ipdb> temp
ipdb> print temp
None

这意味着它已授权用户,但无法登录。

4

2 回答 2

2

验证后需要调用登录函数。

from django.contrib.auth import login as auth_login
auth_login(request, user)
于 2013-05-15T09:03:53.537 回答
1

您需要将用户输入的密码按authorise原样发送,不需要对其进行 shs224。authorise将负责散列它。

from django.contrib.auth import login

#remove md5 step
authuser = authorise(username=username, password=password)
login(authuser, request)

您需要在login之后调用authenticate

于 2013-05-15T09:07:13.640 回答