New UI layout
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

cookiehelper.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const cryptoProvider = window["CryptoJS"];
  2. const cryptoAlgorithm = window["CryptoJS"].AES;
  3. const _secretKey = "unibase";
  4. export function encrypt(content) {
  5. return cryptoAlgorithm.encrypt(content, _secretKey).toString();
  6. }
  7. export function decrypt(encoded) {
  8. return cryptoAlgorithm
  9. .decrypt(encoded, _secretKey)
  10. .toString(cryptoProvider.enc.Utf8);
  11. }
  12. export function setCookie(cname, cvalue, exdays) {
  13. let _cookievalue = "";
  14. if (cvalue) {
  15. _cookievalue = encrypt(cvalue);
  16. }
  17. var d = new Date();
  18. d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
  19. var expires = "expires=" + d.toUTCString();
  20. document.cookie =
  21. cname +
  22. "=" +
  23. _cookievalue +
  24. ";" +
  25. expires +
  26. ";path=/;samesite=none;secure=true";
  27. }
  28. export function getCookie(cname) {
  29. var name = cname + "=";
  30. var decodedCookie = decodeURIComponent(document.cookie);
  31. var ca = decodedCookie.split(";");
  32. for (var i = 0; i < ca.length; i++) {
  33. var c = ca[i];
  34. while (c.charAt(0) === " ") {
  35. c = c.substring(1);
  36. }
  37. if (c.indexOf(name) === 0) {
  38. var cookie = c.substring(name.length, c.length);
  39. var cookie_decrypt = decrypt(cookie);
  40. return cookie_decrypt;
  41. }
  42. }
  43. return "";
  44. }
  45. export function isAuthenticated() {
  46. if (getCookie("_idty")) {
  47. return true;
  48. }
  49. return false;
  50. }