Exemple #1
0
def profile(request, id):
    try:
        user = Users.objects.get(id = id)
        loggedUser = Users.objects.get(id = request.session['id'])
        if (not Users.is_authenticated(session_key = request.session.session_key, cookie = request.session)):
                raise CookieError
    except CookieError:
        # User has not logged in
        request.session.flush()
        return HttpResponseRedirect('/')
    except:
        # Likely, user with id = id has not been found
        return HttpResponseRedirect('/user/home')
    else:
        if (not user.inactive):
            # Rendering profile page using id
            t = get_template('profile.html')
            c = RequestContext(request, { 'ProfileUserName': user.username,
                                         'ProfileName': user.name,
                                         'ProfileSurname': user.surname,
                                         'ProfileGender': user.gender,
                                         'ProfileBirthdate': user.birthdate,
                                         'UserID': loggedUser.id,
                                         'UserName': loggedUser.username,
                                         'section': 'Perfil' })
            return HttpResponse(t.render(c))
        else:
            return HttpResponseRedirect('/user/home')
Exemple #2
0
def test_if_authenticated(step):
    session = world.browser.session
    session['id'] = 1
    session['user_session'] = 'foo'
    session.set_expiry(0)
    session.save()
    assert Users.is_authenticated(session_key = world.browser.cookies['sessionid'].value, cookie = world.browser.session)
Exemple #3
0
def config(request):
    try:
        id = request.session['id']
    except:
        # User is not logged in
        return HttpResponseRedirect('/')
    else:
        #User maybe has logged in
        try:
            dbCookie = Session.objects.get(session_key = request.session.session_key).get_decoded()
            if (not Users.is_authenticated(session_key = request.session.session_key, cookie = request.session)):
                raise CookieError
        except:
            # Bad cookie
            request.session.flush()
            return HttpResponseRedirect('/')
        else:
            user = Users.objects.get(id = dbCookie['id'])
            t = get_template('config.html')
            # Here we load all user information with context
            context = {'UserID': user.id,
                       'UserName': user.username,
                       'Name': user.name,
                       'Surname': user.surname,
                       'Email': user.email,
                       'Birthdate': user.birthdate,
                       'Gender': user.gender,
                       'section': 'Configuración'}
            if (request.session.get('configError', False)):
                context.update({ 'configError': request.session['configError'] })
                del request.session['configError']
            if (request.session.get('configOK', False)):
                context.update({ 'configOK': request.session['configOK'] })
                del request.session['configOK']
            if (request.session.get('passwordError', False)):
                context.update({ 'passwordError': request.session['passwordError'] })
                del request.session['passwordError']
            if (request.session.get('passwordOK', False)):
                context.update({ 'passwordOK': request.session['passwordOK'] })
                del request.session['passwordOK']
            c = RequestContext(request, context)
            return HttpResponse(t.render(c))    
Exemple #4
0
def home(request):
    try:
        id = request.session['id']
    except:
        # User is not logged in
        return HttpResponseRedirect('/')
    else:
        #User maybe has logged in
        try:
            dbCookie = Session.objects.get(session_key = request.session.session_key).get_decoded()
            if (not Users.is_authenticated(session_key = request.session.session_key, cookie = request.session)):
                raise CookieError
        except:
            # Bad cookie
            request.session.flush()
            return HttpResponseRedirect('/')
        else:
            user = Users.objects.get(id = dbCookie['id'])
            t = get_template('home.html')
            # Here we load all user information with context
            c = RequestContext(request, { 'UserName': user.username,
                                          'UserID': user.id,
                                          'section': 'Home' })
            return HttpResponse(t.render(c))
Exemple #5
0
def test_if_logout_works(step):
    world.response = world.browser.get('/user/logout')
    world.browser.session.flush()
    assert not Users.is_authenticated(session_key = world.browser.cookies['sessionid'].value, cookie = world.browser.session)