Skip to content

Commit 1f75dfd

Browse files
committed
Merge branch 'develop' of github.com:OpenShock/Frontend into develop
2 parents 9eb2236 + 50b2d27 commit 1f75dfd

7 files changed

Lines changed: 193 additions & 7 deletions

File tree

src/lib/api/internal/v2/.openapi-generator/FILES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ models/HubCreateRequest.ts
1616
models/LcgNodeResponseV2.ts
1717
models/LegacyEmptyResponse.ts
1818
models/LoginV2.ts
19+
models/LoginV2OkResponse.ts
1920
models/OpenShockProblem.ts
2021
models/PasswordResetRequestV2.ts
22+
models/RoleType.ts
2123
models/ShareInviteBaseDetails.ts
2224
models/ShockerLimits.ts
2325
models/ShockerPermLimitPairWithId.ts

src/lib/api/internal/v2/apis/AccountApi.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type {
1818
ChangeUsernameRequest,
1919
LegacyEmptyResponse,
2020
LoginV2,
21+
LoginV2OkResponse,
2122
OpenShockProblem,
2223
PasswordResetRequestV2,
2324
SignUpV2,
@@ -30,6 +31,8 @@ import {
3031
LegacyEmptyResponseToJSON,
3132
LoginV2FromJSON,
3233
LoginV2ToJSON,
34+
LoginV2OkResponseFromJSON,
35+
LoginV2OkResponseToJSON,
3336
OpenShockProblemFromJSON,
3437
OpenShockProblemToJSON,
3538
PasswordResetRequestV2FromJSON,
@@ -124,12 +127,12 @@ export interface AccountApiInterface {
124127
* @throws {RequiredError}
125128
* @memberof AccountApiInterface
126129
*/
127-
accountLoginV2Raw(requestParameters: AccountLoginV2Request, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<LegacyEmptyResponse>>;
130+
accountLoginV2Raw(requestParameters: AccountLoginV2Request, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<LoginV2OkResponse>>;
128131

129132
/**
130133
* Authenticate a user
131134
*/
132-
accountLoginV2(loginV2?: LoginV2, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<LegacyEmptyResponse>;
135+
accountLoginV2(loginV2?: LoginV2, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<LoginV2OkResponse>;
133136

134137
/**
135138
*
@@ -267,7 +270,7 @@ export class AccountApi extends runtime.BaseAPI implements AccountApiInterface {
267270
/**
268271
* Authenticate a user
269272
*/
270-
async accountLoginV2Raw(requestParameters: AccountLoginV2Request, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<LegacyEmptyResponse>> {
273+
async accountLoginV2Raw(requestParameters: AccountLoginV2Request, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<LoginV2OkResponse>> {
271274
const queryParameters: any = {};
272275

273276
const headerParameters: runtime.HTTPHeaders = {};
@@ -285,13 +288,13 @@ export class AccountApi extends runtime.BaseAPI implements AccountApiInterface {
285288
body: LoginV2ToJSON(requestParameters['loginV2']),
286289
}, initOverrides);
287290

288-
return new runtime.JSONApiResponse(response, (jsonValue) => LegacyEmptyResponseFromJSON(jsonValue));
291+
return new runtime.JSONApiResponse(response, (jsonValue) => LoginV2OkResponseFromJSON(jsonValue));
289292
}
290293

291294
/**
292295
* Authenticate a user
293296
*/
294-
async accountLoginV2(loginV2?: LoginV2, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<LegacyEmptyResponse> {
297+
async accountLoginV2(loginV2?: LoginV2, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<LoginV2OkResponse> {
295298
const response = await this.accountLoginV2Raw({ loginV2: loginV2 }, initOverrides);
296299
return await response.value();
297300
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* OpenShock.API
5+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6+
*
7+
* The version of the OpenAPI document: 2
8+
*
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
import { mapValues } from '../runtime';
16+
import type { RoleType } from './RoleType';
17+
import {
18+
RoleTypeFromJSON,
19+
RoleTypeFromJSONTyped,
20+
RoleTypeToJSON,
21+
RoleTypeToJSONTyped,
22+
} from './RoleType';
23+
24+
/**
25+
*
26+
* @export
27+
* @interface LoginV2OkResponse
28+
*/
29+
export interface LoginV2OkResponse {
30+
/**
31+
*
32+
* @type {string}
33+
* @memberof LoginV2OkResponse
34+
*/
35+
accountId: string;
36+
/**
37+
*
38+
* @type {string}
39+
* @memberof LoginV2OkResponse
40+
*/
41+
accountName: string;
42+
/**
43+
*
44+
* @type {string}
45+
* @memberof LoginV2OkResponse
46+
*/
47+
accountEmail: string;
48+
/**
49+
*
50+
* @type {string}
51+
* @memberof LoginV2OkResponse
52+
*/
53+
profileImage: string;
54+
/**
55+
*
56+
* @type {Array<RoleType>}
57+
* @memberof LoginV2OkResponse
58+
*/
59+
accountRoles: Array<RoleType>;
60+
}
61+
62+
/**
63+
* Check if a given object implements the LoginV2OkResponse interface.
64+
*/
65+
export function instanceOfLoginV2OkResponse(value: object): value is LoginV2OkResponse {
66+
if (!('accountId' in value) || value['accountId'] === undefined) return false;
67+
if (!('accountName' in value) || value['accountName'] === undefined) return false;
68+
if (!('accountEmail' in value) || value['accountEmail'] === undefined) return false;
69+
if (!('profileImage' in value) || value['profileImage'] === undefined) return false;
70+
if (!('accountRoles' in value) || value['accountRoles'] === undefined) return false;
71+
return true;
72+
}
73+
74+
export function LoginV2OkResponseFromJSON(json: any): LoginV2OkResponse {
75+
return LoginV2OkResponseFromJSONTyped(json, false);
76+
}
77+
78+
export function LoginV2OkResponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): LoginV2OkResponse {
79+
if (json == null) {
80+
return json;
81+
}
82+
return {
83+
84+
'accountId': json['accountId'],
85+
'accountName': json['accountName'],
86+
'accountEmail': json['accountEmail'],
87+
'profileImage': json['profileImage'],
88+
'accountRoles': ((json['accountRoles'] as Array<any>).map(RoleTypeFromJSON)),
89+
};
90+
}
91+
92+
export function LoginV2OkResponseToJSON(json: any): LoginV2OkResponse {
93+
return LoginV2OkResponseToJSONTyped(json, false);
94+
}
95+
96+
export function LoginV2OkResponseToJSONTyped(value?: LoginV2OkResponse | null, ignoreDiscriminator: boolean = false): any {
97+
if (value == null) {
98+
return value;
99+
}
100+
101+
return {
102+
103+
'accountId': value['accountId'],
104+
'accountName': value['accountName'],
105+
'accountEmail': value['accountEmail'],
106+
'profileImage': value['profileImage'],
107+
'accountRoles': ((value['accountRoles'] as Array<any>).map(RoleTypeToJSON)),
108+
};
109+
}
110+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* OpenShock.API
5+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6+
*
7+
* The version of the OpenAPI document: 2
8+
*
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
/**
16+
*
17+
* @export
18+
* @enum {string}
19+
*/
20+
export enum RoleType {
21+
Support = 'Support',
22+
Staff = 'Staff',
23+
Admin = 'Admin',
24+
System = 'System'
25+
}
26+
27+
28+
export function instanceOfRoleType(value: any): boolean {
29+
for (const key in RoleType) {
30+
if (Object.prototype.hasOwnProperty.call(RoleType, key)) {
31+
if (RoleType[key as keyof typeof RoleType] === value) {
32+
return true;
33+
}
34+
}
35+
}
36+
return false;
37+
}
38+
39+
export function RoleTypeFromJSON(json: any): RoleType {
40+
return RoleTypeFromJSONTyped(json, false);
41+
}
42+
43+
export function RoleTypeFromJSONTyped(json: any, ignoreDiscriminator: boolean): RoleType {
44+
return json as RoleType;
45+
}
46+
47+
export function RoleTypeToJSON(value?: RoleType | null): any {
48+
return value as any;
49+
}
50+
51+
export function RoleTypeToJSONTyped(value: any, ignoreDiscriminator: boolean): RoleType {
52+
return value as RoleType;
53+
}
54+

src/lib/api/internal/v2/models/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ export * from './HubCreateRequest';
1010
export * from './LcgNodeResponseV2';
1111
export * from './LegacyEmptyResponse';
1212
export * from './LoginV2';
13+
export * from './LoginV2OkResponse';
1314
export * from './OpenShockProblem';
1415
export * from './PasswordResetRequestV2';
16+
export * from './RoleType';
1517
export * from './ShareInviteBaseDetails';
1618
export * from './ShockerLimits';
1719
export * from './ShockerPermLimitPairWithId';

src/lib/stores/UserStore.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ function setSelfName(name: string) {
3636
});
3737
}
3838

39+
async function setSelf(user: ApiUserSelf) {
40+
update((state) => ({
41+
...state,
42+
self: user,
43+
all: updateAllFromSelf(state.all, user),
44+
}));
45+
}
46+
3947
async function refreshSelf(): Promise<boolean> {
4048
update((v) => ({ ...v, loading: true }));
4149

@@ -80,6 +88,7 @@ export const UserStore = {
8088
set,
8189
update,
8290
setSelfName,
91+
setSelf,
8392
refreshSelf,
8493
reset,
8594
};

src/routes/(anonymous)/login/+page.svelte

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@
3535
}
3636
3737
try {
38-
await accountV2Api.accountLoginV2({ usernameOrEmail, password, turnstileResponse });
39-
await UserStore.refreshSelf();
38+
const account = await accountV2Api.accountLoginV2({ usernameOrEmail, password, turnstileResponse });
39+
UserStore.setSelf({
40+
id: account.accountId,
41+
name: account.accountName,
42+
avatar: account.profileImage,
43+
email: account.accountEmail,
44+
roles: account.accountRoles,
45+
});
4046
goto(page.url.searchParams.get('redirect') ?? '/home');
4147
} catch (error) {
4248
await handleApiError(error, (problem) => {

0 commit comments

Comments
 (0)