Skip to content

Commit 07c15e9

Browse files
authored
Merge pull request #9 from femioladeji/password-settings-page
Add support to password apps configuration
2 parents 809ba2d + 5dc0a59 commit 07c15e9

File tree

10 files changed

+160
-25
lines changed

10 files changed

+160
-25
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "Screentime",
44
"description": "To keep track and manage your time on sites that reduce productivity. You can set the number of minutes you want and time frames",
55
"short_name": "screentime",
6-
"version": "4.1.0",
6+
"version": "4.2.0",
77
"browser_action": {
88
"default_popup": "index.html",
99
"default_icon" : "images/icon_128.png"

package-lock.json

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "screentime",
3-
"version": "4.1.0",
3+
"version": "4.2.0",
44
"private": true,
55
"scripts": {
66
"serve": "vue-cli-service serve",
@@ -11,6 +11,7 @@
1111
"test:unit": "vue-cli-service test:unit"
1212
},
1313
"dependencies": {
14+
"bcryptjs": "^2.4.3",
1415
"chart.js": "^2.7.3",
1516
"vue": "^2.5.17",
1617
"vue-chartjs": "^3.4.0",

src/assets/js/dev_storage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const data = {
22
timer: {
3-
'2019-08-15': {
3+
'2020-08-24': {
44
instagram: 2000,
55
youtube: 2240,
66
twitter: 2000,

src/assets/js/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ storage.initialize();
66
export const DATAKEY = 'timer';
77
export const CONFIGKEY = 'sites';
88
export const SETTINGSKEY = 'settings';
9+
export const PASSWORDKEY = 'password';
910

1011
const ALLGRADIENTS = [
1112
{ from: '#5CEAF3', to: '#ACABE0' },

src/assets/main.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ body {
9494
text-align: center;
9595
}
9696

97+
.text-error {
98+
color: #d34f4f;
99+
}
100+
97101
.content {
98102
padding: 5% 30px;
99103
min-height: 320px;
@@ -371,9 +375,10 @@ a {
371375
background: #649EF7;
372376
}
373377

374-
.settings {
378+
.settings .box {
375379
align-items: center;
376380
justify-content: space-between;
381+
margin-bottom: 20px;
377382
}
378383

379384
.settings .theme-buttons {
@@ -382,6 +387,10 @@ a {
382387
border: 1px solid #E0E0E0;
383388
}
384389

390+
.settings .form input {
391+
width: 284px;
392+
}
393+
385394
.settings .theme-buttons .btn {
386395
border: none;
387396
width: 50%;

src/components/Apps.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<div class="site-actions">
1515
<switch-button @toggle="update" v-model="each.control"></switch-button>
1616
<router-link class="edit" :to="{ name: 'Advanced', params: { name: key }}">
17-
<!-- <img src="../assets/images/edit.png" /> -->
1817
</router-link>
1918
<img @click="remove(key)" src="../assets/images/trash.png" />
2019
</div>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<template>
2+
<div>
3+
<router-view v-if="isPageUnlocked"></router-view>
4+
<div v-else class="content">
5+
<form v-on:submit.prevent="unlockPage" class="form">
6+
<div class="input-field">
7+
<label>Enter password to edit configuration</label>
8+
<input v-model="password" type="password" />
9+
</div>
10+
<p v-if="errorMessage" class="text-center text-error">{{ errorMessage }}</p>
11+
<button type="submit" class="btn save">Continue</button>
12+
</form>
13+
</div>
14+
</div>
15+
</template>
16+
17+
<script>
18+
import bcrypt from 'bcryptjs';
19+
import utils, { SETTINGSKEY } from '../assets/js/utils';
20+
21+
export default {
22+
name: 'AppsConfiguration',
23+
data() {
24+
return {
25+
password: '',
26+
currentPassword: '',
27+
pageUnlocked: false,
28+
errorMessage: ''
29+
};
30+
},
31+
computed: {
32+
isPageUnlocked() {
33+
return !this.currentPassword || this.pageUnlocked;
34+
}
35+
},
36+
methods: {
37+
async getPassword() {
38+
const password = await utils.getData(SETTINGSKEY);
39+
this.currentPassword = password.password;
40+
},
41+
unlockPage() {
42+
if (bcrypt.compareSync(this.password, this.currentPassword)) {
43+
this.pageUnlocked = true;
44+
this.errorMessage = '';
45+
} else {
46+
this.errorMessage = 'Please enter a valid password';
47+
}
48+
}
49+
},
50+
mounted() {
51+
this.getPassword();
52+
}
53+
};
54+
</script>

src/components/Settings.vue

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<template>
22
<div class="content">
3-
<div class="box settings">
4-
Theme settings
5-
<div class="theme-buttons">
3+
<div class="settings">
4+
<div class="box">
5+
Theme settings
6+
<div class="theme-buttons">
67
<button
78
@click="setTheme('flash')"
89
class="btn"
@@ -15,19 +16,44 @@
1516
:disabled="theme == 'batman'">
1617
Batman
1718
</button>
19+
</div>
1820
</div>
21+
<form class="form" @submit.prevent="savePassword">
22+
<div v-if="isCurrentPassword" class="box">
23+
Current Password
24+
<div>
25+
<input v-model="oldPassword" type="password" />
26+
</div>
27+
</div>
28+
<div class="box">
29+
New Password
30+
<div>
31+
<input v-model="newPassword" type="password" />
32+
</div>
33+
</div>
34+
<div v-if="errorMessage" class="text-center text-error">{{ errorMessage }}</div>
35+
<div>
36+
<button type="submit" class="btn save">{{ buttonCaption }}</button>
37+
</div>
38+
</form>
1939
</div>
2040
</div>
2141
</template>
2242

2343
<script>
24-
import utils, { SETTINGSKEY } from '../assets/js/utils';
44+
import bcrypt from 'bcryptjs';
45+
import utils, { SETTINGSKEY, PASSWORDKEY } from '../assets/js/utils';
2546
2647
export default {
2748
name: 'Settings',
2849
data() {
2950
return {
30-
theme: ''
51+
theme: '',
52+
newPassword: '',
53+
oldPassword: '',
54+
isCurrentPassword: '',
55+
errorMessage: '',
56+
buttonCaption: 'Save Password'
3157
};
3258
},
3359
methods: {
@@ -40,11 +66,44 @@ export default {
4066
}
4167
utils.saveConfiguration(SETTINGSKEY, { theme });
4268
this.theme = theme;
69+
},
70+
async getTheme() {
71+
const settings = await utils.getData(SETTINGSKEY);
72+
this.theme = settings.theme || 'flash';
73+
},
74+
async getPassword() {
75+
const password = await utils.getData(SETTINGSKEY);
76+
this.isCurrentPassword = password.password;
77+
},
78+
async savePassword() {
79+
if (this.newPassword) {
80+
if (this.isCurrentPassword
81+
&& !bcrypt.compareSync(this.oldPassword, this.isCurrentPassword)) {
82+
this.errorMessage = 'Invalid old password';
83+
} else {
84+
const hashedPassword = bcrypt.hashSync(this.newPassword, 10);
85+
await utils.saveConfiguration(SETTINGSKEY, {
86+
[PASSWORDKEY]: hashedPassword
87+
});
88+
this.buttonCaption = 'Saving...';
89+
this.errorMessage = '';
90+
setTimeout(() => {
91+
this.resetFields(hashedPassword);
92+
}, 1500);
93+
}
94+
}
95+
},
96+
resetFields(hashedPassword) {
97+
this.newPassword = '';
98+
this.oldPassword = '';
99+
this.errorMessage = '';
100+
this.isCurrentPassword = hashedPassword;
101+
this.buttonCaption = 'Save Password';
43102
}
44103
},
45-
async mounted() {
46-
const settings = await utils.getData(SETTINGSKEY);
47-
this.theme = settings.theme || 'flash';
104+
mounted() {
105+
this.getTheme();
106+
this.getPassword();
48107
}
49108
};
50109
</script>

src/router.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Apps from '@/components/Apps';
55
import Index from '@/components/Index';
66
import Settings from '@/components/Settings';
77
import Advanced from '@/components/Advanced';
8+
import AppsConfiguration from '@/components/AppsConfiguration';
89

910
Vue.use(Router);
1011

@@ -15,24 +16,30 @@ export default new Router({
1516
name: 'Index',
1617
component: Index
1718
},
18-
{
19-
path: '/app',
20-
name: 'apps',
21-
component: Apps
22-
},
2319
{
2420
path: '/add',
2521
name: 'Add',
2622
component: Add
2723
},
28-
{
29-
path: '/app/:name',
30-
name: 'Advanced',
31-
component: Advanced
32-
},
3324
{
3425
path: '/settings',
3526
component: Settings
27+
},
28+
{
29+
path: '/app',
30+
component: AppsConfiguration,
31+
children: [
32+
{
33+
path: '/',
34+
name: 'apps',
35+
component: Apps
36+
},
37+
{
38+
path: '/:name',
39+
name: 'Advanced',
40+
component: Advanced
41+
}
42+
]
3643
}
3744
]
3845
});

0 commit comments

Comments
 (0)