示例#1
0
文件: views.py 项目: nitingera1996/pd
def next_step(request):
    u=request.user
    if request.method=="POST":
        up=UserProfile(user=u,level=1)
        name = request.POST.get('name')
        email = request.POST.get('email')
        dob_date = request.POST.get('dob_date')
        dob_month = request.POST.get('dob_month')
        dob_year = request.POST.get('dob_year')
        profile_pic_url=request.FILES['picture']
        print profile_pic_url
        languages=request.POST.get('language')
        profile_tagline=request.POST.get('profile_tag')
        liked_category_ids=request.POST.getlist('category')
        up.name=name
        up.dob_date=int(dob_date)
        up.dob_month=int(dob_month)
        up.dob_year=int(dob_year)
        up.languages=int(languages) 
        up.profile_tag_line=profile_tagline
        up.save()
        up_follow=Follow(userprofile=u)
        up_follow.save()
        return HttpResponseRedirect('/blogu/')
    else:
        #try:
           # up=UserProfile.objects.get(user=u)
           # return HttpResponseRedirect('/blogu/')
        #except:
        context_dict={}
        cat_list=Category.objects.all()
        context_dict['cat_list']=cat_list
        return render(request,'blogu/next_step.html',context_dict)
示例#2
0
文件: views.py 项目: nitingera1996/pd
def google_login(request):
    if request.method=="POST":
        #print "Hello"
        email=request.POST['email']
        image_url=request.POST['image_url']
        name=request.POST['name']
        google_id=request.POST['id']
        response_dict={}
        print "email=",email
        try:
            u=User.objects.get(email=email)
            up=UserProfile.objects.get(user=u)
            if up.google_registered:
                up.login=1
                up.save()
            else:
                up.google_id=google_id
                up.google_registered=True
                up.login=1
                up.save()
                    #print "Hello"
            user = authenticate(username = up.user.username,password=up.user.password)
            if user:
                if user.is_active:
                    login(request,user)
                    response_dict.update({'response':"logged in"})
                    response=HttpResponse(json.dumps(response_dict), content_type='application/javascript')
                else:
                    response_dict.update({'response':"Your Nblik account is disabled."})
                    response=HttpResponse(json.dumps(response_dict), content_type='application/javascript')

        except:
            print "In except"
            signup_username=create_signup_username(name)
            print signup_username,email
            user=User.objects.create_user(username=signup_username,email=email)
            user.set_password("password")
            user.save()
            user1=User.objects.get(username=signup_username)
            print "user1=", user1
            profile=UserProfile(user=user1,level=1)
            profile.name=name
            profile.google_id=google_id
            profile.google_registered=True
            profile.login=1
            profile.save()
            up_follow=Follow(userprofile=user1)
            up_follow.save()
            user1 = authenticate(username = signup_username,password="******")
            #user1 = authenticate(username = signup_username,password=signup_password1)
            login(request,user1)
            response_dict.update({'response':'logged_in'})
            response=HttpResponse(json.dumps(response_dict), content_type='application/javascript')
        return response
示例#3
0
文件: views.py 项目: nitingera1996/pd
def login_and_signup(request):
    if request.method == 'POST':
        login_statement=None
        signup_statement=None
        login_username_or_email = request.POST.get('login_username_or_email')
        if login_username_or_email:
            login_password = request.POST.get('login_password')
            if not login_username_or_email:
                login_statement="Please enter the username"
            if not login_password and login_username_or_email:
                login_statement ="Please enter the password"
            try:
                u=User.objects.get(email=login_username_or_email)
                login_username=u.username
            except:
                login_username=login_username_or_email
            try:
                u=User.objects.get(username=login_username)
            except:
                u=None
            user = authenticate(username = login_username,password=login_password)
            if user and login_username and login_password:
                if user.is_active:
                    login(request,user)
                    return HttpResponseRedirect('/blogu/')
                else:
                    return HttpResponse("Your Nblik account is disabled.")
            else:
                print "Invalid login details: {0}, {1}".format(login_username,login_password)
                login_statement="Invalid username password combination"
        else:
            registered = False
            signup_name = request.POST.get('signup_name')
            signup_email = request.POST.get('signup_email')
            signup_password1 = request.POST.get('signup_password1')
            signup_password2 = request.POST.get('signup_password2')
            register_as = request.POST.get('register_as')         
            try:
                u=User.objects.get(email=signup_email)
                signup_statement="Email already registered"
            except:
                if signup_password1!=signup_password2:
                    signup_statement="password not same"
                else:
                    signup_username=create_signup_username(signup_name)
                    user=User.objects.create_user(username=signup_username,email=signup_email)
                    user.set_password(signup_password1)
                    user.save()
                    user1=User.objects.get(username=signup_username)
                    if register_as=="user":
                        profile=UserProfile(user=user1,level=1)
                        profile.name=signup_name
                        profile.save()
                        up_follow=Follow(userprofile=user1)
                        up_follow.save()
                    else:
                        company=Company(user=user1)
                        company.name=signup_name
                        company.save()
                    user1 = authenticate(username = signup_username,password=signup_password1)
                    #user1 = authenticate(username = signup_username,password=signup_password1)
                    print user1
                    login(request,user1)
                    return render(request,'blogu/next_step.html',{'email':signup_email,'name':signup_name}) 
                    #return render(request,'blogu/signup2.html',{'username':signup_username})

        return render(request,'blogu/login.html',{'login_statement':login_statement,'signup_statement':signup_statement,'cat_list':Category.objects.all()})
    else:
        return render(request,'blogu/login.html',{})