Skip to content

Commit

Permalink
#65 - toggle password visibility (#164)
Browse files Browse the repository at this point in the history
* Add password visibility toggle to login and registration forms

* Update password visibility button position

* Remove password confirmation field from registration form

* Removed backend needs for password_confirmation, bugfix
  • Loading branch information
Lee0z authored Nov 8, 2023
1 parent b0e89b9 commit 5c93e11
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
1 change: 0 additions & 1 deletion app/Exceptions/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class ExceptionHandler extends Handler
protected $dontFlash = [
"current_password",
"password",
"password_confirmation",
];

public function register(): void
Expand Down
1 change: 0 additions & 1 deletion app/Http/Middleware/TrimStrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ class TrimStrings extends Middleware
protected $except = [
"current_password",
"password",
"password_confirmation",
];
}
2 changes: 1 addition & 1 deletion app/Http/Requests/RegisterRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function rules(): array
return [
"name" => ["required", "string", "max:60"],
"email" => ["required", "string", "email", "max:255", "unique:users"],
"password" => ["required", Password::defaults(), "confirmed"],
"password" => ["required", Password::defaults()],
];
}
}
35 changes: 20 additions & 15 deletions resources/js/Shared/Layout/Nav.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup>
import { computed, ref } from 'vue'
import { Dialog, DialogPanel } from '@headlessui/vue'
import { Bars3Icon, XMarkIcon, UserCircleIcon, ArrowRightOnRectangleIcon, ComputerDesktopIcon, MapPinIcon, FlagIcon } from '@heroicons/vue/24/outline'
import { Bars3Icon, XMarkIcon, UserCircleIcon, ArrowRightOnRectangleIcon, ComputerDesktopIcon, MapPinIcon, FlagIcon, EyeIcon, EyeSlashIcon } from '@heroicons/vue/24/outline'
import { router, usePage } from '@inertiajs/vue3'
import { onClickOutside } from '@vueuse/core'
import { useForm } from '@inertiajs/vue3'
Expand All @@ -21,7 +21,6 @@ const registerForm = useForm({
name: '',
email: '',
password: '',
password_confirmation: '',
})
function register() {
Expand Down Expand Up @@ -86,6 +85,12 @@ function toggleAuthDialog() {
isMobileMenuOpened.value = false
}
const isPasswordVisible = ref(false)
function togglePasswordVisibility() {
isPasswordVisible.value = !isPasswordVisible.value
}
const isLoginFormSelected = ref(true)
function toggleAuthOption() {
Expand Down Expand Up @@ -167,13 +172,16 @@ defineExpose({
required
>
</div>
<div>
<label class="mb-1 block text-sm font-semibold text-gray-800">{{ __('Password') }}</label>
<input v-model="loginForm.password" type="password" class="w-full rounded-lg border-blumilk-200 py-3 md:p-2"
<div class="relative">
<label class="mb-1 block w-full text-sm font-semibold text-gray-800">{{ __('Password') }}</label>
<input v-model="loginForm.password" :type="isPasswordVisible ? 'text' : 'password'" class="w-full rounded-lg border-blumilk-200 py-3 md:p-2"
required
>
<ErrorMessage :message="loginForm.errors.loginError" />
<button type="button" class="absolute bottom-3 right-2 md:bottom-2" @click="togglePasswordVisibility">
<component :is="!isPasswordVisible ? EyeIcon : EyeSlashIcon" class="h-6 w-6 text-blumilk-400" />
</button>
</div>
<ErrorMessage :message="loginForm.errors.loginError" />
<div class="flex w-full md:w-fit">
<button type="submit"
class="w-full rounded-lg bg-blumilk-500 p-4 font-semibold text-white hover:bg-blumilk-600 md:py-2"
Expand Down Expand Up @@ -204,19 +212,16 @@ defineExpose({
>
<ErrorMessage :message="registerForm.errors.email" />
</div>
<div>
<div class="relative">
<label class="mb-1 block text-sm font-semibold text-gray-800">{{ __('Password') }}</label>
<input v-model="registerForm.password" type="password"
class="w-full rounded-lg border-blumilk-200 py-3 md:p-2" required
>
</div>
<div>
<label class="mb-1 block text-sm font-semibold text-gray-800">{{ __('Confirm password') }}</label>
<input v-model="registerForm.password_confirmation" type="password"
<input v-model="registerForm.password" :type="isPasswordVisible ? 'text' : 'password'"
class="w-full rounded-lg border-blumilk-200 py-3 md:p-2" required
>
<ErrorMessage :message="registerForm.errors.password" />
<button type="button" class="absolute bottom-3 right-2 md:bottom-2" @click="togglePasswordVisibility">
<component :is="!isPasswordVisible ? EyeIcon : EyeSlashIcon" class="h-6 w-6 text-blumilk-400" />
</button>
</div>
<ErrorMessage :message="registerForm.errors.password" />
<div class="flex w-full md:w-fit">
<button type="submit"
class="w-full rounded-lg bg-blumilk-500 p-4 font-semibold text-white hover:bg-blumilk-600 md:py-2"
Expand Down
2 changes: 0 additions & 2 deletions tests/Feature/SignupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public function testUserCanSignupWithProperCredentials(): void
"name" => "Test",
"email" => "[email protected]",
"password" => "123456789",
"password_confirmation" => "123456789",
];

$this->post(uri: "/register", data: $user);
Expand All @@ -29,7 +28,6 @@ public function testUserCannotBeCreatedWithInvalidName(): void
"name" => Str::random(256),
"email" => "[email protected]",
"password" => "123456789",
"password_confirmation" => "123456789",
]);

$response->assertSessionHasErrors(["name"]);
Expand Down

0 comments on commit 5c93e11

Please sign in to comment.