-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #400 from reedu-reengineering-education/fix/passwo…
…rd-login Fix/password login
- Loading branch information
Showing
31 changed files
with
1,164 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Html } from '@react-email/html' | ||
import * as React from 'react' | ||
import { Tailwind } from '@react-email/tailwind' | ||
import { Head } from '@react-email/head' | ||
import { Heading } from '@react-email/heading' | ||
import { Text } from '@react-email/text' | ||
import { Font } from '@react-email/font' | ||
import { Container } from '@react-email/container' | ||
|
||
interface PasswordRequestProps { | ||
password: string | ||
} | ||
|
||
export default function PasswordRequest({ password }: PasswordRequestProps) { | ||
return ( | ||
<Tailwind | ||
config={{ | ||
theme: { | ||
extend: { | ||
colors: { | ||
brand: '#38383a', | ||
}, | ||
}, | ||
}, | ||
}} | ||
> | ||
<Head> | ||
<title>Mapstories Passwort Request</title> | ||
<Font | ||
fallbackFontFamily="Helvetica" | ||
fontFamily="sans-serif" | ||
fontStyle="normal" | ||
fontWeight={400} | ||
/> | ||
</Head> | ||
<Html> | ||
<Container className="p-4"> | ||
<Heading as="h2" className="text-brand text-lg font-bold"> | ||
Mapstories Password Request | ||
</Heading> | ||
<Text className="text-base text-gray-700"> | ||
Du hast ein neues Passwort für deinen Zugang bei Mapstories | ||
angefordert. Unten findest du dein neues Passwort: | ||
</Text> | ||
<Text className="mt-4 text-lg font-medium text-gray-900"> | ||
Passwort: <span className="text-brand font-bold">{password}</span> | ||
</Text> | ||
<Text className="mt-4 text-sm text-gray-600"> | ||
Bitte ändere dein Passwort nach dem Einloggen, um deine Sicherheit | ||
zu gewährleisten. | ||
</Text> | ||
</Container> | ||
</Html> | ||
</Tailwind> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { db } from '@/src/lib/db' | ||
import nodemailer from 'nodemailer' | ||
import crypto from 'crypto' | ||
import { withMethods } from '@/src/lib/apiMiddlewares/withMethods' | ||
import bcrypt from 'bcrypt' | ||
import { render } from '@react-email/render' | ||
import PasswordRequest from '@/emails/passwordRequest' | ||
|
||
async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
const { email } = req.body | ||
|
||
if (!email) { | ||
return res.status(400).json({ message: 'Email is required' }) | ||
} | ||
|
||
try { | ||
// Generate a new random password | ||
const newPassword = crypto.randomBytes(8).toString('hex') | ||
const hashedPassword = await bcrypt.hash(newPassword, 10) | ||
|
||
// Update the user's password in the database | ||
const updatedUser = await db.user.findUnique({ | ||
where: { email }, | ||
}) | ||
|
||
if (!updatedUser) { | ||
return res.status(404).json({ message: 'User not found' }) | ||
} | ||
|
||
if (updatedUser.password && updatedUser.password.length > 0) { | ||
return res.status(400).json({ | ||
message: 'User already has a password set', | ||
}) | ||
} | ||
await db.user.update({ | ||
where: { email }, | ||
data: { password: hashedPassword }, | ||
}) | ||
|
||
// Send an email to the user with the new password | ||
const transporter = nodemailer.createTransport({ | ||
host: process.env.SMTP_HOST, | ||
port: 587, | ||
secure: false, | ||
auth: { | ||
user: process.env.SMTP_USER, | ||
pass: process.env.SMTP_PASS, | ||
}, | ||
}) | ||
|
||
const emailHmtl = render(PasswordRequest({ password: newPassword })) | ||
|
||
const mailOptions = { | ||
from: process.env.SMTP_USER, | ||
to: email, | ||
subject: 'Your new password', | ||
html: emailHmtl, | ||
} | ||
await transporter.sendMail(mailOptions) | ||
|
||
res | ||
.status(200) | ||
.json({ message: 'New password has been set and emailed to you' }) | ||
} catch (error) { | ||
console.error(error) | ||
res.status(500).json({ message: 'Internal server error' }) | ||
} | ||
} | ||
|
||
export default withMethods(['POST'], handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterEnum | ||
ALTER TYPE "MediaType" ADD VALUE 'LAMAPOLL'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
-- AlterTable | ||
ALTER TABLE "users" ADD COLUMN "password" TEXT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Link from 'next/link' | ||
|
||
import { Button } from '@/src/components/Elements/Button' | ||
import { ChevronLeftIcon } from '@heroicons/react/24/outline' | ||
import { useTranslation } from '@/src/app/i18n' | ||
import { LogoWithClaimAndBackground } from '@/src/components/Layout/MapstoriesLogo' | ||
import UserAuthPassword from '@/src/components/Auth/UserAuthPassword' | ||
|
||
export default async function LoginPage({ | ||
params: { lng }, | ||
}: { | ||
params: { lng: string } | ||
}) { | ||
const { t } = await useTranslation(lng, 'login') | ||
|
||
return ( | ||
<div className="container flex h-screen w-screen flex-col items-center justify-center"> | ||
<Link className="absolute left-4 top-4" href="/"> | ||
<Button | ||
startIcon={<ChevronLeftIcon className="w-4" />} | ||
variant={'inverse'} | ||
> | ||
{t('back')} | ||
</Button> | ||
</Link> | ||
<div className="mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px]"> | ||
<div className="flex flex-col space-y-2 text-center"> | ||
<LogoWithClaimAndBackground className="mx-auto h-32 w-60" /> | ||
<h1 className="text-2xl font-bold">{t('welcome_back')}</h1> | ||
<p className="text-sm text-slate-600"> | ||
{t('enter_email_and_password_for_signin')} | ||
</p> | ||
<p className="textz-sm text-slate-800"> | ||
{t('enable_password_login')} | ||
<a className="text-blue-500" href="/passwordRequest"> | ||
{t('link')} | ||
</a> | ||
{t('enable_password_login_end')} | ||
</p> | ||
</div> | ||
<UserAuthPassword /> | ||
{/* <h1 className="text-center">Noch keinen Account?</h1> | ||
<p className="px-8 text-center text-sm text-slate-600"> | ||
{t('disclaimerRegister')}{' '} | ||
<Link className="hover:text-brand underline" href="/terms"> | ||
{t('TOS')} | ||
</Link>{' '} | ||
{t('and')}{' '} | ||
<Link className="hover:text-brand underline" href="/privacy"> | ||
{t('PP')} | ||
</Link> | ||
</p> */} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useTranslation } from '@/src/app/i18n' | ||
import UserAuthRequestPassword from '@/src/components/Auth/UserAuthRequestPassword' | ||
import { LogoWithClaimAndBackground } from '@/src/components/Layout/MapstoriesLogo' | ||
import React from 'react' | ||
|
||
export default async function RequestPasswordPage({ | ||
params: { lng }, | ||
}: { | ||
params: { lng: string } | ||
}) { | ||
const { t } = await useTranslation(lng, 'login') | ||
|
||
return ( | ||
<div className="container flex h-screen w-screen flex-col items-center justify-center"> | ||
<div className="mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px]"> | ||
<div className="flex flex-col space-y-2 text-center"> | ||
<LogoWithClaimAndBackground className="mx-auto h-32 w-60" /> | ||
<h1 className="text-2xl font-bold">{t('welcome_back')}</h1> | ||
<p className="text-sm text-slate-600"> | ||
{t('enter_email_for_password_request')} | ||
</p> | ||
</div> | ||
<UserAuthRequestPassword /> | ||
{/* <h1 className="text-center">Noch keinen Account?</h1> | ||
<p className="px-8 text-center text-sm text-slate-600"> | ||
{t('disclaimerRegister')}{' '} | ||
<Link className="hover:text-brand underline" href="/terms"> | ||
{t('TOS')} | ||
</Link>{' '} | ||
{t('and')}{' '} | ||
<Link className="hover:text-brand underline" href="/privacy"> | ||
{t('PP')} | ||
</Link> | ||
</p> */} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.