Exemplo n.º 1
0
def newlogin(request):
    form = UserCreationForm()
    if request.method == 'POST':
        data = request.POST.copy()
        errors = form.get_validation_errors(data)
        if not errors:
            if data['magicword'] == "bacon":
		new_user = form.save(data)
		burner = Burner()
		burner.user = new_user
		burner.save()
		cache.delete(CACHE_KEY)
		user = authenticate(username=data['username'], password=data['password1'])
		if user: login(request, user)
		return HttpResponseRedirect("/user/profile")
            else:
                # this is a total cheat, but doing this without an entry in the model is a pita
                data['badmagicword'] = "1"

    else:
        data, errors = {}, {}
        try:
            del data['badmagicword']
        except KeyError:
            pass

    return render_to_response("campmanager/user/newlogin", {
        'form' : forms.FormWrapper(form, data, errors)
    })
Exemplo n.º 2
0
def newlogin(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)

        if form.is_valid():
            new_user = form.save()
            burner = Burner()
            burner.user = new_user
            burner.arrival_date = "2012-10-13"
            burner.email = form.cleaned_data.get('email')
            burner.realname = form.cleaned_data.get('username')
            burner.save()
            cache.delete(CACHE_KEY)
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            if user: auth_login(request, user)
            return HttpResponseRedirect("/user/profile")

    else:
        form = SignUpForm()
    return render(request, 'campmanager/user/newlogin', {'form': form})
Exemplo n.º 3
0
def myprofile(request):

    setup = request.GET.get('setup', '')
    msg = None
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/user/login/?next=%s' % request.path)

    burnerList = Burner.objects.filter(user=request.user.id)
    if burnerList: 
        burner = burnerList[0]
    else:
        burner = Burner(user=request.user)

    if request.method == 'POST':
        burner.realname = request.POST['realname'] 
        burner.mobile = request.POST['phone']
        burner.arrival_date = "2012-10-13"
        msg = "Profile saved."
        burner.save()

#        try:
#            burner.arrival_date = datetime.datetime.strptime(request.POST['arrival_date'], "%m-%d-%Y") #.strftime("%Y-%m-%d")
#            msg = "Profile saved."
#            burner.save()
#        except ValueError:
#            msg = "Invalid arrival date. Please format mm-dd-yyyy."
#            burner.arrival_date = datetime.date.today()
        if request.POST['setup'] == '1':
            return HttpResponseRedirect('/group/0/?setup=1')

    t = loader.get_template('campmanager/user/myprofile')
    c = RequestContext(request, {
            'msg' : msg,
            'realname' : burner.realname,
            'phone' : burner.mobile,
            'setup' : setup,
#            'arrival_date' : str(burner.arrival_date) or "",
#            'arrival_date_y' : burner.arrival_date.year,
#            'arrival_date_m' : burner.arrival_date.month,
#            'arrival_date_d' : burner.arrival_date.day,
    })
    return HttpResponse(t.render(c))
Exemplo n.º 4
0
def myprofile(request):

    setup = request.GET.get('setup', '')
    msg = None
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/user/login/?next=%s' % request.path)

    burnerList = Burner.objects.filter(user=request.user.id)
    user = User.objects.get(username=request.user)
    if burnerList:
        burner = burnerList[0]
    else:
        burner = Burner(user=request.user)

    google_login = request.user.social_auth.filter(provider='google-oauth2')
    facebook_login = request.user.social_auth.filter(provider='facebook')

    msg = facebook_login

    if request.method == 'POST':
        if 'A' in request.POST:
            form = MyProfileForm(request.POST, user=request.user)
            pw_form = PasswordChangeForm(request.user)

            if form.is_valid():
                burner.realname = form.cleaned_data.get('username')
                user.username = form.cleaned_data.get('username')
                user.first_name = form.cleaned_data.get('first_name')
                user.last_name = form.cleaned_data.get('last_name')
                user.email = form.cleaned_data.get('email')
                burner.email = form.cleaned_data.get('email')
                burner.mobile = form.cleaned_data.get('phone')
                burner.arrival_date = "2012-10-13"
                msg = "Profile saved."
                burner.save()
                user.save()
        if 'B' in request.POST:
            form = MyProfileForm(
                initial={
                    'username': user.username,
                    'first_name': user.first_name,
                    'last_name': user.last_name,
                    'email': user.email,
                    'phone': burner.mobile
                })
            pw_form = PasswordChangeForm(request.user, request.POST)

            if pw_form.is_valid():
                user = pw_form.save()
                update_session_auth_hash(request, user)  # Important!
                msg = 'Your password was successfully updated!'
    #        try:
    #            burner.arrival_date = datetime.datetime.strptime(request.POST['arrival_date'], "%m-%d-%Y") #.strftime("%Y-%m-%d")
    #            msg = "Profile saved."
    #            burner.save()
    #        except ValueError:
    #            msg = "Invalid arrival date. Please format mm-dd-yyyy."
    #            burner.arrival_date = datetime.date.today()
    #if request.POST['setup'] == '1':
    #    return HttpResponseRedirect('/group/0/?setup=1')
    else:
        form = MyProfileForm(
            initial={
                'username': user.username,
                'first_name': user.first_name,
                'last_name': user.last_name,
                'email': user.email,
                'phone': burner.mobile
            })

        pw_form = PasswordChangeForm(request.user)
    t = 'campmanager/user/myprofile'
    c = {
        'msg': msg,
        'realname': burner.realname,
        'first_name': burner.user.first_name,
        'last_name': burner.user.last_name,
        'phone': burner.mobile,
        'email': burner.email,
        'setup': setup,
        'form': form,
        'pw_form': pw_form,
        'google_login': google_login,
        'facebook_login': facebook_login
        #            'arrival_date' : str(burner.arrival_date) or "",
        #            'arrival_date_y' : burner.arrival_date.year,
        #            'arrival_date_m' : burner.arrival_date.month,
        #            'arrival_date_d' : burner.arrival_date.day,
    }
    return render(request, t, c)