Sign out
Task: end the user's session.
yaml
# Recipe: signing out clears the session; the protected page is closed again.
paths:
components: ./components1
2
3
2
3
xml
<q:component name="Home" require_auth="true">
<h1>Hello, {session.userName}</h1>
<a href="/logout">Sign out</a>
</q:component>1
2
3
4
2
3
4
A page can change the session and then redirect: what it wrote to the session before q:redirect stays written.
xml
<q:component name="Logout">
<!-- A page that clears the session and redirects (ACT-7). -->
<q:set name="session.authenticated" value="false" type="boolean" />
<q:set name="session.userName" value="" />
<q:set name="session.userRole" value="" />
<q:redirect url="/login" flash="You are signed out." />
</q:component>1
2
3
4
5
6
7
2
3
4
5
6
7
xml
<q:component name="Login">
<q:if condition="flash"><p>{flash}</p></q:if>
<h1>Sign in</h1>
</q:component>1
2
3
4
2
3
4
The test signs in, signs out, and checks that the home page asks to sign in again:
xml
<q:test name="signing out ends the session" page="/">
<test:as user="ana" role="member" />
<test:visit />
<test:expect text="Hello, ana" />
<test:visit path="/logout" />
<test:expect status="302" redirect="/login" />
<test:expect text="You are signed out." />
<test:visit path="/" />
<test:expect status="302" redirect="/login" />
</q:test>1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
text
tests/logout.test.q
PASS signing out ends the session
1 passed, 0 failed1
2
3
2
3