Example #1
0
def profile(request):
    # Get a list of the users API Keys
    keys = ApiKey.objects.filter(user=request.user)
    try:
        backup_tokens = request.user.staticdevice_set.all()[0].token_set.count(
        )
    except IndexError:
        backup_tokens = 0

    # Get a list of the users current sessions
    sessions = request.user.session_set.filter(expire_date__gt=now())

    # Get the current session key
    session_key = request.session.session_key

    # Process the form if we have data coming in
    if request.method == 'POST':
        form = UserProfileForm(request.POST, instance=request.user.profile)
        if form.is_valid():
            form.save()
    else:
        form = UserProfileForm(instance=request.user.profile)

    # Show the template
    return render(
        request, 'account_profile.html', {
            'keys': keys,
            'sessions': sessions,
            'session_key': session_key,
            'form': form,
            'user': request.user,
            'default_device': default_device(request.user),
            'backup_tokens': backup_tokens,
        })
Example #2
0
def profile(request):
    # Get a list of the users API Keys
    keys = ApiKey.objects.filter(user=request.user)
    try:
        backup_tokens = request.user.staticdevice_set.all()[0].token_set.count()
    except IndexError:
        backup_tokens = 0

    # Get a list of the users current sessions
    sessions = request.user.session_set.filter(expire_date__gt=now())

    # Get the current session key
    session_key = request.session.session_key

    # Process the form if we have data coming in
    if request.method == 'POST':
        form = UserProfileForm(request.POST, instance=request.user.profile)
        if form.is_valid():
            form.save()
    else:
        form = UserProfileForm(instance=request.user.profile)

    # Show the template
    return render(request, 'account_profile.html', {
        'keys': keys,
        'sessions': sessions,
        'session_key': session_key,
        'form': form,
        'user': request.user,
        'default_device': default_device(request.user),
        'backup_tokens': backup_tokens,
    })
Example #3
0
def profile(request):
    # Get a list of the users API Keys
    keys = ApiKey.objects.filter(user=request.user)

    # Get a list of the users current sessions
    sessions = request.user.session_set.filter(expire_date__gt=now())

    # Get the current session key
    session_key = request.session.session_key

    # Process the form if we have data coming in
    if request.method == 'POST':
        form = UserProfileForm(request.POST, instance=request.user.profile)
        if form.is_valid():
            form.save()
    else:
        form = UserProfileForm(instance=request.user.profile)

    # Show the template
    return render(request, 'account_profile.html', {
        'keys': keys,
        'sessions': sessions,
        'session_key': session_key,
        'form': form,
        'user': request.user,
    })
Example #4
0
File: views.py Project: 3241966/PMS
def user_details(request):
	ago = datetime.now()-timedelta(days=182)
	entries = Entry.objects.filter(submitter=request.user,hidden=False,submittedtime__gte=ago).order_by('submittedtime')
	
	if request.method == "POST":
		profileform = UserProfileForm(request.POST,user=request.user,instance=request.user.get_profile())
		passwordform = PasswordChangeForm(request.user)
		if profileform.is_valid():
			request.user.first_name = profileform.cleaned_data['first_name'].capitalize()
			request.user.last_name = profileform.cleaned_data['last_name'].capitalize()
			request.user.save()		
			profileform.save()
			messages.add_message(request,messages.SUCCESS,"Info updated")
	else:
		passwordform = PasswordChangeForm(user=request.user)
		profileform = UserProfileForm(user=request.user,instance=request.user.get_profile())
	
	return render_to_response("details.html",{'profileform' : profileform,'passwordform' : passwordform, 'entries' : entries},context_instance=RequestContext(request))
Example #5
0
def profile(request):
    try:
        api_key = ApiKey.objects.get(user=request.user)
    except ObjectDoesNotExist:
        api_key = ApiKey.objects.create(user=request.user)

    if request.method == 'POST':
        form = UserProfileForm(request.POST, instance=request.user.profile)
        if form.is_valid():
            form.save()
    else:
        form = UserProfileForm(instance=request.user.profile)

    return render(request, 'account_profile.html', {
        'form': form,
        'user': request.user,
        'apikey': api_key,
    })
Example #6
0
def register(request):
    #print "jestem tutaj"
    if request.method == 'POST':
        uform=UserForm(request.POST)
        pform=UserProfileForm(request.POST)
        #print form.is_valid()
        if uform.is_valid() and pform.is_valid():
            
            user=uform.save()
            user.set_password(request.POST['password'])
            user.save()
            profile=pform.save(commit=False)
            profile.user=user
            profile.save()
            return HttpResponseRedirect('/mysite/mainsite/')
    else:
        uform=UserForm()
        pform=UserProfileForm()
    return render_to_response('register.html',{"uform":uform,"pform":pform},context_instance=RequestContext(request))
Example #7
0
File: views.py Project: 3241966/PMS
def create_account(request):
	if request.method == 'POST':
		form = UserForm(request.POST)
		form2 = UserProfileForm(request.POST)
		if form.is_valid() and form2.is_valid():
			user = form.save(commit=False)
			user.first_name = form2.cleaned_data['first_name']
			user.last_name = form2.cleaned_data['last_name']
			user.save()
			
			profile = form2.save(commit=False)
			profile.user = user
			profile.save()
			messages.add_message(request,messages.SUCCESS,"Account created")
			return HttpResponseRedirect(reverse("accounts.views.login_user"))
	else:
		form = UserForm()
		form2 = UserProfileForm()
	
	return render_to_response('create_account.html',{'form' : form,'form2' : form2},context_instance=RequestContext(request))