Skip to content

Commit 249c39b

Browse files
profile and forgot-reset-password
1 parent 31e2e7a commit 249c39b

File tree

17 files changed

+294
-47
lines changed

17 files changed

+294
-47
lines changed

app/Http/Livewire/ForgotPassword.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,35 @@
22

33
namespace App\Http\Livewire;
44

5+
use Illuminate\Http\Request;
6+
use Illuminate\Support\Facades\Password;
57
use Livewire\Component;
8+
use App\Models\User;
9+
use Illuminate\Notifications\Notifiable;
10+
use App\Notifications\ResetPassword;
611

712
class ForgotPassword extends Component
813
{
14+
use Notifiable;
15+
16+
public $mailSentAlert = false;
17+
public $email='';
18+
public $rules=[
19+
'email' => 'required|email|exists:users'
20+
];
21+
protected $messages = [
22+
'email.exists' => 'The Email Address must be in our database.',
23+
];
24+
public function routeNotificationForMail() {
25+
return $this->email;
26+
}
27+
public function recoverPassword() {
28+
$this->validate();
29+
$user=User::where('email', $this->email)->first();
30+
$this->notify(new ResetPassword($user->remember_token));
31+
$this->mailSentAlert = true;
32+
}
33+
934
public function render()
1035
{
1136
return view('livewire.forgot-password')

app/Http/Livewire/Login.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public function login()
2424

2525
}
2626

27-
2827
public function render()
2928
{
3029
return view('livewire.auth.login')

app/Http/Livewire/Profile.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,39 @@
22

33
namespace App\Http\Livewire;
44

5+
use App\Models\User;
56
use Livewire\Component;
67

78
class Profile extends Component
89
{
10+
public User $user;
11+
public $showSavedAlert = false;
12+
13+
protected $rules = [
14+
'user.first_name' => 'max:15',
15+
'user.last_name' => 'max:20',
16+
'user.birthday' => 'date_format:Y-m-d',
17+
'user.email' => 'email',
18+
'user.phone' => '',
19+
'user.gender' => '',
20+
'user.address' => '',
21+
'user.number' => '',
22+
'user.city' => '',
23+
'user.zip' => '',
24+
];
25+
26+
public function mount() { $this->user = auth()->user(); }
27+
28+
public function save()
29+
{
30+
$this->validate();
31+
32+
$this->user->save();
33+
34+
$this->showSavedAlert = true;
35+
}
36+
37+
938
public function render()
1039
{
1140
return view('livewire.profile')

app/Http/Livewire/Register.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Livewire\Component;
66
use App\Models\User;
77
use Illuminate\Support\Facades\Hash;
8+
use Illuminate\Support\Str;
89

910
class Register extends Component
1011
{
@@ -22,13 +23,18 @@ public function register()
2223
{
2324
$this->validate([
2425
'email' => 'required',
25-
'password' => 'required|same:passwordConfirmation',
26+
'password' => 'required|same:passwordConfirmation|min:6',
2627
]);
2728

2829
$user = User::create([
2930
'email' =>$this->email,
3031
'password' => Hash::make($this->password),
32+
'remember_token' => Str::random(10),
3133
]);
34+
35+
auth()->login($user);
36+
37+
return redirect('/profile');
3238
}
3339

3440
public function render()

app/Http/Livewire/ResetPassword.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,23 @@
55
use Livewire\Component;
66

77
class ResetPassword extends Component
8-
{
8+
{
9+
public $email = '';
10+
public $password = '';
11+
public $passwordConfirmation = '';
12+
13+
public $rules=[
14+
'email' => 'required|email|exists:users',
15+
'password' => 'required|same:passwordConfirmation|min:6',
16+
];
17+
protected $messages = [
18+
'email.exists' => 'The Email Address must be in our database.',
19+
];
20+
21+
public function resetPassword() {
22+
/////to do : add functionality here
23+
}
24+
925
public function render()
1026
{
1127
return view('livewire.reset-password')

app/Notifications/ResetPassword.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace App\Notifications;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use Illuminate\Notifications\Messages\MailMessage;
8+
use Illuminate\Notifications\Notification;
9+
use Illuminate\Http\Request;
10+
11+
class ResetPassword extends Notification
12+
{
13+
use Queueable;
14+
15+
public $token;
16+
17+
/**
18+
* Create a new notification instance.
19+
*
20+
* @return void
21+
*/
22+
public function __construct($token)
23+
{
24+
$this->token = $token;
25+
}
26+
27+
/**
28+
* Get the notification's delivery channels.
29+
*
30+
* @param mixed $notifiable
31+
* @return array
32+
*/
33+
public function via($notifiable)
34+
{
35+
return ['mail'];
36+
}
37+
38+
/**
39+
* Get the mail representation of the notification.
40+
*
41+
* @param mixed $notifiable
42+
* @return \Illuminate\Notifications\Messages\MailMessage
43+
*/
44+
public function toMail($notifiable)
45+
{
46+
return (new MailMessage)
47+
->subject('Reset your password')
48+
->line('Hey, did you forget your password? Click the button to reset it.')
49+
->action('Reset Password', url('reset-password', $this->token))
50+
->line('Thank you for using our application!');
51+
}
52+
53+
/**
54+
* Get the array representation of the notification.
55+
*
56+
* @param mixed $notifiable
57+
* @return array
58+
*/
59+
public function toArray($notifiable)
60+
{
61+
return [
62+
//
63+
];
64+
}
65+
}

database/factories/UserFactory.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ class UserFactory extends Factory
2424
public function definition()
2525
{
2626
return [
27-
'First Name' => $this->faker->firstName(),
28-
'Last Name' => $this->faker->lastName(),
27+
'First_Name' => $this->faker->firstName(),
28+
'Last_Name' => $this->faker->lastName(),
2929
'Gender' => Arr::random(['male', 'female', 'other']),
3030
'email' => $this->faker->unique()->safeEmail(),
3131
'email_verified_at' => now(),
3232
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
3333
'Phone' => $this->faker->phoneNumber,
34+
'Birthday' => $this->faker->dateTimeThisCentury,
35+
'Address' => $this->faker->address,
36+
'City' => $this->faker->city,
37+
'ZIP' => $this->faker->randomNumber(6),
38+
'Number' => $this->faker->buildingNumber,
3439
'remember_token' => Str::random(10),
3540
];
3641
}

database/migrations/2014_10_12_000000_create_users_table.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ public function up()
1515
{
1616
Schema::create('users', function (Blueprint $table) {
1717
$table->increments('id')->unique();
18-
$table->string('First Name')->nullable();
19-
$table->string('Last Name')->nullable();
18+
$table->string('First_Name')->nullable();
19+
$table->string('Last_Name')->nullable();
2020
$table->string('Gender')->nullable();
2121
$table->string('Email')->unique();
2222
$table->string('password');
23+
$table->date('Birthday')->nullable();
24+
$table->string('Address')->nullable();
25+
$table->string('Number')->nullable();
26+
$table->string('City')->nullable();
27+
$table->string('ZIP')->nullable();
2328
$table->string('Phone')->nullable();
2429
$table->timestamp('email_verified_at')->nullable();
2530
$table->rememberToken();

public/assets/js/volt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ d.addEventListener("DOMContentLoaded", function(event) {
140140

141141

142142
// Datepicker
143-
var datepickers = [].slice.call(d.querySelectorAll('[data-datepicker]'))
143+
var datepickers = [].slice.call(document.querySelectorAll('[data-datepicker]'))
144144
var datepickersList = datepickers.map(function (el) {
145145
return new Datepicker(el, {
146146
buttonClass: 'btn'

resources/views/layouts/base.blade.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
<meta name="msapplication-TileColor" content="#ffffff">
3535
<meta name="theme-color" content="#ffffff">
3636

37+
<!-- Datepicker -->
38+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.4/dist/css/datepicker.min.css">
39+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.4/dist/css/datepicker-bs4.min.css">
40+
3741
<!-- Fontawesome -->
3842
<link type="text/css" href="/vendor/fontawesome-free/css/all.min.css" rel="stylesheet">
3943

@@ -50,6 +54,11 @@
5054

5155
@livewireScripts
5256

57+
<!-- Alpine -->
58+
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js" defer></script>
59+
<!-- Datepicker -->
60+
<script src="https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.4/dist/js/datepicker.min.js"></script>
61+
5362
<script src="/assets/js/volt.js"></script>
5463
<script src="/assets/js/datepicker.min.js"></script>
5564
<script async defer src="https://buttons.github.io/buttons.js"></script>

0 commit comments

Comments
 (0)