user-authentication
This commit is contained in:
@@ -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'
|
||||
})
|
||||
}
|
@@ -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'
|
||||
})
|
||||
}
|
@@ -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'
|
||||
})
|
||||
}
|
@@ -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
|
||||
})
|
||||
}
|
@@ -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: ''
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user