-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alan Yeh <[email protected]>
- Loading branch information
Showing
15 changed files
with
156 additions
and
88 deletions.
There are no files selected for viewing
32 changes: 15 additions & 17 deletions
32
central-studio-views/central-identity-view/src/main/node/src/App.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
central-studio-views/central-identity-view/src/main/node/src/api/IdentityService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import type { Account } from '@/api/data/organization/Account' | ||
import axios from 'axios' | ||
import { sha256 } from 'js-sha256' | ||
|
||
const client = axios.create({ | ||
validateStatus: function(status: number) { | ||
return true | ||
} | ||
}) | ||
|
||
class IdentityService { | ||
/** | ||
* 登录 | ||
* @param account 帐户名 | ||
* @param password 密码 | ||
*/ | ||
public async login(account: string, password: string): Promise<void> { | ||
// 对密码进行 sha256 摘要后再提交 | ||
// 防止原始密码被截取 | ||
const hash = sha256.create() | ||
hash.update(password) | ||
|
||
const response = await client.post('/identity/api/login', { | ||
account: account, | ||
password: hash.hex(), | ||
secret: 'lLS4p6skBbBVZX30zR5' | ||
}) | ||
|
||
if (response.status !== 200) { | ||
throw new Error(response.data.message) | ||
} | ||
} | ||
|
||
/** | ||
* 退出登录 | ||
*/ | ||
public async logout(): Promise<void> { | ||
return client.get('/identity/api/logout', { | ||
headers: { | ||
'Accept': 'application/json' | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* 获取当前已登录用户 | ||
*/ | ||
public async getAccount(): Promise<Account | null> { | ||
try { | ||
const response = await client.get('/identity/api/account') | ||
if (response.status !== 200) { | ||
return null | ||
} | ||
return response.data | ||
} catch (error) { | ||
return null | ||
} | ||
} | ||
} | ||
|
||
export const identity = new IdentityService() |
2 changes: 1 addition & 1 deletion
2
.../src/main/node/src/data/authority/Role.ts → .../main/node/src/api/data/authority/Role.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
8 changes: 4 additions & 4 deletions
8
...node/src/data/organization/AccountUnit.ts → .../src/api/data/organization/AccountUnit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...c/main/node/src/data/organization/Area.ts → ...in/node/src/api/data/organization/Area.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../node/src/data/organization/Department.ts → ...e/src/api/data/organization/Department.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...tudio-views/central-identity-view/src/main/node/src/api/data/organization/Organization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { Account } from '@/api/data/organization/Account' | ||
import type { AccountUnit } from '@/api/data/organization/AccountUnit' | ||
import type { Area } from '@/api/data/organization/Area' | ||
import type { Department } from '@/api/data/organization/Department' | ||
import type { Rank } from '@/api/data/organization/Rank' | ||
import type { Unit } from '@/api/data/organization/Unit' | ||
|
||
export type { Account, AccountUnit, Area, Department, Rank, Unit } |
4 changes: 2 additions & 2 deletions
4
...c/main/node/src/data/organization/Rank.ts → ...in/node/src/api/data/organization/Rank.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...c/main/node/src/data/organization/Unit.ts → ...in/node/src/api/data/organization/Unit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
...al-studio-views/central-identity-view/src/main/node/src/data/organization/Organization.ts
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
central-studio-views/central-identity-view/src/main/node/src/stores/account.ts
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
central-studio-views/central-identity-view/src/main/node/src/stores/session.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { ref } from 'vue' | ||
import { defineStore } from 'pinia' | ||
import type { Account } from '@/api/data/organization/Organization' | ||
import { identity } from '@/api/IdentityService' | ||
|
||
export const useSessionStore = defineStore('session', () => { | ||
const account = ref<Account | null>(null) | ||
|
||
/** | ||
* 获取当前已登录的用户信息 | ||
* 如果当前用户未登录,将返回 null | ||
*/ | ||
async function getAccount(): Promise<Account | null> { | ||
if (!account.value) { | ||
account.value = await identity.getAccount() | ||
} | ||
return account.value | ||
} | ||
|
||
/** | ||
* 登录 | ||
* @param account 帐户名 | ||
* @param password 密码 | ||
*/ | ||
async function login(account: string, password: string): Promise<void> { | ||
return identity.login(account, password) | ||
} | ||
|
||
/** | ||
* 退出登录 | ||
*/ | ||
async function logout(): Promise<void> { | ||
return identity.logout() | ||
} | ||
|
||
return { getAccount, login, logout } | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 10 additions & 19 deletions
29
central-studio-views/central-identity-view/src/main/node/src/views/LoginView.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters