Skip to content

Commit

Permalink
change password
Browse files Browse the repository at this point in the history
  • Loading branch information
linrium committed Dec 20, 2016
1 parent bf59eef commit c9f6c7e
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 42 deletions.
76 changes: 46 additions & 30 deletions app/Http/Controllers/Member/MyAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use App\Http\Controllers\Controller;

use Auth;
use App\User;
use Hash;

class MyAccountController extends Controller
{
Expand All @@ -26,46 +28,49 @@ public function index()
}

/**
* Show the form for creating a new resource.
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function create()
public function edit($id)
{
//
}
$user = User::find($id)->toArray();

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
return view('member.myaccount.edit', compact('user'));
}

/**
* Display the specified resource.
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function update(Request $request, $id)
{
//
$user = User::find($id);
$user->username = $request->txtName;
$user->save();

return redirect()->route('myaccount.index')->with([
'flash_level'=>'success',
'flash_message'=>'Username updated succesfully'
]);
}


/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
public function editPassword($id)
{
//
$user = User::find($id)->toArray();

return view('member.myaccount.editPassword', compact('user'));
}

/**
Expand All @@ -75,19 +80,30 @@ public function edit($id)
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function updatePassword(Request $request, $id)
{
//
}
$this->validate($request, [
'txtPassword' => 'required|min:6|confirmed',
'txtRepassword' => 'required|min:6|confirmed|same:txtPassword'
]);

if(Hash::check($request->txtOldPassword, Auth::user()->password)) {
$user = User::find($id);
$user->password = $request->txtNewPassword;
$user->save();

return redirect()->route('myaccount.index')->with([
'flash_level'=>'success',
'flash_message'=>'Password updated succesfully'
]);
} else {
return redirect()->route('myaccount.editPassword')->with([
'flash_level'=>'success',
'flash_message'=>'Wrong password'
]);
}



/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
1 change: 0 additions & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public function edit($id)
public function update(Request $request, $id)
{
$user = User::find($id);
$user->name = $request->txtName;
$user->username = $request->txtName;
$user->email = $request->txtEmail;
$user->password = Hash::make($request->txtPassword);
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Requests/UserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public function authorize()
public function rules()
{
return [
'txtName' => 'required',
'txtEmail' => 'required|unique:users,email',
'txtPassword' => 'required',
'txtRepassword' => 'required|same:txtPassword'
'txtName' => 'required|max:255',
'txtEmail' => 'required|max:255|unique:users,email',
'txtPassword' => 'required|min:6|confirmed',
'txtRepassword' => 'required|min:6|confirmed|same:txtPassword'
];
}

Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/user/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-default">Create</button>
<button type="submit" class="btn btn-default">Update</button>
</div>
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/member/component/left-sidebar.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="sidebar-collapse" class="col-sm-3 col-lg-2 sidebar">
<ul class="nav menu">
<li><a href="{!! route('home.index') !!}"><svg class="glyph stroked dashboard-dial"><use xlink:href="#stroked-dashboard-dial"></use></svg> Home</a></li>
<li><a href="{!! route('user.index') !!}"><svg class="glyph stroked male user"><use xlink:href="#stroked-male-user"/></svg> My Account</a></li>
<li><a href="{!! route('myaccount.index') !!}"><svg class="glyph stroked male user"><use xlink:href="#stroked-male-user"/></svg> My Account</a></li>
</ul>

</div><!--/.sidebar-->
41 changes: 41 additions & 0 deletions resources/views/member/myaccount/edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@extends('member.master')
@section('content')
<div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main">

<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Edit my account manager</h1>
</div>
</div><!--/.row-->

<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">Change username</div>
<div class="panel-body">
<div class="col-lg-7">
@include('member.component.alertForm')
<form class="form-horizontal" action="{!! route('myaccount.update', $user['id']) !!}" method="post">
<input type="hidden" name="_token" value="{!! csrf_token() !!}">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="id" value="{{ $user['id'] }}">
<div class="form-group">
<label for="txtName" class="col-sm-3 control-label">Username</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="txtName" value="{!! old('txtName', isset($user) ? $user['username'] : '') !!}" name="txtName" placeholder="Please enter user name">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-success">Update</button>
<a href="{{ route('myaccount.index') }}" class="btn btn-default">Cancel</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div><!--/.row-->
</div> <!--/.main-->
@endsection()
53 changes: 53 additions & 0 deletions resources/views/member/myaccount/editPassword.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@extends('member.master')
@section('content')
<div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main">

<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Edit my account manager</h1>
</div>
</div><!--/.row-->

<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">Change username</div>
<div class="panel-body">
<div class="col-lg-7">
@include('member.component.alertForm')
<form class="form-horizontal" action="{!! route('myaccount.updatePassword', $user['id']) !!}" method="post">
<input type="hidden" name="_token" value="{!! csrf_token() !!}">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="id" value="{{ $user['id'] }}">
<div class="form-group">
<label for="txtName" class="col-sm-3 control-label">Old password</label>
<div class="col-sm-9">
<input type="password" class="form-control" id="txtOldPassword" name="txtOldPassword" placeholder="Please enter old password">
</div>
</div>
<div class="form-group">
<label for="txtName" class="col-sm-3 control-label">New password</label>
<div class="col-sm-9">
<input type="password" class="form-control" id="txtNewPassword" name="txtNewPassword" placeholder="Please enter new password">
</div>
</div>
<div class="form-group">
<label for="txtName" class="col-sm-3 control-label">New repassword</label>
<div class="col-sm-9">
<input type="password" class="form-control" id="txtNewRepassword" name="txtNewRepassword" placeholder="Please enter new repassword">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-success">Update</button>
<a href="{{ route('myaccount.index') }}" class="btn btn-default">Cancel</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div><!--/.row-->
</div> <!--/.main-->
@endsection()
28 changes: 24 additions & 4 deletions resources/views/member/myaccount/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,39 @@

<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Years manager</h1>
@include('admin.component.alert')
<h1 class="page-header">My Account manager</h1>
@include('member.component.alert')
</div>
</div><!--/.row-->

<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<a class="btn btn-success" href="{!! route('year.create') !!}">Create Year</a>
<a class="btn btn-success" href="{!! route('myaccount.edit', $user['id']) !!}">Change username</a>
<a class="btn btn-success" href="{!! route('myaccount.editPassword', $user['id']) !!}">Change password</a>
</div>
<div class="panel-body">
<h1>Hello</h1>
<form class="form-horizontal">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Username" name="txtUsername" value="{!! old('txtUsername', isset($user) ? $user['username'] : '') !!}" disabled>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Email address</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputPassword3" placeholder="Email" name="txtEmail" value="{!! old('txtEmail', isset($user) ? $user['email'] : '') !!}" disabled>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Role</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputPassword3" placeholder="Role" name="txtRole" value="{!! old('txtRole', isset($user) ? $user['role'] : '') !!}" disabled>
</div>
</div>
</form>
</div>
</div>
</div>
Expand Down
25 changes: 24 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,30 @@
});

Route::group(['prefix'=>'member'], function() {
Route::resource('myaccount', 'Member\MyAccountController');
Route::group(['prefix'=>'myaccount'], function() {
Route::get('', [
'as' => 'myaccount.index',
'uses' => 'Member\MyAccountController@index'
]);
Route::get('{id}/edit', [
'as' => 'myaccount.edit',
'uses' => 'Member\MyAccountController@edit'
]);
Route::put('{id}', [
'as' => 'myaccount.update',
'uses' => 'Member\MyAccountController@update'
]);

Route::get('{id}/editPassword', [
'as' => 'myaccount.editPassword',
'uses' => 'Member\MyAccountController@editPassword'
]);
Route::put('{id}/updatePassword', [
'as' => 'myaccount.updatePassword',
'uses' => 'Member\MyAccountController@updatePassword'
]);
});

});

Route::get('admin', function() {
Expand Down

0 comments on commit c9f6c7e

Please sign in to comment.