Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
luisnmartins committed Apr 25, 2018
2 parents 8cda35f + 67e6ba3 commit c62cab9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 49 deletions.
6 changes: 3 additions & 3 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public function __construct()
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'username' => 'required|string|max:30|unique:users',
'name' => "required|regex:/^[\p{L}\s'.-]+$/u|max:255",
'username' => 'required|regex:/^[a-zA-Z0-9]{6,20}$/u|unique:users',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'password' => 'required|regex:/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/u|confirmed',
]);
}

Expand Down
18 changes: 18 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Auth\Middleware\Authenticate;
use Illuminate\Support\Facades\Validator;

use App\User;
use App\Country;
Expand Down Expand Up @@ -38,8 +39,25 @@ public function showProfile($id) {

}

public function validator(array $data) {

return Validator::make($data, [
'name' => "sometimes|regex:/^[\p{L}\s'.-]+$/u|max:30",
'username' => 'sometimes|regex:/^[a-zA-Z0-9]{6,20}$/u|unique:users',
'email' => 'sometimes|string|email|max:255|unique:users',
'old_password' => 'sometimes|regex:/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/u',
'new_password' => 'sometimes|regex:/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/u'
]);

}

public function editProfile(Request $request) {
Auth::check();

$validator = $this->validator($request->all());
if($validator->fails()) {
return response()->json("Bad request", 400);
}
if($request->old_password != null) {
if(Hash::check($request->old_password, Auth::user()->password)) {
$password = Hash::make($request->new_password);
Expand Down
23 changes: 16 additions & 7 deletions public/js/editProfileRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@ $(document).ready(function () {

var formFills = $("#profile_form .form-group input");
var type = "PUT";
var my_data = {
'name': formFills.get(0).value,
'username': formFills.get(1).value,
'email': formFills.get(2).value,
'old_password': formFills.get(3).value,
'new_password': formFills.get(4).value,
'confirm_password': formFills.get(5).value
var my_data = {};
if(formFills.get(0).value !== ''){
my_data.name = formFills.get(0).value;
}
if(formFills.get(1).value !== ''){
my_data.username = formFills.get(1).value;
}
if(formFills.get(2).value !== ''){
my_data.email = formFills.get(2).value;
}

if(formFills.get(3).value !== ''){
my_data.old_password = formFills.get(3).value;
}
if(formFills.get(4).value !== ''){
my_data.new_password = formFills.get(4).value;
}

console.log(my_data.old_password + '\n' + my_data.new_password + '\n' + my_data.confirm_password + '\n');
Expand Down
47 changes: 8 additions & 39 deletions resources/views/auth/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
<form method="POST" action="{{ route('register') }}">
{{ csrf_field() }}
<div class="form-group">
<input type="text" class="form-control" name="name" id="name" value="{{ old('name') }}" placeholder="Name" required>
<input type="text" class="form-control" name="name" oninvalid="this.setCustomValidity('Please enter a valid name')"
oninput="this.setCustomValidity('')" pattern="^[\p{L}\s'.-]+$" id="name" value="{{ old('name') }}" placeholder="Name" required>
@if ($errors->has('name'))
<span class="error">
{{ $errors->first('name') }}
</span>
@endif
</div>
<div class="form-group">
<input type="text" class="form-control" id="username" name="username" value="{{ old('username') }}" placeholder="Username" required>
<input type="text" class="form-control" id="username" oninvalid="this.setCustomValidity('Username must have at least 6 characters')"
oninput="this.setCustomValidity('')" pattern="^[a-zA-Z0-9]{6,20}$" name="username" value="{{ old('username') }}" placeholder="Username" required>
@if ($errors->has('username'))
<span class="error">
{{ $errors->first('username') }}
Expand All @@ -44,7 +46,8 @@
@endif
</div>
<div class="form-group">
<input type="password" class="form-control" name="password" aria-describedby="passwordAdvice" placeholder="Password" required>
<input type="password" class="form-control" oninvalid="this.setCustomValidity('Password must have one uppercase letter, one number and at least 8 characters')"
oninput="this.setCustomValidity('')" pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$" name="password" aria-describedby="passwordAdvice" placeholder="Password" required>
<!--<small id="passwordAdvice" class="form-text text-muted">Your password must be atleast 8 char long, blablabla</small>-->
@if ($errors->has('password'))
<span class="error">
Expand All @@ -53,7 +56,8 @@
@endif
</div>
<div class="form-group">
<input type="password" class="form-control" name="password_confirmation" placeholder="Repeat password" required>
<input type="password" class="form-control" oninvalid="this.setCustomValidity('Password must have one uppercase letter, one number and at least 8 characters')"
oninput="this.setCustomValidity('')" pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$" name="password_confirmation" placeholder="Repeat password" required>
</div>
<input type="submit" class="black-button" value="Create Account"></input>
</form>
Expand All @@ -66,39 +70,4 @@
</div>
</div>
</main>
{{--<form method="POST" action="{{ route('register') }}">
{{ csrf_field() }}
<label for="name">Teste</label>
<input id="name" type="text" name="name" value="{{ old('name') }}" required autofocus>
@if ($errors->has('name'))
<span class="error">
{{ $errors->first('name') }}
</span>
@endif
<label for="email">E-Mail Address</label>
<input id="email" type="email" name="email" value="{{ old('email') }}" required>
@if ($errors->has('email'))
<span class="error">
{{ $errors->first('email') }}
</span>
@endif
<label for="password">Password</label>
<input id="password" type="password" name="password" required>
@if ($errors->has('password'))
<span class="error">
{{ $errors->first('password') }}
</span>
@endif
<label for="password-confirm">Confirm Password</label>
<input id="password-confirm" type="password" name="password_confirmation" required>
<button type="submit">
Register
</button>
<a class="button button-outline" href="{{ route('login') }}">Login</a>
</form>--}}
@endsection

0 comments on commit c62cab9

Please sign in to comment.