Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
fix: substitute wrong links and fix send mail
Browse files Browse the repository at this point in the history
  • Loading branch information
tassiluca committed Feb 1, 2024
1 parent 9da5f6f commit b362d1d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 113 deletions.
12 changes: 2 additions & 10 deletions api-service/api/src/controllers/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ export async function generateCodeFor(req: Request, res: Response, next: NextFun
// Divide the code in two parts
const firstPart = code.substring(0, code.length/2);
const secondPart = code.substring(code.length/2, code.length);

res.locals.code = StatusCodes.CREATED;
res.locals.data = firstPart;


const message = {
from: 'ChainVote',
to: res.locals.user.email,
Expand All @@ -138,12 +133,9 @@ export async function generateCodeFor(req: Request, res: Response, next: NextFun
This is the other part of your code: <b>${secondPart}</b>
`
};
const info = await mailer.sendMail(message);
await mailer.sendMail(message).catch((error: any) => next(error));
res.locals.code = StatusCodes.CREATED;
res.locals.data = {
msg: "Email sent",
info: info.messageId
}
res.locals.data = firstPart;
} catch (error) {
return next(transformHyperledgerError(error));
}
Expand Down
9 changes: 3 additions & 6 deletions api-service/api/src/controllers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ export async function passwordForgotten(req: Request, res: Response, next: NextF
const data = {'password': password}
try {
await User.updateOne({ email: req.body.email }, data);
res.locals.code = StatusCodes.OK;
res.locals.data = true;
} catch(error) {
return next(error);
}
Expand All @@ -199,11 +197,10 @@ export async function passwordForgotten(req: Request, res: Response, next: NextF
This is the new password: <b>${password}</b>
`
};
const info = await mailer.sendMail(message)
res.locals.code = 201
await mailer.sendMail(message).catch((error: any) => next(error));
res.locals.code = StatusCodes.CREATED;
res.locals.data = {
msg: "Email sent",
info: info.messageId
msg: "Email sent"
}
return next();
}
2 changes: 1 addition & 1 deletion frontend/src/components/ElectionCardComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ul>
<div class="d-flex flex-column links">
<a :href="`/elections/${election.id}`">See details</a>
<a v-if="isOpen(election) && authStore.userRole !== Role.Admin" :href="`/vote/${election.id}`">Cast a vote</a>
<a v-if="isOpen(election) && authStore.userRole !== Role.Admin" :href="`/insert-code/${election.id}`">Cast a vote</a>
<a v-if="isOpen(election) && authStore.userRole !== Role.Admin" href="#" @click="$emit('openModal', election.id, election.goal)">Get code</a>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ElectionComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
<div class="d-flex justify-content-center flex-wrap">
<a :href="`/elections/${election.id}`" class="useful-link">Details</a>
<a :href="`/vote/${election.id}`" class="useful-link" v-if="isOpen(election) && authStore.userRole !== Role.Admin">Vote</a>
<a :href="`/insert-code/${election.id}`" class="useful-link" v-if="isOpen(election) && authStore.userRole !== Role.Admin">Vote</a>
<a class="useful-link" v-if="isOpen(election) && authStore.userRole !== Role.Admin" @click="$emit('openModal', election.id, election.goal)" href="#">Get code</a>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/vote/RequestCodeModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function sendCodeRequest(id: string) {
axios.post(`${apiEndpoints.API_SERVER}/code/generate`, { electionId: id })
.then((response) => {
code.value = response.data.data
console.log(code.value)
codeRequest.value = true
requestError.value = false
}).catch((error) => {
Expand Down Expand Up @@ -51,7 +52,7 @@ function sendCodeRequest(id: string) {
</p>
</div>
<div class="row mb-2">
<p>Already have a code? <a href="#toElectionPage">Vote now</a></p>
<p>Already have a code? <a :href="`/insert-code/${electionId}`">Vote now</a></p>
</div>
<div class="row mb-2">
<form @submit.prevent="sendCodeRequest(electionId)">
Expand Down
94 changes: 1 addition & 93 deletions frontend/src/views/ElectionsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,99 +48,7 @@ function updateNow() {
async function getVotings() {
try {
// data.value = await votingStore.getVotings();
data.value = [
{
id: 1,
goal: "Goal 1",
voters: 100,
start: new Date(),
end: new Date(10938943246341),
choices: [
{name: "Choice 1"},
{name: "Choice 2"},
{name: "Choice 3"},
],
results: {
"Choice 1": 10,
"Choice 2": 20,
"Choice 3": 30,
},
turnout: "10",
},
{
id: 2,
goal: "Goal 2",
voters: 100,
start: new Date(),
end: new Date(10938943246341),
choices: [
{name: "Choice 1"},
{name: "Choice 2"},
{name: "Choice 3"},
],
results: {
"Choice 1": 10,
"Choice 2": 20,
"Choice 3": 30,
},
turnout: "10",
},
{
id: 3,
goal: "Goal 3",
voters: 100,
start: new Date(),
end: new Date(10938943246341),
choices: [
{name: "Choice 1"},
{name: "Choice 2"},
{name: "Choice 3"},
],
results: {
"Choice 1": 10,
"Choice 2": 20,
"Choice 3": 30,
},
turnout: "10",
},
{
id: 4,
goal: "Goal 4",
voters: 100,
start: new Date(),
end: new Date(10938943246341),
choices: [
{name: "Choice 1"},
{name: "Choice 2"},
{name: "Choice 3"},
],
results: {
"Choice 1": 10,
"Choice 2": 20,
"Choice 3": 30,
},
turnout: "10",
},
{
id: 5,
goal: "Goal 5",
voters: 100,
start: new Date(),
end: new Date(10938943246341),
choices: [
{name: "Choice 1"},
{name: "Choice 2"},
{name: "Choice 3"},
],
results: {
"Choice 1": 10,
"Choice 2": 20,
"Choice 3": 30,
},
turnout: "10",
},
]
data.value = await votingStore.getVotings();
} catch (e: any) {
console.error(e);
await router.push({name: "not-found"})
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/views/VoteView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
async function submitForm() {
submitting.value = true;
response.value= await useVotingStore().castVote(choosedOption.value);
try {
response.value = await useVotingStore().castVote(choosedOption.value);
} catch (e: any) {
response.value = {
success: false,
msg: e.response.data.error.message,
};
}
submitting.value = false;
}
Expand Down

0 comments on commit b362d1d

Please sign in to comment.