diff --git a/public_html/asset/svg/minipopup.leave.svg b/public_html/asset/svg/minipopup.leave.svg index e11c7f3..c6de577 100644 --- a/public_html/asset/svg/minipopup.leave.svg +++ b/public_html/asset/svg/minipopup.leave.svg @@ -22,7 +22,7 @@ image/svg+xml - + @@ -49,7 +49,7 @@ inkscape:window-maximized="1" inkscape:current-layer="svg898" /> diff --git a/public_html/asset/svg/minipopup.password.svg b/public_html/asset/svg/minipopup.password.svg new file mode 100644 index 0000000..9e69d37 --- /dev/null +++ b/public_html/asset/svg/minipopup.password.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/webpack/lib/authentication.js b/webpack/lib/authentication.js index 64b24b0..94b7dd6 100644 --- a/webpack/lib/authentication.js +++ b/webpack/lib/authentication.js @@ -26,7 +26,16 @@ export default class Authentication{ * ---------------------------------------------------------*/ // TOKEN - get token(){ return this.lsi.fetch('token'); } + get token(){ + let tok = this.lsi.fetch('token'); + + // redirect if on 'auth' page + if( tok === null && gs.get.authed ) + document.location = ''; + + return tok; + } + set token(_token){ return this.lsi.push('token', _token); } // USER DATA diff --git a/webpack/lib/content-controller.js b/webpack/lib/content-controller.js index d080f2e..c1e6649 100644 --- a/webpack/lib/content-controller.js +++ b/webpack/lib/content-controller.js @@ -77,7 +77,7 @@ export default class ContentController{ change_username(username=null){ /* (1) Error: if invalid user_id */ - if( typeof username !== 'string' || username.length < 3 ) + if( typeof username !== 'string' || !/^[a-z0-9_-]{3,20}$/i.test(username) ) return false; /* (2) Error: unknown user */ @@ -85,7 +85,7 @@ export default class ContentController{ return false; /* (3) Call api UPDATE */ - api.call(`PUT /user/${this.uid}`, { username: username, password: null }, function(rs){ + api.call(`PUT /user/${this.uid}`, { username: username }, function(rs){ // manage error if( rs.error !== 0 ) @@ -109,5 +109,29 @@ export default class ContentController{ } + /* (7) Change password + * + * @password New password + * + ---------------------------------------------------------*/ + change_password(password=null){ + + /* (1) Error: if invalid user_id */ + if( typeof password !== 'string' || !/^[^<>\/\\]{8,50}$/.test(password) ) + return false; + + /* (2) Error: unknown user */ + if( this.uid == null ) + return false; + + /* (3) Call api UPDATE */ + api.call(`PUT /user/${this.uid}`, { password: password }, () => {}, auth.token); + + /* (4) Error */ + return true; + + } + + } \ No newline at end of file diff --git a/webpack/lib/popup-controller.js b/webpack/lib/popup-controller.js index e2908f3..b714586 100644 --- a/webpack/lib/popup-controller.js +++ b/webpack/lib/popup-controller.js @@ -66,6 +66,15 @@ export default class PopupController{ reset(){ }, submit(){ gs.get.channel.remove() && this.parent.hide(); } }); + /* (6) Change password */ + this.register('password.change', { + data: { + password: '', + confirm: '' + }, + reset(){ this.data.password = ''; this.data.confirm = ''; }, + submit(){ this.data.password === this.data.confirm && gs.get.content.change_password(this.data.password) && this.parent.hide(); } + }); } diff --git a/webpack/vue/auth/dialog.vue b/webpack/vue/auth/dialog.vue index d0b4615..b3a9f3e 100644 --- a/webpack/vue/auth/dialog.vue +++ b/webpack/vue/auth/dialog.vue @@ -61,6 +61,7 @@ &[data-icon='remove']{ background-image: url('/asset/svg/minipopup.remove.svg'); } &[data-icon='logout']{ background-image: url('/asset/svg/minipopup.logout.svg'); } &[data-icon='leave']{ background-image: url('/asset/svg/minipopup.leave.svg'); } + &[data-icon='password']{ background-image: url('/asset/svg/minipopup.password.svg'); } &:hover{ background-color: #f9f9f9; color: #737f8d; } @@ -104,6 +105,7 @@ Remove channel Create room Change nickname + Change password Leave channel Logout diff --git a/webpack/vue/auth/wrapper.vue b/webpack/vue/auth/wrapper.vue index 2527f00..9154d8d 100644 --- a/webpack/vue/auth/wrapper.vue +++ b/webpack/vue/auth/wrapper.vue @@ -112,6 +112,24 @@ + + +