customer profile old password match bug fixed

This commit is contained in:
prashant-webkul 2018-11-22 22:00:10 +05:30
parent 5b5006b809
commit 460b025b2b
5 changed files with 89 additions and 23 deletions

View File

@ -8,6 +8,8 @@ use Illuminate\Http\Response;
use Illuminate\Support\Facades\Event;
use Auth;
use Cart;
use Validator;
use Hash;
/**
* Customer controller for the APIs of Profile customer
@ -37,17 +39,46 @@ class CustomerController extends Controller
if($this->customer == 'unauthorized') {
return response()->json($this->customer, 401);
} else {
$customer = [
'id' => $this->customer->id,
'first_name' => $this->customer->first_name,
'last_name' => $this->customer->last_name,
'gender' => $this->customer->gender,
'date_of_birth' => $this->customer->date_of_birth,
'email' => $this->customer->email,
'subscribed_to_news_letter' => $this->customer->subscribed_to_news_letter,
];
$customer = auth()->guard('customer')->user();
}
return response()->json($customer, 200);
}
public function updateProfile($id) {
$validator = Validator::make(request()->all(), [
'first_name' => 'string|required',
'last_name' => 'string|required',
'gender' => 'required',
'date_of_birth' => 'date',
'email' => 'email|required|unique:customers,email,'.$id,
'password' => 'confirmed|required_if:oldpassword,!=,null'
]);
if ($validator->fails()) {
return response()->json($validator->messages(), 400);
}
$data = collect(request()->all())->toArray();
if($data['oldpassword'] == null) {
$data = collect(request()->input())->except([ 'oldpassword', 'password', 'password_confirmation'])->toArray();
} else {
if(Hash::check($data['oldpassword'], auth()->guard('customer')->user()->password)) {
$data = collect(request()->input())->toArray();
$data['password'] = bcrypt($data['password']);
} else {
return response()->json('Old password does not match', 200);
}
}
$result = $this->customer->update($data);
if($result) {
return response()->json(true, 200);
} else {
return response()->json(false, 200);
}
}
}

View File

@ -7,8 +7,9 @@ Route::group(['namespace' => 'Webkul\API\Http\Controllers\Customer', 'prefix' =>
//auth route for customer
Route::post('logout', 'AuthController@destroy');
//get user
Route::get('get/user', 'CustomerController@getProfile');
//get customer profile
Route::get('get/profile', 'CustomerController@getProfile');
Route::put('update/profile/{id}', 'CustomerController@updateProfile');
//wishlist
Route::get('get/wishlist', 'WishlistController@getWishlist');
@ -16,11 +17,8 @@ Route::group(['namespace' => 'Webkul\API\Http\Controllers\Customer', 'prefix' =>
//address
Route::get('get/address', 'AddressController@get');
Route::get('get/default/address', 'AddressController@getDefault');
Route::post('create/address', 'AddressController@create');
Route::put('make/default/address/{id}', 'AddressController@makeDefault');
Route::delete('delete/address/{id}', 'AddressController@delete');
});

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddIsVerifiedColumnInCustomersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('customers', function (Blueprint $table) {
$table->boolean('is_verified')->nullable()->after('subscribed_to_news_letter');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('customers', function (Blueprint $table) {
$table->dropColumn('is_verified');
});
}
}

View File

@ -8,6 +8,7 @@ use Webkul\Customer\Repositories\CustomerRepository;
use Webkul\Product\Repositories\ProductReviewRepository as ProductReview;
use Webkul\Customer\Models\Customer;
use Auth;
use Hash;
/**
* Customer controlller for the customer basically for the tasks of customers which will be done after customer authentication.
@ -94,41 +95,45 @@ class CustomerController extends Controller
$id = auth()->guard('customer')->user()->id;
$this->validate(request(), [
'first_name' => 'string',
'last_name' => 'string',
'gender' => 'required',
'date_of_birth' => 'date',
'email' => 'email|unique:customers,email,'.$id,
'password' => 'confirmed|required_if:oldpassword,!=,null'
]);
$data = collect(request()->input())->except('_token')->toArray();
if($data['oldpassword'] == null) {
$data = collect(request()->input())->except(['_token','password','password_confirmation','oldpassword'])->toArray();
if($this->customer->update($data, $id)) {
Session()->flash('success','Profile Updated Successfully');
return redirect()->back();
} else {
Session()->flash('success','Profile Updated Successfully');
Session()->flash('success','Profile Cannot Be Updated Successfully');
return redirect()->back();
}
} else {
$data = collect(request()->input())->except(['_token','oldpassword'])->toArray();
if(Hash::check($data['oldpassword'], auth()->guard('customer')->user()->password)) {
$data = collect(request()->input())->except(['_token','oldpassword'])->toArray();
$data['password'] = bcrypt($data['password']);
$data['password'] = bcrypt($data['password']);
} else {
session()->flash('warning', 'The Old Password Does Not Match');
return redirect()->back();
}
if($this->customer->update($data, $id)) {
Session()->flash('success','Profile Updated Successfully');
return redirect()->back();
} else {
Session()->flash('success','Profile Updated Successfully');
Session()->flash('success','Profile Cannot Be Updated Successfully');
return redirect()->back();
}

View File

@ -58,7 +58,7 @@
<div class="control-group" :class="[errors.has('old_password') ? 'has-error' : '']">
<label for="password">{{ __('shop::app.customer.account.profile.opassword') }}</label>
<input type="oldpassword" class="control" name="oldpassword">
<input type="password" class="control" name="oldpassword">
<span class="control-error" v-if="errors.has('oldpassword')">@{{ errors.first('oldpassword') }}</span>
</div>
@ -68,7 +68,7 @@
<span class="control-error" v-if="errors.has('password')">@{{ errors.first('password') }}</span>
</div>
<div class="control-group">
<div class="control-group" :class="[errors.has('password_confirmation') ? 'has-error' : '']">
<label for="password">{{ __('shop::app.customer.account.profile.cpassword') }}</label>
<input type="password" class="control" name="password_confirmation">
<span>@{{ errors.first('password') }}</span>