Пример #1
0
def signup(request):
    base_vars=get_base_vars(request)
    
    if request.user.is_authenticated():
        base_vars.update({"message":"You are logged in."})
        return render_to_response("message.html", base_vars)
    else:
        if request.method=="POST":
            suForm=SignupForm(request.POST, request.FILES)
            if suForm.is_valid():
                pk=len(User.objects.all()).__str__()
                username=pk.join([request.POST['first_name'],request.POST['last_name']])
                user=User.objects.create_user( username=username,email=request.POST['email'],password=request.POST['password1'])
                user.first_name=request.POST['first_name']
                user.last_name=request.POST['last_name']
                user.save()
                
                person = account_models.person()
                person.user_id = user
                person.sex = request.POST['sex']
                person.phno = request.POST['phno']
                person.pin = request.POST['pin']
                person.website = request.POST['website']
                person.save()
                
                logged_in_user = authenticate(username=username, password=request.POST['password1'])
                if logged_in_user is not None:
                    login(request, logged_in_user)
                    return HttpResponseRedirect("/account/home")
            else:
                base_vars.update({"reg_form":suForm,})
                return render_to_response("account_signup.html", base_vars)
        else:
            base_vars.update({"reg_form":SignupForm()})
            return render_to_response("account_signup.html", base_vars)
Пример #2
0
def home(request):
    base_vars = get_base_vars(request)
    
    if request.user.is_authenticated():
        email=base_vars['user']
        user = User.objects.get( email = email )
        _id = user.id
        person = account_models.person()
        person = account_models.person.objects.get( user_id = _id )
        base_vars.update({"email": email,"fname":user.first_name,"lname":user.last_name,"sex":person.sex, "phno":person.phno })
        return render_to_response("home.html",base_vars)
    else:
        HttpResponseRedirect("/account/")