From 906fe9758ecd6753d51c84d4e8f7059eedbcfc1a Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sun, 14 Feb 2021 22:49:06 +0800 Subject: [PATCH] Add profile links. --- web/src/auth/Auth.js | 11 +++++++++++ web/src/auth/Util.js | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/web/src/auth/Auth.js b/web/src/auth/Auth.js index 632ad1ed..888a218f 100644 --- a/web/src/auth/Auth.js +++ b/web/src/auth/Auth.js @@ -12,11 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. +import {trim} from "./Util"; + export let authConfig = { serverUrl: "http://example.com", // your Casdoor URL, like the official one: https://door.casbin.com appName: "app-example", // your Casdoor application name, like: "app-built-in" + organizationName: "org-example", // your Casdoor organization name, like: "built-in" } export function initAuthWithConfig(config) { authConfig = config; } + +export function getMyProfileUrl() { + return `${trim(authConfig.serverUrl)}/account` +} + +export function getUserProfileUrl(userName) { + return `${trim(authConfig.serverUrl)}/users/${authConfig.organizationName}/${userName}`; +} diff --git a/web/src/auth/Util.js b/web/src/auth/Util.js index 6a3fd2b0..adfbe2d6 100644 --- a/web/src/auth/Util.js +++ b/web/src/auth/Util.js @@ -25,3 +25,20 @@ export function showMessage(type, text) { message.error(text); } } + +export function trim(str, ch) { + if (str === undefined) { + return undefined; + } + + let start = 0; + let end = str.length; + + while(start < end && str[start] === ch) + ++start; + + while(end > start && str[end - 1] === ch) + --end; + + return (start > 0 || end < str.length) ? str.substring(start, end) : str; +}