Remove lib docCookies
This commit is contained in:
parent
a1cbac0afb
commit
3ebc206e7d
|
|
@ -24,7 +24,6 @@ module.exports = {
|
||||||
"blessing": true,
|
"blessing": true,
|
||||||
"debounce": false,
|
"debounce": false,
|
||||||
"showModal": false,
|
"showModal": false,
|
||||||
"docCookies": false,
|
|
||||||
"showAjaxError": false,
|
"showAjaxError": false,
|
||||||
"getQueryString": false,
|
"getQueryString": false,
|
||||||
"TexturePreview": false
|
"TexturePreview": false
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,12 @@ class UserController extends Controller
|
||||||
|
|
||||||
if ($this->user->changePasswd($request->input('new_password'))) {
|
if ($this->user->changePasswd($request->input('new_password'))) {
|
||||||
event(new UserProfileUpdated($action, $this->user));
|
event(new UserProfileUpdated($action, $this->user));
|
||||||
return json(trans('user.profile.password.success'), 0);
|
|
||||||
|
session()->flush();
|
||||||
|
|
||||||
|
return json(trans('user.profile.password.success'), 0)
|
||||||
|
->withCookie(cookie()->forget('uid'))
|
||||||
|
->withCookie(cookie()->forget('token'));
|
||||||
}
|
}
|
||||||
|
|
||||||
break; // @codeCoverageIgnore
|
break; // @codeCoverageIgnore
|
||||||
|
|
@ -156,7 +161,10 @@ class UserController extends Controller
|
||||||
|
|
||||||
if ($this->user->setEmail($request->input('new_email'))) {
|
if ($this->user->setEmail($request->input('new_email'))) {
|
||||||
event(new UserProfileUpdated($action, $this->user));
|
event(new UserProfileUpdated($action, $this->user));
|
||||||
return json(trans('user.profile.email.success'), 0);
|
|
||||||
|
return json(trans('user.profile.email.success'), 0)
|
||||||
|
->withCookie(cookie()->forget('uid'))
|
||||||
|
->withCookie(cookie()->forget('token'));
|
||||||
}
|
}
|
||||||
|
|
||||||
break; // @codeCoverageIgnore
|
break; // @codeCoverageIgnore
|
||||||
|
|
|
||||||
|
|
@ -1125,10 +1125,8 @@ describe('tests for "common" module', () => {
|
||||||
it('send feedbacks', async () => {
|
it('send feedbacks', async () => {
|
||||||
const fetch = jest.fn()
|
const fetch = jest.fn()
|
||||||
.mockReturnValue(Promise.resolve({ errno: 0, msg: 'Recorded.' }));
|
.mockReturnValue(Promise.resolve({ errno: 0, msg: 'Recorded.' }));
|
||||||
const docCookies = require('../common/cookie');
|
|
||||||
|
|
||||||
window.document.cookie = '';
|
window.document.cookie = '';
|
||||||
window.docCookies = docCookies;
|
|
||||||
window.fetch = fetch;
|
window.fetch = fetch;
|
||||||
window.blessing = {
|
window.blessing = {
|
||||||
site_name: 'inm',
|
site_name: 'inm',
|
||||||
|
|
|
||||||
|
|
@ -3,43 +3,6 @@
|
||||||
const $ = require('jquery');
|
const $ = require('jquery');
|
||||||
window.jQuery = window.$ = $;
|
window.jQuery = window.$ = $;
|
||||||
|
|
||||||
describe('tests for "cookie" module', () => {
|
|
||||||
it('operates cookies', () => {
|
|
||||||
const cookies = require('../common/cookie');
|
|
||||||
|
|
||||||
expect(cookies.hasItem('key1')).toBe(false);
|
|
||||||
expect(cookies.getItem('key1')).toBeNull();
|
|
||||||
|
|
||||||
expect(cookies.setItem('key1', 'value1')).toBe(true);
|
|
||||||
expect(document.cookie).toBe('key1=value1');
|
|
||||||
expect(cookies.setItem('key2', 'value2')).toBe(true);
|
|
||||||
expect(document.cookie).toBe('key1=value1; key2=value2');
|
|
||||||
expect(cookies.hasItem('key1')).toBe(true);
|
|
||||||
expect(cookies.getItem('key1')).toBe('value1');
|
|
||||||
expect(cookies.hasItem('key2')).toBe(true);
|
|
||||||
expect(cookies.getItem('key2')).toBe('value2');
|
|
||||||
expect(cookies.keys()).toEqual(['key1', 'key2']);
|
|
||||||
|
|
||||||
expect(cookies.setItem('domain', 'value')).toBe(false);
|
|
||||||
|
|
||||||
expect(cookies.removeItem('key0')).toBe(false);
|
|
||||||
expect(cookies.removeItem('key2')).toBe(true);
|
|
||||||
expect(cookies.hasItem('key2')).toBe(false);
|
|
||||||
expect(document.cookie).toBe('key1=value1');
|
|
||||||
expect(cookies.removeItem('key1')).toBe(true);
|
|
||||||
|
|
||||||
expect(cookies.setItem('key3', 'value3', 50));
|
|
||||||
expect(cookies.getItem('key3')).toBe('value3');
|
|
||||||
expect(cookies.setItem('key3', 'value3', Infinity));
|
|
||||||
expect(cookies.getItem('key3')).toBe('value3');
|
|
||||||
expect(cookies.setItem('key3', 'value3', '60'));
|
|
||||||
expect(cookies.getItem('key3')).toBe('value3');
|
|
||||||
expect(cookies.setItem('key4', 'value3', new Date));
|
|
||||||
expect(cookies.removeItem('key3')).toBe(true);
|
|
||||||
expect(document.cookie).toBe('');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('tests for "i18n" module', () => {
|
describe('tests for "i18n" module', () => {
|
||||||
const modulePath = '../common/i18n';
|
const modulePath = '../common/i18n';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -850,7 +850,6 @@ describe('tests for "profile" module', () => {
|
||||||
|
|
||||||
it('change password', async () => {
|
it('change password', async () => {
|
||||||
const fetch = jest.fn()
|
const fetch = jest.fn()
|
||||||
.mockReturnValueOnce(Promise.resolve({ errno: 0, msg: 'success' }))
|
|
||||||
.mockReturnValueOnce(Promise.resolve({ errno: 0, msg: 'success' }))
|
.mockReturnValueOnce(Promise.resolve({ errno: 0, msg: 'success' }))
|
||||||
.mockReturnValueOnce(Promise.resolve({ errno: 1, msg: 'warning' }))
|
.mockReturnValueOnce(Promise.resolve({ errno: 1, msg: 'warning' }))
|
||||||
.mockReturnValueOnce(Promise.reject());
|
.mockReturnValueOnce(Promise.reject());
|
||||||
|
|
@ -862,19 +861,12 @@ describe('tests for "profile" module', () => {
|
||||||
warning: jest.fn()
|
warning: jest.fn()
|
||||||
};
|
};
|
||||||
const showAjaxError = jest.fn();
|
const showAjaxError = jest.fn();
|
||||||
const docCookies = {
|
|
||||||
removeItem: jest.fn()
|
|
||||||
};
|
|
||||||
window.fetch = fetch;
|
window.fetch = fetch;
|
||||||
window.swal = swal;
|
window.swal = swal;
|
||||||
window.trans = trans;
|
window.trans = trans;
|
||||||
window.url = url;
|
window.url = url;
|
||||||
window.toastr = toastr;
|
window.toastr = toastr;
|
||||||
window.showAjaxError = showAjaxError;
|
window.showAjaxError = showAjaxError;
|
||||||
window.logout = jest.fn()
|
|
||||||
.mockReturnValueOnce(Promise.resolve({ errno: 0 }))
|
|
||||||
.mockReturnValueOnce(Promise.reject());
|
|
||||||
window.docCookies = docCookies;
|
|
||||||
|
|
||||||
document.body.innerHTML = `
|
document.body.innerHTML = `
|
||||||
<input id="password" />
|
<input id="password" />
|
||||||
|
|
@ -911,10 +903,6 @@ describe('tests for "profile" module', () => {
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: { current_password: 'password', new_password: 'new-password' }
|
data: { current_password: 'password', new_password: 'new-password' }
|
||||||
});
|
});
|
||||||
expect(logout).toBeCalled();
|
|
||||||
|
|
||||||
await changePassword();
|
|
||||||
expect(docCookies.removeItem).toBeCalledWith('token');
|
|
||||||
|
|
||||||
await changePassword();
|
await changePassword();
|
||||||
expect(swal).toBeCalledWith({ type: 'warning', text: 'warning' });
|
expect(swal).toBeCalledWith({ type: 'warning', text: 'warning' });
|
||||||
|
|
@ -925,9 +913,8 @@ describe('tests for "profile" module', () => {
|
||||||
|
|
||||||
it('change email', async () => {
|
it('change email', async () => {
|
||||||
const fetch = jest.fn()
|
const fetch = jest.fn()
|
||||||
.mockReturnValueOnce(Promise.resolve({ errno: 0, msg: 'success' }))
|
|
||||||
.mockReturnValueOnce(Promise.resolve({ errno: 0, msg: 'success' }))
|
|
||||||
.mockReturnValueOnce(Promise.resolve({ errno: 1, msg: 'warning' }))
|
.mockReturnValueOnce(Promise.resolve({ errno: 1, msg: 'warning' }))
|
||||||
|
.mockReturnValueOnce(Promise.resolve({ errno: 0, msg: 'success' }))
|
||||||
.mockReturnValueOnce(Promise.reject());
|
.mockReturnValueOnce(Promise.reject());
|
||||||
const swal = jest.fn()
|
const swal = jest.fn()
|
||||||
.mockReturnValueOnce(Promise.resolve())
|
.mockReturnValueOnce(Promise.resolve())
|
||||||
|
|
@ -941,19 +928,12 @@ describe('tests for "profile" module', () => {
|
||||||
warning: jest.fn()
|
warning: jest.fn()
|
||||||
};
|
};
|
||||||
const showAjaxError = jest.fn();
|
const showAjaxError = jest.fn();
|
||||||
const docCookies = {
|
|
||||||
removeItem: jest.fn()
|
|
||||||
};
|
|
||||||
window.fetch = fetch;
|
window.fetch = fetch;
|
||||||
window.swal = swal;
|
window.swal = swal;
|
||||||
window.trans = trans;
|
window.trans = trans;
|
||||||
window.url = url;
|
window.url = url;
|
||||||
window.toastr = toastr;
|
window.toastr = toastr;
|
||||||
window.showAjaxError = showAjaxError;
|
window.showAjaxError = showAjaxError;
|
||||||
window.logout = jest.fn()
|
|
||||||
.mockReturnValueOnce(Promise.resolve({ errno: 0 }))
|
|
||||||
.mockReturnValueOnce(Promise.reject());
|
|
||||||
window.docCookies = docCookies;
|
|
||||||
|
|
||||||
document.body.innerHTML = `
|
document.body.innerHTML = `
|
||||||
<input id="new-email" />
|
<input id="new-email" />
|
||||||
|
|
@ -985,15 +965,11 @@ describe('tests for "profile" module', () => {
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: { new_email: 'a@b.c', password: 'pwd' }
|
data: { new_email: 'a@b.c', password: 'pwd' }
|
||||||
});
|
});
|
||||||
expect(swal).toBeCalledWith({ type: 'success', text: 'success' });
|
|
||||||
expect(logout).toBeCalled();
|
|
||||||
|
|
||||||
await changeEmail();
|
|
||||||
expect(docCookies.removeItem).toBeCalled();
|
|
||||||
|
|
||||||
await changeEmail();
|
|
||||||
expect(swal).toBeCalledWith({ type: 'warning', text: 'warning' });
|
expect(swal).toBeCalledWith({ type: 'warning', text: 'warning' });
|
||||||
|
|
||||||
|
await changeEmail();
|
||||||
|
expect(swal).toBeCalledWith({ type: 'success', text: 'success' });
|
||||||
|
|
||||||
await changeEmail();
|
await changeEmail();
|
||||||
expect(showAjaxError).toBeCalled();
|
expect(showAjaxError).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,9 @@ function initTables() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendFeedback() {
|
async function sendFeedback() {
|
||||||
if (docCookies.getItem('feedback_sent') !== null)
|
if (document.cookie.replace(/(?:(?:^|.*;\s*)feedback_sent\s*=\s*([^;]*).*$)|^.*$/, '$1') !== '') {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { errno } = await fetch({
|
const { errno } = await fetch({
|
||||||
|
|
@ -41,8 +42,8 @@ async function sendFeedback() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (errno === 0) {
|
if (errno === 0) {
|
||||||
// Will be expired when current session ends
|
// It will be expired when current session ends
|
||||||
docCookies.setItem('feedback_sent', Date.now());
|
document.cookie = 'feedback_sent=' + Date.now();
|
||||||
|
|
||||||
console.log('Feedback sent. Thank you!');
|
console.log('Feedback sent. Thank you!');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
||||||
/* eslint-disable */
|
|
||||||
|
|
||||||
/*\
|
|
||||||
|*|
|
|
||||||
|*| :: cookies.js ::
|
|
||||||
|*|
|
|
||||||
|*| A complete cookies reader/writer framework with full unicode support.
|
|
||||||
|*|
|
|
||||||
|*| https://developer.mozilla.org/en-US/docs/DOM/document.cookie
|
|
||||||
|*|
|
|
||||||
|*| This framework is released under the GNU Public License, version 3 or later.
|
|
||||||
|*| http://www.gnu.org/licenses/gpl-3.0-standalone.html
|
|
||||||
|*|
|
|
||||||
|*| Syntaxes:
|
|
||||||
|*|
|
|
||||||
|*| * docCookies.setItem(name, value[, end[, path[, domain[, secure]]]])
|
|
||||||
|*| * docCookies.getItem(name)
|
|
||||||
|*| * docCookies.removeItem(name[, path], domain)
|
|
||||||
|*| * docCookies.hasItem(name)
|
|
||||||
|*| * docCookies.keys()
|
|
||||||
|*|
|
|
||||||
\*/
|
|
||||||
|
|
||||||
var docCookies = {
|
|
||||||
getItem: function (sKey) {
|
|
||||||
return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
|
|
||||||
},
|
|
||||||
setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
|
|
||||||
if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) { return false; }
|
|
||||||
var sExpires = "";
|
|
||||||
if (vEnd) {
|
|
||||||
switch (vEnd.constructor) {
|
|
||||||
case Number:
|
|
||||||
sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd;
|
|
||||||
break;
|
|
||||||
case String:
|
|
||||||
sExpires = "; expires=" + vEnd;
|
|
||||||
break;
|
|
||||||
case Date:
|
|
||||||
sExpires = "; expires=" + vEnd.toUTCString();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
document.cookie = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : "");
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
removeItem: function (sKey, sPath, sDomain) {
|
|
||||||
if (!sKey || !this.hasItem(sKey)) { return false; }
|
|
||||||
document.cookie = encodeURIComponent(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + ( sDomain ? "; domain=" + sDomain : "") + ( sPath ? "; path=" + sPath : "");
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
hasItem: function (sKey) {
|
|
||||||
return (new RegExp("(?:^|;\\s*)" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie);
|
|
||||||
},
|
|
||||||
keys: /* optional method: you can safely remove it! */ function () {
|
|
||||||
var aKeys = document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, "").split(/\s*(?:\=[^;]*)?;\s*/);
|
|
||||||
for (var nIdx = 0; nIdx < aKeys.length; nIdx++) { aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]); }
|
|
||||||
return aKeys;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'test') {
|
|
||||||
module.exports = docCookies;
|
|
||||||
}
|
|
||||||
|
|
@ -70,18 +70,13 @@ async function changePassword() {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (errno === 0) {
|
if (errno === 0) {
|
||||||
try {
|
await swal({
|
||||||
await swal({
|
type: 'success',
|
||||||
type: 'success',
|
text: msg
|
||||||
text: msg
|
});
|
||||||
});
|
|
||||||
await logout();
|
// Cookies were already deleted by remote server
|
||||||
} catch (error) {
|
return window.location = url('auth/login');
|
||||||
docCookies.removeItem('token') && console.warn(error);
|
|
||||||
} finally {
|
|
||||||
window.location = url('auth/login');
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
return swal({ type: 'warning', text: msg });
|
return swal({ type: 'warning', text: msg });
|
||||||
}
|
}
|
||||||
|
|
@ -136,14 +131,8 @@ async function changeEmail() {
|
||||||
type: 'success',
|
type: 'success',
|
||||||
text: msg
|
text: msg
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
return window.location = url('auth/login');
|
||||||
await logout();
|
|
||||||
} catch (error) {
|
|
||||||
docCookies.removeItem('token') && console.warn(error);
|
|
||||||
} finally {
|
|
||||||
window.location = url('auth/login');
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return swal({ type: 'warning', text: msg });
|
return swal({ type: 'warning', text: msg });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user