]> BookStack Code Mirror - bookstack/commitdiff
Add min length validation on name on register form & add sign up link 1395/head
authorChristopher Wilkinson <redacted>
Tue, 16 Apr 2019 11:18:51 +0000 (12:18 +0100)
committerChristopher Wilkinson <redacted>
Tue, 16 Apr 2019 11:18:51 +0000 (12:18 +0100)
app/Http/Controllers/Auth/RegisterController.php
resources/views/auth/forms/login/standard.blade.php
resources/views/auth/login.blade.php
resources/views/common/header.blade.php
tests/Auth/AuthTest.php

index da4f42bb1066a49481b06c1215b89a84642e8213..79d69665298130643405f24a8bfff18d30d20c57 100644 (file)
@@ -70,7 +70,7 @@ class RegisterController extends Controller
     protected function validator(array $data)
     {
         return Validator::make($data, [
-            'name' => 'required|max:255',
+            'name' => 'required|min:2|max:255',
             'email' => 'required|email|max:255|unique:users',
             'password' => 'required|min:6',
         ]);
index a12fbd7531ce39d4b16f202651ddb7139e4f2a3c..0e580943e6d06821cb6f7cd7102c13aec0fc3a17 100644 (file)
@@ -6,5 +6,10 @@
 <div class="form-group">
     <label for="password">{{ trans('auth.password') }}</label>
     @include('form.password', ['name' => 'password', 'tabindex' => 1])
-    <span class="block small mt-s"><a href="{{ baseUrl('/password/email') }}">{{ trans('auth.forgot_password') }}</a></span>
-</div>
\ No newline at end of file
+    <span class="block small mt-s">
+        <a href="{{ baseUrl('/password/email') }}">{{ trans('auth.forgot_password') }}</a>
+        @if(setting('registration-enabled', false))
+            • <a href="{{ baseUrl('/register') }}">{{ trans('auth.sign_up') }}</a>
+        @endif
+    </span>
+</div>
index eb7ca2da8751a852131e076133095f3a14a120c8..6e3f12a854af4fe9f8564635a9bc5842c18ad6d5 100644 (file)
@@ -9,7 +9,7 @@
         <div class="card content-wrap">
             <h1 class="list-heading">{{ title_case(trans('auth.log_in')) }}</h1>
 
-            <form action="{{ baseUrl("/login") }}" method="POST" id="login-form" class="mt-l">
+            <form action="{{ baseUrl('/login') }}" method="POST" id="login-form" class="mt-l">
                 {!! csrf_field() !!}
 
                 <div class="stretch-inputs">
index c9c301572a1754cb7794130535b740bfffd5089d..7fab6cfda1c91c0387f8e0c5a919c2e4f2151575 100644 (file)
@@ -41,7 +41,7 @@
 
                     @if(!signedInUser())
                         @if(setting('registration-enabled', false))
-                            <a href="{{ baseUrl("/register") }}">@icon('new-user') {{ trans('auth.sign_up') }}</a>
+                            <a href="{{ baseUrl('/register') }}">@icon('new-user') {{ trans('auth.sign_up') }}</a>
                         @endif
                         <a href="{{ baseUrl('/login') }}">@icon('login') {{ trans('auth.log_in') }}</a>
                     @endif
index 0aa0e2a23625ea9ab614623065edb116679af9e9..c39ef68e56399740b3ace0965e2d3d29b67d61dc 100644 (file)
@@ -69,6 +69,31 @@ class AuthTest extends BrowserKitTest
             ->seePageIs('/register');
     }
 
+    public function test_registration_validation()
+    {
+        $this->setSettings(['registration-enabled' => 'true']);
+
+        $this->visit('/register')
+            ->type('1', '#name')
+            ->type('1', '#email')
+            ->type('1', '#password')
+            ->press('Create Account')
+            ->see('The name must be at least 2 characters.')
+            ->see('The email must be a valid email address.')
+            ->see('The password must be at least 6 characters.')
+            ->seePageIs('/register');
+    }
+
+    public function test_sign_up_link_on_login()
+    {
+        $this->visit('/login')
+            ->dontSee('Sign up');
+
+        $this->setSettings(['registration-enabled' => 'true']);
+
+        $this->visit('/login')
+            ->see('Sign up');
+    }
 
     public function test_confirmed_registration()
     {