user-authentication

This commit is contained in:
King Wang
2021-06-14 20:57:26 +08:00
parent 54c2f31f83
commit 7b18b2e3b2
38 changed files with 1418 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
import { ApiCall } from "tsrpc";
import { ReqAdminAction, ResAdminAction } from "../../shared/protocols/action/PtlAdminAction";
export async function ApiAdminAction(call: ApiCall<ReqAdminAction, ResAdminAction>) {
call.succ({
result: 'Success'
})
}

View File

@@ -0,0 +1,8 @@
import { ApiCall } from "tsrpc";
import { ReqGuestAction, ResGuestAction } from "../../shared/protocols/action/PtlGuestAction";
export async function ApiGuestAction(call: ApiCall<ReqGuestAction, ResGuestAction>) {
call.succ({
result: 'Success'
})
}

View File

@@ -0,0 +1,8 @@
import { ApiCall } from "tsrpc";
import { ReqNormalAction, ResNormalAction } from "../../shared/protocols/action/PtlNormalAction";
export async function ApiNormalAction(call: ApiCall<ReqNormalAction, ResNormalAction>) {
call.succ({
result: 'Success'
})
}

View File

@@ -0,0 +1,17 @@
import { ApiCall } from "tsrpc";
import { UserUtil } from "../../models/UserUtil";
import { ReqLogin, ResLogin } from "../../shared/protocols/user/PtlLogin";
export async function ApiLogin(call: ApiCall<ReqLogin, ResLogin>) {
let user = UserUtil.users.find(v => v.username === call.req.username && v.password === call.req.password);
if (!user) {
call.error('Error username or password');
return;
}
let sso = await UserUtil.createSsoToken(user.uid);
call.succ({
__ssoToken: sso
})
}

View File

@@ -0,0 +1,10 @@
import { ApiCall } from "tsrpc";
import { UserUtil } from "../../models/UserUtil";
import { ReqLogout, ResLogout } from "../../shared/protocols/user/PtlLogout";
export async function ApiLogout(call: ApiCall<ReqLogout, ResLogout>) {
call.req.__ssoToken && UserUtil.destroySsoToken(call.req.__ssoToken);
call.succ({
__ssoToken: ''
});
}