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

Commit

Permalink
Sent verification email
Browse files Browse the repository at this point in the history
  • Loading branch information
MoinJulian committed May 5, 2024
1 parent c7e4280 commit c174e8d
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 28 deletions.
50 changes: 50 additions & 0 deletions src/routes/dashboard/settings/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SECRET_NOREPLY_EMAIL_PASSWORD } from '$env/static/private';
import { change_animation } from '$lib/server/user/account/change_animation';
import { change_email } from '$lib/server/user/account/change_email';
import { change_handicap } from '$lib/server/user/account/change_handicap';
Expand All @@ -11,6 +12,7 @@ import { User_Model } from '$lib/server/user/models';
import { cookie_options } from '$lib/server/user/utils';
import { fail, redirect, type Actions } from '@sveltejs/kit';
import type { Types } from 'mongoose';
import nodemailer from 'nodemailer';
import type { PageServerLoad } from '../$types';

interface HandicapHistory {
Expand Down Expand Up @@ -211,5 +213,53 @@ export const actions: Actions = {
const message = `Your animation settings got changed`;

return { message, animation };
},
verify: async (event) => {
const data = await event.request.formData();
const email = (data.get('email') as string)?.toLowerCase()?.trim();

const user = await User_Model?.findOne({ 'user.email': email });

const verification_code = user?.user?.verification_code as string;
const name = user?.user?.name;

const transporter = nodemailer.createTransport({
host: 'mail.privateemail.com',
port: 465,
secure: true,
auth: {
user: 'noreply@realgolf.games',
pass: `${SECRET_NOREPLY_EMAIL_PASSWORD}`
}
});

async function sendEmail() {
try {
// send mail with defined transport object
const info = await transporter.sendMail({
from: 'RealGolf.Games <noreply@realgolf.games>',
to: `'${name}' <${email}>`,
subject: 'Verification Code for RealGolf.Games Account',
html: `
Your verification code is: ${verification_code} <br/>
Please enter this code in the verification form to complete your registration. <br/>
<a href="https://realgolf.games/verify">Click here to verify your account</a>
`
});

console.log('Message sent: %s', info.messageId);

const message = 'Email sent succesfully';

return { message };
} catch (error) {
console.error('Error sending email:', error);

return { error };
}
}

await sendEmail();
}
};
66 changes: 39 additions & 27 deletions src/routes/dashboard/settings/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

<div class="id">
<p>{$_('your_id')}: {data.id}</p>
<button on:click={() => copy_to_clipboard(data.id)}>{$_("copy_id")}</button>
<button on:click={() => copy_to_clipboard(data.id)}>{$_('copy_id')}</button>
<p>
{$_('your_id_info')}
</p>
Expand Down Expand Up @@ -139,6 +139,18 @@
<button aria-label="update password">{$_('update')}</button>
</div>
</form>

<form action="?/verify" method="POST" autocomplete="off" class="update-form">
<div>
<label for="verification">Enter your email to verify</label>
<div>
<label for="email_input">{$_('email')}</label>
<input type="email" id="email_input" name="email" />
</div>
</div>

<button>Send</button>
</form>
</div>

<div class="handicap">
Expand All @@ -153,12 +165,12 @@
})}
</p>
<p>
{$_("when_handicap_changed")}
{$_('when_handicap_changed')}
</p>

<div id="update-handicap">
<form action="?/handicap" method="POST" class="handicap-form">
<label for="handicap">{$_("enter_new_handicap")}</label>
<label for="handicap">{$_('enter_new_handicap')}</label>
<input type="string" name="handicap" id="handicap" bind:value={data.handicap} />
<button aria-label="Update Handicap">{$_('update')}</button>
</form>
Expand All @@ -167,28 +179,28 @@
{#if handicap_history && handicap_history.length > 0}
<div class="handicap_history">
<details>
<summary>{$_("handicap_hstory")}</summary>
<summary>{$_('handicap_hstory')}</summary>
{#each handicap_history.slice().reverse() as handicap}
<div>
<p>{$_("handicap")}: {handicap.handicap}</p>
<p>{$_("updated_at_the")}: {new Date(handicap.date).toLocaleString()}</p>
<p>{$_('handicap')}: {handicap.handicap}</p>
<p>{$_('updated_at_the')}: {new Date(handicap.date).toLocaleString()}</p>
</div>
{/each}
<form action="?/clear_handicap_history" method="POST">
<button>{$_("clear_history")}</button>
<button>{$_('clear_history')}</button>
</form>
</details>
</div>
{/if}
</div>

<div class="measurement">
<h2>{$_("measurement_unit")}</h2>
<h2>{$_('measurement_unit')}</h2>
<p class="underline">
{$_("current_measurement_unit")}: {capitalizeFirstLetter(data.measurement_unit)}
{$_('current_measurement_unit')}: {capitalizeFirstLetter(data.measurement_unit)}
</p>
<form action="?/measurement" method="POST" class="measurement-form">
<label for="measurement-unit">{$_("select_measurement_unit")}:</label>
<label for="measurement-unit">{$_('select_measurement_unit')}:</label>
<select id="measurement-unit" name="measurement-unit" bind:value={data.measurement_unit}>
<option value="yards">Yards</option>
<option value="meters">Meters</option>
Expand All @@ -199,28 +211,28 @@
</div>

<div id="preferences">
<h2>{$_("appearance")}</h2>
<h2>{$_('appearance')}</h2>
<p class="underline">
{$_("current_theme")}: {capitalizeFirstLetter(data.theme)}
{$_('current_theme')}: {capitalizeFirstLetter(data.theme)}
</p>
<form action="?/theme" method="POST" class="theme-form">
<label for="theme-settings">{$_("select_your_theme")}:</label>
<label for="theme-settings">{$_('select_your_theme')}:</label>
<select id="theme-settings" name="theme-settings" bind:value={data.theme}>
<option value="dark">{$_("dark")}</option>
<option value="light">{$_("light")}</option>
<option value="system">{$_("system")}</option>
<option value="dark">{$_('dark')}</option>
<option value="light">{$_('light')}</option>
<option value="system">{$_('system')}</option>
</select>
<br />
<button aria-label="update Theme">{$_('update')}</button>
</form>

<h2>{$_("rounded_corners")}</h2>
<h2>{$_('rounded_corners')}</h2>
<p class="underline">
{$_("current_rounded_corner")}: {JSON.stringify(data.rounded_corners)}
{$_('current_rounded_corner')}: {JSON.stringify(data.rounded_corners)}
</p>
<form action="?/rounded_corners" method="POST" class="rounded-corners-form">
<div class="same-row">
<label for="rounded-corners-settings">{$_("select_prefered_rounded_corners")}:</label>
<label for="rounded-corners-settings">{$_('select_prefered_rounded_corners')}:</label>
<input
type="checkbox"
name="rounded-corners"
Expand All @@ -232,13 +244,13 @@
<button aria-label="update Rounded Corners">{$_('update')}</button>
</form>

<h2>{$_("animations")}</h2>
<h2>{$_('animations')}</h2>
<p class="underline">
{$_("current_animation_setting")}: {JSON.stringify(data.animation)}
{$_('current_animation_setting')}: {JSON.stringify(data.animation)}
</p>
<form action="?/animation" method="POST" class="animation-form">
<div class="same-row">
<label for="animation-settings">{$_("select_prefered_animation_setting")}:</label>
<label for="animation-settings">{$_('select_prefered_animation_setting')}:</label>
<input type="checkbox" name="animation" id="animation" bind:checked={data.animation} />
</div>
<br />
Expand All @@ -247,24 +259,24 @@
</div>

<div class="delete-account">
<h2 class="danger-zone">{$_("danger_zone")}</h2>
<h2 class="error">{$_("account_will_be_gone")}</h2>
<h2 class="danger-zone">{$_('danger_zone')}</h2>
<h2 class="error">{$_('account_will_be_gone')}</h2>
<form action="?/delete_account" method="POST" class="delete_account_form">
<div>
<label for="delete_account_password_input">{$_("password")}</label>
<label for="delete_account_password_input">{$_('password')}</label>
<input
type="password"
id="delete_account_password_input"
name="password_delete_account"
value=""
/>
</div>
<button aria-label="delete Account">{$_("delete_account")}</button>
<button aria-label="delete Account">{$_('delete_account')}</button>
</form>
</div>

<form action="/logout" method="POST" class="logout-form">
<button>{$_("sign_out")}</button>
<button>{$_('sign_out')}</button>
</form>
{/if}

Expand Down
1 change: 0 additions & 1 deletion src/routes/support/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const actions: Actions = {
});

console.log('Message sent: %s', info.messageId);
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
} catch (error) {
console.error('Error sending email:', error);
}
Expand Down

0 comments on commit c174e8d

Please sign in to comment.