Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit fa6a84d

Browse files
committed
raspberry pi auth opt in/out page
1 parent b44099c commit fa6a84d

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ exports.register = function (server, options, next) {
120120
}
121121
});
122122

123+
server.route({
124+
method: 'GET',
125+
path: '/raspberry-opt',
126+
handler: {
127+
file: {
128+
path: 'index.html'
129+
}
130+
}
131+
});
132+
123133
server.route({
124134
method: 'GET',
125135
path: '/login',

src/router/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import EventForm from '@/events/cd-event-form';
1111
import BookingConfirmation from '@/events/order/cd-booking-confirmation';
1212
import Login from '@/users/cd-login';
1313
import AccountType from '@/users/cd-account-type';
14+
import RaspberryOpt from '@/users/cd-raspberry-opt';
1415
import orderWrapper from '@/events/order/wrapper';
1516
import UserService from '@/users/service';
1617
import store from '@/store';
@@ -113,6 +114,11 @@ const router = new Router({
113114
name: 'AccountType',
114115
component: AccountType,
115116
},
117+
{
118+
path: '/raspberry-opt',
119+
name: 'RaspberryOpt',
120+
component: RaspberryOpt,
121+
},
116122
{
117123
path: '/login',
118124
name: 'Login',

src/users/cd-login.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
<p>
3636
{{ $t('The account for email {msg} is linked to a My Raspberry Pi account.', { msg: email }) }}
3737
</p>
38+
<p>
39+
<a :href="`/raspberry-opt?optIn=true`">{{$t('Opt this browser in to My Raspberry Pi authentication.')}}</a>
40+
</p>
3841
<p>
3942
<a :href="`/rpi/login?user=${email}`">{{$t('Login through My Raspberry Pi.')}}</a>
4043
</p>
@@ -104,10 +107,14 @@
104107
this.errors.clear();
105108
}
106109
if (response.body.ok === false) {
110+
if (response.body.why === 'raspberry-linked') {
111+
window.localStorage.setItem('rpiAuth', true);
112+
}
107113
this.errors.add({
108114
field: 'loginFailed',
109115
msg: response.body.why });
110116
} else {
117+
window.localStorage.clear('rpiAuth');
111118
const forumUrl = `^${Vue.config.forumsUrlBase}/auth/CoderDojo$`;
112119
if (this.redirectUrl.match(forumUrl)) {
113120
this.redirectTo(this.redirectUrl);

src/users/cd-raspberry-opt.vue

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<template>
2+
<div class="cd-auth-type container-fluid">
3+
<div class="row">
4+
<div class="cd-auth-type__box">
5+
<span v-if="rpiAuthFlag">
6+
<h3
7+
class="cd-auth-type__header"
8+
>{{ $t("This browser is opted in to My Raspberry Pi authentication.") }}</h3>
9+
<div class="form-group text-center">
10+
<button class="cd-auth-type__opt btn btn-primary" v-on:click="optOut">Opt Out</button>
11+
<div>
12+
</span>
13+
<span v-else>
14+
<h3
15+
class="cd-auth-type__header"
16+
>{{ $t("This browser is opted out of My Raspberry Pi authentication.") }}</h3>
17+
<div class="form-group text-center">
18+
<button class="cd-auth-type__opt btn btn-primary" v-on:click="optIn">Opt In</button>
19+
<div>
20+
</span>
21+
</div>
22+
</div>
23+
</div>
24+
</template>
25+
26+
<script>
27+
import store from '@/store';
28+
29+
export default {
30+
name: 'Auth-Type',
31+
created() {
32+
if (this.$route.query.optIn) {
33+
const rpiAuthFlag = window.localStorage.getItem('rpiAuth') === 'true';
34+
if (!rpiAuthFlag) {
35+
this.optIn();
36+
}
37+
}
38+
},
39+
data() {
40+
return {
41+
rpiAuthFlag: window.localStorage.getItem('rpiAuth') === 'true',
42+
};
43+
},
44+
store,
45+
methods: {
46+
optIn() {
47+
window.localStorage.setItem('rpiAuth', true);
48+
location.reload();
49+
},
50+
optOut() {
51+
window.localStorage.clear('rpiAuth');
52+
// reload and clear optIn query param
53+
location.href = location.href.split('?')[0];
54+
},
55+
},
56+
};
57+
</script>
58+
59+
<style scoped lang="less">
60+
@import "~@coderdojo/cd-common/common/_colors";
61+
@import "../common/styles/cd-primary-button.less";
62+
63+
.cd-auth-type {
64+
&__header {
65+
padding: 12px;
66+
}
67+
&__box {
68+
border-style: solid;
69+
border-color: @cd-orange;
70+
border-width: 1px 1px 3px 1px;
71+
padding: 32px 56px 56px;
72+
max-width: 425px;
73+
margin: 20px auto 128px;
74+
}
75+
76+
&__opt {
77+
.primary-button;
78+
}
79+
}
80+
</style>

0 commit comments

Comments
 (0)