Skip to content

Commit 465bfed

Browse files
author
Balaji D
committed
Added account info edit page
1 parent 641ce86 commit 465bfed

File tree

4 files changed

+195
-0
lines changed

4 files changed

+195
-0
lines changed

app/Http/Controllers/Admin/UserController.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,69 @@ public function destroy(User $user)
161161
return redirect()->route('user.index')
162162
->with('message','User deleted successfully');
163163
}
164+
165+
/**
166+
* Show the user a form to change their personal information & password.
167+
*/
168+
public function accountInfo()
169+
{
170+
$user = \Auth::user();
171+
172+
return view('admin.user.account_info', compact('user'));
173+
}
174+
175+
/**
176+
* Save the modified personal information for a user.
177+
*/
178+
public function accountInfoStore(Request $request)
179+
{
180+
$request->validateWithBag('account', [
181+
'name' => ['required', 'string', 'max:255'],
182+
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email,'.\Auth::user()->id],
183+
]);
184+
185+
$user = \Auth::user()->update($request->except(['_token']));
186+
187+
if ($user) {
188+
$message = "Account updated successfully.";
189+
} else {
190+
$message = "Error while saving. Please try again.";
191+
}
192+
193+
return redirect()->route('admin.account.info')->with('account_message', $message);
194+
}
195+
196+
/**
197+
* Save the new password for a user.
198+
*/
199+
public function changePasswordStore(Request $request)
200+
{
201+
$validator = \Validator::make(request()->all(), [
202+
'old_password' => ['required'],
203+
'new_password' => ['required', Rules\Password::defaults()],
204+
'confirm_password' => ['required', 'same:new_password', Rules\Password::defaults()],
205+
]);
206+
207+
$validator->after(function ($validator) use ($request) {
208+
if (! Hash::check($request->input('old_password'), \Auth::user()->password)) {
209+
$validator->errors()->add(
210+
'old_password', 'Old password is incorrect.'
211+
);
212+
}
213+
});
214+
215+
$validator->validateWithBag('password');
216+
217+
$user = \Auth::user()->update([
218+
'password' => Hash::make($request->input('old_password')),
219+
]);
220+
221+
if ($user) {
222+
$message = "Password updated successfully.";
223+
} else {
224+
$message = "Error while saving. Please try again.";
225+
}
226+
227+
return redirect()->route('admin.account.info')->with('password_message', $message);
228+
}
164229
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<x-app-layout>
2+
<x-slot name="header">
3+
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
4+
{{ __('My Account') }}
5+
</h2>
6+
</x-slot>
7+
8+
<div class="py-12">
9+
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
10+
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
11+
<div class="px-6">
12+
<h1 class="inline-block text-2xl sm:text-3xl font-extrabold text-slate-900 tracking-tight dark:text-slate-200 py-4 block sm:inline-block flex">{{ __('Account Info') }}</h1>
13+
@if ($errors->account->any())
14+
<ul class="mt-3 list-none list-inside text-sm text-red-400">
15+
@foreach ($errors->account->all() as $error)
16+
<li>{{ $error }}</li>
17+
@endforeach
18+
</ul>
19+
@endif
20+
@if(session()->has('account_message'))
21+
<div class="mb-8 text-green-400 font-bold">
22+
{{ session()->get('account_message') }}
23+
</div>
24+
@endif
25+
</div>
26+
<div class="w-full px-6 py-4 bg-white overflow-hidden">
27+
28+
<form method="POST" action="{{ route('admin.account.info.store') }}">
29+
@csrf
30+
31+
<div class="py-2">
32+
<label for="name" class="block font-medium text-sm text-gray-700{{$errors->account->has('name') ? ' text-red-400' : ''}}">{{ __('Name') }}</label>
33+
34+
<input id="name" class="rounded-md shadow-sm border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 block mt-1 w-full{{$errors->account->has('name') ? ' border-red-400' : ''}}"
35+
type="text"
36+
name="name"
37+
value="{{ old('name', $user->name) }}"
38+
/>
39+
</div>
40+
41+
<div class="py-2">
42+
<label for="email" class="block font-medium text-sm text-gray-700{{$errors->account->has('email') ? ' text-red-400' : ''}}">{{ __('Email') }}</label>
43+
44+
<input id="email" class="rounded-md shadow-sm border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 block mt-1 w-full{{$errors->account->has('email') ? ' border-red-400' : ''}}"
45+
type="email"
46+
name="email"
47+
value="{{ old('email', $user->email) }}"
48+
/>
49+
</div>
50+
51+
<div class="flex justify-end mt-4">
52+
<button type="submit" class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:ring ring-gray-300 disabled:opacity-25 transition ease-in-out duration-150">
53+
{{ __('Update') }}
54+
</button>
55+
</div>
56+
</form>
57+
</div>
58+
</div>
59+
</div>
60+
</div>
61+
<div class="py-3">
62+
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
63+
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
64+
<div class="px-6">
65+
<h1 class="inline-block text-2xl sm:text-3xl font-extrabold text-slate-900 tracking-tight dark:text-slate-200 py-4 block sm:inline-block flex">{{ __('Change Password') }}</h1>
66+
@if ($errors->password->any())
67+
<ul class="mt-3 list-none list-inside text-sm text-red-400">
68+
@foreach ($errors->password->all() as $error)
69+
<li>{{ $error }}</li>
70+
@endforeach
71+
</ul>
72+
@endif
73+
@if(session()->has('password_message'))
74+
<div class="mb-8 text-green-400 font-bold">
75+
{{ session()->get('password_message') }}
76+
</div>
77+
@endif
78+
</div>
79+
<div class="w-full px-6 py-4 bg-white overflow-hidden">
80+
81+
<form method="POST" action="{{ route('admin.account.password.store') }}">
82+
@csrf
83+
84+
<div class="py-2">
85+
<label for="old_password" class="block font-medium text-sm text-gray-700{{$errors->password->has('old_password') ? ' text-red-400' : ''}}">{{ __('Old Password') }}</label>
86+
87+
<input id="old_password" class="rounded-md shadow-sm border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 block mt-1 w-full{{$errors->password->has('old_password') ? ' border-red-400' : ''}}"
88+
type="password"
89+
name="old_password"
90+
/>
91+
</div>
92+
93+
<div class="py-2">
94+
<label for="new_password" class="block font-medium text-sm text-gray-700{{$errors->password->has('new_password') ? ' text-red-400' : ''}}">{{ __('New Password') }}</label>
95+
96+
<input id="new_password" class="rounded-md shadow-sm border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 block mt-1 w-full{{$errors->password->has('new_password') ? ' border-red-400' : ''}}"
97+
type="password"
98+
name="new_password"
99+
/>
100+
</div>
101+
102+
<div class="py-2">
103+
<label for="confirm_password" class="block font-medium text-sm text-gray-700{{$errors->password->has('confirm_password') ? ' text-red-400' : ''}}">{{ __('Confirm password') }}</label>
104+
105+
<input id="confirm_password" class="rounded-md shadow-sm border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 block mt-1 w-full{{$errors->password->has('confirm_password') ? ' border-red-400' : ''}}"
106+
type="password"
107+
name="confirm_password"
108+
/>
109+
</div>
110+
111+
<div class="flex justify-end mt-4">
112+
<button type='submit' class='inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:ring ring-gray-300 disabled:opacity-25 transition ease-in-out duration-150'>
113+
{{ __('Change Password') }}
114+
</button>
115+
</div>
116+
</form>
117+
</div>
118+
</div>
119+
</div>
120+
</div>
121+
</x-app-layout>

resources/views/layouts/navigation.blade.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444

4545
<x-slot name="content">
4646
<!-- Authentication -->
47+
<x-dropdown-link :href="route('admin.account.info')" :active="request()->routeIs('admin.account.info')">
48+
{{ __('My Account') }}
49+
</x-dropdown-link>
4750
<form method="POST" action="{{ route('logout') }}">
4851
@csrf
4952

@@ -94,6 +97,9 @@
9497
</div>
9598

9699
<div class="mt-3 space-y-1">
100+
<x-responsive-nav-link :href="route('admin.account.info')" :active="request()->routeIs('admin.account.info')">
101+
{{ __('My Account') }}
102+
</x-responsive-nav-link>
97103
<!-- Authentication -->
98104
<form method="POST" action="{{ route('logout') }}">
99105
@csrf

routes/admin.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
Route::resource('user', 'UserController');
99
Route::resource('role', 'RoleController');
1010
Route::resource('permission', 'PermissionController');
11+
Route::get('edit-account-info', 'UserController@accountInfo')->name('admin.account.info');
12+
Route::post('edit-account-info', 'UserController@accountInfoStore')->name('admin.account.info.store');
13+
Route::post('change-password', 'UserController@changePasswordStore')->name('admin.account.password.store');
1114
});

0 commit comments

Comments
 (0)