Skip to content

Commit

Permalink
[fix] some detail bugs
Browse files Browse the repository at this point in the history
Signed-off-by: TechQuery <shiy2008@gmail.com>
  • Loading branch information
TechQuery committed Jan 22, 2025
1 parent 66f7edb commit 0b02618
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 57 deletions.
7 changes: 0 additions & 7 deletions models/Base/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ export class UserModel extends BaseListModel<User> {
return (this.session = body!);
}

@toggle('downloading')
async getSession() {
const { body } = await this.client.get<User>(`${this.baseURI}/session`);

return (this.session = body!);
}

async signOut() {
this.session = undefined;

Expand Down
25 changes: 15 additions & 10 deletions models/Personnel/Election.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { VoteTicket } from '@kaiyuanshe/kys-service';
import { observable } from 'mobx';
import { BaseModel, persist, restore, toggle } from 'mobx-restful';

import { isServer } from '../Base';
import userStore from '../Base/User';

export interface VoteTicket {
electionName: string;
publicKey: string;
signature: string;
}
export const buffer2hex = (buffer: ArrayBufferLike) =>
Array.from(new Uint8Array(buffer), x => x.toString(16).padStart(2, '0')).join(
'',
);

export class ElectionModel extends BaseModel {
client = userStore.client;
algorithm = { name: 'ECDSA', namedCurve: 'P-384' };
algorithm = { name: 'ECDSA', namedCurve: 'P-384', hash: { name: 'SHA-256' } };

@persist()
@observable
Expand All @@ -25,7 +26,7 @@ export class ElectionModel extends BaseModel {
@observable
accessor currentVoteTicket: VoteTicket | undefined;

restored = restore(this, 'Electron');
restored = !isServer() && restore(this, 'Electron');

@toggle('uploading')
async makePublicKey() {
Expand All @@ -47,17 +48,21 @@ export class ElectionModel extends BaseModel {

@toggle('uploading')
async savePublicKey(electionName: string, jsonWebKey = this.publicKey) {
await userStore.restored;

const { body } = await this.client.post(
`election/${electionName}/public-key`,
{ jsonWebKey },
);
await userStore.getSession();

return body!;
}

@toggle('uploading')
async signVoteTicket(electionName: string) {
await this.restored;

if (this.currentVoteTicket) return this.currentVoteTicket;

await this.makePublicKey();
await this.savePublicKey(electionName);

Expand All @@ -69,7 +74,7 @@ export class ElectionModel extends BaseModel {
return (this.currentVoteTicket = {
electionName,
publicKey: this.publicKey,
signature: new TextDecoder().decode(signature),
signature: buffer2hex(signature),
});
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@eslint/compat": "^1.2.5",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.18.0",
"@kaiyuanshe/kys-service": "^1.0.0-rc.1",
"@kaiyuanshe/kys-service": "^1.0.0-rc.2",
"@softonus/prettier-plugin-duplicate-remover": "^1.1.2",
"@types/eslint-config-prettier": "^6.11.3",
"@types/eslint__eslintrc": "^2.1.2",
Expand Down
45 changes: 23 additions & 22 deletions pages/election/[year]/vote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,32 @@ export default class ElectionVotePage extends Component<
await this.electionStore.signVoteTicket(this.electionName);
}

renderVoteForm = () => (
<SessionBox autoCover>
<Row xs={1} sm={2}>
<Col>
<h2 className="text-center">{t('director_election_voting')}</h2>
<iframe
className="w-100 vh-100 border-0"
src={`${VoteForm.理事}?${this.formData}`}
/>
</Col>
<Col>
<h2 className="text-center">{t('member_application_voting')}</h2>
<iframe
className="w-100 vh-100 border-0"
src={`${VoteForm.正式成员}?${this.formData}`}
/>
</Col>
</Row>
</SessionBox>
renderVoteForm = (formData: URLSearchParams) => (
<Row xs={1} sm={2}>
<Col>
<h2 className="text-center">{t('director_election_voting')}</h2>
<iframe
className="w-100 vh-100 border-0"
src={`${VoteForm.理事}?${formData}`}
/>
</Col>
<Col>
<h2 className="text-center">{t('member_application_voting')}</h2>
<iframe
className="w-100 vh-100 border-0"
src={`${VoteForm.正式成员}?${formData}`}
/>
</Col>
</Row>
);

render() {
const { year } = this.props.route.params!,
const { props, electionStore, formData } = this;
const { year } = props.route.params!,
electionVoting = textJoin(t('election'), t('voting'));

const title = `${year} ${electionVoting}`,
loading = this.electionStore.uploading > 0;
loading = electionStore.uploading > 0;

return (
<Container className="my-4">
Expand All @@ -88,7 +87,9 @@ export default class ElectionVotePage extends Component<

{loading && <Loading />}

{this.renderVoteForm()}
<SessionBox autoCover>
{formData && this.renderVoteForm(formData)}
</SessionBox>
</Container>
);
}
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions translation/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,6 @@ export default {
this_term_proposition: 'This term proposition',
recommendation: 'recommendation',
vote_for_me: 'Vote for Me',
vote_code_save_tips:
'Please copy the one-time "Vote Verification Code" of this election to avoid being unable to vote when this page is accidentally closed and reopened.',
vote_code_fill_tips:
'Please paste the "Vote Verification Code" copied when you first opened this voting page below.',

// Member pages
related: 'Related',
Expand Down
4 changes: 0 additions & 4 deletions translation/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,6 @@ export default {
this_term_proposition: '本届主张',
recommendation: '推荐语',
vote_for_me: '投我一票',
vote_code_save_tips:
'请复制本次选举的一次性“投票校验码”,以免本页面意外关闭后再次打开时无法投票。',
vote_code_fill_tips:
'请将本次选举首次打开本投票页时复制的“投票校验码”粘贴于下方投票表单内。',

// Member pages
related: '相关',
Expand Down
4 changes: 0 additions & 4 deletions translation/zh-TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,6 @@ export default {
this_term_proposition: '本屆主張',
recommendation: '推薦語',
vote_for_me: '投我一票',
vote_code_save_tips:
'請複製本次選舉的一次性“投票校驗碼”,以免本頁面意外關閉後再次打開時無法投票。',
vote_code_fill_tips:
'請將本次選舉首次打開本投票頁時複製的“投票校驗碼”粘貼於下方投票表單內。',

// Member pages
related: '相關',
Expand Down

1 comment on commit 0b02618

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for kaiyuanshe ready!

✅ Preview
https://kaiyuanshe-oi4i0l0k6-techquerys-projects.vercel.app

Built with commit 0b02618.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.