diff --git a/pkg/userstore/migrations/schema.sql b/pkg/userstore/migrations/schema.sql index 23e064b..a4b5a31 100644 --- a/pkg/userstore/migrations/schema.sql +++ b/pkg/userstore/migrations/schema.sql @@ -1,9 +1,26 @@ -- --- LibSQL SQL Schema dump automatic generated by geni +-- Sqlite SQL Schema dump automatic generated by geni -- -CREATE TABLE schema_migrations (id VARCHAR(255) NOT NULL PRIMARY KEY); -CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP, username TEXT NOT NULL UNIQUE, password TEXT NOT NULL); +CREATE TABLE schema_migrations (id VARCHAR(255) PRIMARY KEY); +CREATE TABLE users ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME DEFAULT CURRENT_TIMESTAMP, + username TEXT NOT NULL UNIQUE, + password TEXT NOT NULL +); CREATE TABLE sqlite_sequence(name,seq); -CREATE TABLE mail (id INTEGER PRIMARY KEY AUTOINCREMENT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP, user_id INTEGER NOT NULL, mail TEXT NOT NULL UNIQUE, validation_code TEXT NOT NULL UNIQUE, is_validated BOOLEAN NOT NULL DEFAULT 0, is_primary BOOLEAN NOT NULL DEFAULT 0, FOREIGN KEY (user_id) REFERENCES users (id)); \ No newline at end of file +CREATE TABLE mail ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME DEFAULT CURRENT_TIMESTAMP, + user_id INTEGER NOT NULL, + mail TEXT NOT NULL UNIQUE, + validation_code TEXT NOT NULL UNIQUE, + is_validated BOOLEAN NOT NULL DEFAULT 0, + is_primary BOOLEAN NOT NULL DEFAULT 0, + + FOREIGN KEY(user_id) REFERENCES users(id) +); \ No newline at end of file diff --git a/pkg/web/web.go b/pkg/web/web.go index c49529b..45352e3 100644 --- a/pkg/web/web.go +++ b/pkg/web/web.go @@ -45,6 +45,7 @@ func (w Web) PostRegisterPage(c *gin.Context) { if c.PostForm("password") != c.PostForm("confirm_password") { c.HTML(http.StatusOK, "register.html", gin.H{"msg": "Passworts dont match"}) + return } err := w.ma.RegisterUser(c.PostForm("username"), c.PostForm("email"), c.PostForm("password")) diff --git a/playwright/screenshot.png b/playwright/screenshot.png index 6ab948e..c83dbfe 100644 Binary files a/playwright/screenshot.png and b/playwright/screenshot.png differ diff --git a/playwright/tests/example.spec.js b/playwright/tests/example.spec.js index a2d6183..c1e0b45 100644 --- a/playwright/tests/example.spec.js +++ b/playwright/tests/example.spec.js @@ -12,6 +12,55 @@ test('check ping route', async ({ page }) => { test('see register page', async ({page}) => { await page.goto('/web/register'); - await expect(page.getByRole('heading', { name: 'Registrieren'})).toBeVisible(); - await expect(page.getByRole('button', { name: 'Registrieren' })).toBeVisible(); + await expect(page.getByRole('heading', { name: 'Register'})).toBeVisible(); + await expect(page.getByRole('button', { name: 'Register' })).toBeVisible(); +}) + +test('invalide username at register page', async ({page}) => { + await page.goto('/web/register'); + await page.getByLabel('Username').fill('abc'); + await page.getByLabel('E-mail Address').fill('error@error.error'); + await page.getByLabel('Password', {name: 'password', exact: true}).fill('7Jw^zNhk!NU3a8qfVp%a*VV!&Won1gD9zVHr&pgNairR5U6^h^$D%TxyJ2qHp%%n3T7rKw'); + await page.getByLabel('Repeat Password').fill('7Jw^zNhk!NU3a8qfVp%a*VV!&Won1gD9zVHr&pgNairR5U6^h^$D%TxyJ2qHp%%n3T7rKw'); + await page.getByRole('button', { name: 'Register' }).click(); + + await expect(page.getByText('username has invalide chars: username has invalide chars ')).toBeVisible(); + + await page.screenshot({ path: 'screenshot.png' }); +}) + +test('invalide mail at register page', async ({page, browserName}) => { + await page.goto('/web/register'); + await page.getByLabel('Username').fill('kekskursefail'); + await page.getByLabel('E-mail Address').fill('error@error.error'); + await page.getByLabel('Password', {name: 'password', exact: true}).fill('7Jw^zNhk!NU3a8qfVp%a*VV!&Won1gD9zVHr&pgNairR5U6^h^$D%TxyJ2qHp%%n3T7rKw'); + await page.getByLabel('Repeat Password').fill('7Jw^zNhk!NU3a8qfVp%a*VV!&Won1gD9zVHr&pgNairR5U6^h^$D%TxyJ2qHp%%n3T7rKw'); + await page.getByRole('button', { name: 'Register' }).click(); + + await page.screenshot({ path: 'screenshot.png' }); + await expect(page.getByText('cant send mail: cant send mail to error mail')).toBeVisible(); +}) + +test('different passwords', async ({page}) => { + await page.goto('/web/register'); + await page.getByLabel('Username').fill('kekskurse'); + await page.getByLabel('E-mail Address').fill('error@error.error'); + await page.getByLabel('Password', {name: 'password', exact: true}).fill('7Jw^zNhk!NU3a8qfVp%a*VV!&Won1gD9zVHr&pgNairR5U6^h^$D%TxyJ2qHp%'); + await page.getByLabel('Repeat Password').fill('7Jw^zNhk!NU3a8qfVp%a*VV!&Won1gD9zVHr&pgNairR5U6^h^$D%TxyJ2qHp%%n3T7rKw'); + await page.getByRole('button', { name: 'Register' }).click(); + + await page.screenshot({ path: 'screenshot.png' }); + await expect(page.getByText('Passworts dont match')).toBeVisible(); +}) + +test('register currect', async ({page, browserName}) => { + await page.goto('/web/register'); + await page.getByLabel('Username').fill('kekskurse'+browserName); + await page.getByLabel('E-mail Address').fill('hello'+browserName+'@example.com'); + await page.getByLabel('Password', {name: 'password', exact: true}).fill('7Jw^zNhk!NU3a8qfVp%a*VV!&Won1gD9zVHr&pgNairR5U6^h^$D%TxyJ2qHp%'); + await page.getByLabel('Repeat Password').fill('7Jw^zNhk!NU3a8qfVp%a*VV!&Won1gD9zVHr&pgNairR5U6^h^$D%TxyJ2qHp%'); + await page.getByRole('button', { name: 'Register' }).click(); + + await page.screenshot({ path: 'screenshot.png' }); + await expect(page.getByText('Your account was created, you can login now')).toBeVisible(); }) diff --git a/templates/register.html b/templates/register.html index e2b3e97..c497926 100644 --- a/templates/register.html +++ b/templates/register.html @@ -8,7 +8,7 @@ </head> <body class="bg-gray-100 flex items-center justify-center min-h-screen"> <div class="bg-white p-8 shadow-xl w-full max-w-md"> - <h2 class="text-2xl font-semibold text-gray-900 text-center mb-6">Registrieren</h2> + <h2 class="text-2xl font-semibold text-gray-900 text-center mb-6">Register</h2> {{ if .msg }} <div id="global-error" class=" bg-red-100 text-red-700 p-3 text-center mb-4 border border-red-400"> {{ .msg }} @@ -16,28 +16,28 @@ {{ end }} <form action="#" method="POST" class="space-y-4"> <div> - <label for="username" class="block text-sm font-medium text-gray-700">Benutzername</label> + <label for="username" class="block text-sm font-medium text-gray-700">Username</label> <input type="text" id="username" name="username" required class="mt-1 p-3 w-full border border-gray-300 focus:ring-2 focus:ring-blue-500 focus:outline-none"> </div> <div> - <label for="email" class="block text-sm font-medium text-gray-700">E-Mail-Adresse</label> + <label for="email" class="block text-sm font-medium text-gray-700">E-mail Address</label> <input type="email" id="email" name="email" required class="mt-1 p-3 w-full border border-gray-300 focus:ring-2 focus:ring-blue-500 focus:outline-none"> </div> <div> - <label for="password" class="block text-sm font-medium text-gray-700">Passwort</label> + <label for="password" class="block text-sm font-medium text-gray-700">Password</label> <input type="password" id="password" name="password" required class="mt-1 p-3 w-full border border-gray-300 focus:ring-2 focus:ring-blue-500 focus:outline-none"> </div> <div> - <label for="confirm_password" class="block text-sm font-medium text-gray-700">Passwort wiederholen</label> + <label for="confirm_password" class="block text-sm font-medium text-gray-700">Repeat Password</label> <input type="password" id="confirm_password" name="confirm_password" required class="mt-1 p-3 w-full border border-gray-300 focus:ring-2 focus:ring-blue-500 focus:outline-none"> </div> <button type="submit" class="w-full bg-blue-600 text-white py-3 text-lg font-medium hover:bg-blue-700 focus:ring-4 focus:ring-blue-300"> - Registrieren + Register </button> </form> @@ -60,7 +60,7 @@ </div> !--> - <p class="text-sm text-gray-600 text-center mt-4">Bereits ein Konto? <a href="#" class="text-blue-500 hover:underline">Anmelden</a></p> + <p class="text-sm text-gray-600 text-center mt-4">Already have an account?? <a href="#" class="text-blue-500 hover:underline">Login</a></p> </div> </body> </html>