Skip to content

Commit

Permalink
DONE Adding user admin button on register : When a user register, he …
Browse files Browse the repository at this point in the history
…can create an admin account
  • Loading branch information
ClawdeenFleury committed Dec 14, 2023
1 parent 55accb9 commit 6595117
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
14 changes: 11 additions & 3 deletions calm-webserver/app/Http/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,20 @@ public function register(Request $request){
"passwordConfirmation" => "required"
]);

User::create([
$userData = [
"name" => $request->name,
"email" => $request->email,
"password" => Hash::make($request->password),
"is_activated" => false
]);
"is_activated" => false,
"is_admin" => false,
];

// Check if admin field is check
if ($request->has('isAdmin')) {
$userData['is_admin'] = true;
}

User::create($userData);

$id = User::where('email', $request->email)->first()->id;
Auth::loginUsingId($id);
Expand Down
3 changes: 2 additions & 1 deletion calm-webserver/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class User extends Authenticatable
'name',
'email',
'password',
'is_activated'
'is_activated',
'is_admin'
];

/**
Expand Down
15 changes: 13 additions & 2 deletions calm-webserver/resources/views/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</svg>
</div>

<input id="name" name="name" type="text" autocomplete="name" required class="block w-full pl-10 input input-sobre">
<input id="name" value="{{old('name')}}" name="name" type="text" autocomplete="name" required class="block w-full pl-10 input input-sobre">
</div>
</div>

Expand All @@ -34,7 +34,7 @@
</svg>
</div>

<input id="email" name="email" type="email" autocomplete="email" required class="block w-full pl-10 input input-sobre">
<input id="email" value="{{old('email')}}" name="email" type="email" autocomplete="email" required class="block w-full pl-10 input input-sobre">
</div>
</div>

Expand Down Expand Up @@ -64,6 +64,17 @@
</div>
</div>

<div>
<div class="text-center">
<label class="relative inline-flex items-center mr-5 cursor-pointer">
<input type="checkbox" name="isAdmin" value="isAdmin" id="isAdmin" class="sr-only peer choose-wash-dry" {{ old('isAdmin') ? 'checked' : '' }}>
<div
class="toggle-switch peer peer-focus:ring-4 peer-focus:ring-vividTangerine peer-checked:after:translate-x-full peer-checked:after:border-white peer-checked:bg-vividTangerine"></div>
<span class="ml-3 text-sm font-medium text-gray-900 dark:text-gray-300">Compte administrateur</span>
</label>
</div>
</div>

<div>
<button type="submit" class="btn btn-sobre flex justify-center w-full ">Inscription</button>
</div>
Expand Down

0 comments on commit 6595117

Please sign in to comment.