Merge pull request #1650 from shivam-webkul/shivam

[Bug Fixed #1219 ] & [Enhancement #1182]  Fixed
This commit is contained in:
Jitendra Singh 2019-10-24 10:36:53 +05:30 committed by GitHub
commit 4fcff1e111
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 185 additions and 27 deletions

View File

@ -40,7 +40,7 @@ class SessionController extends Controller
auth()->setDefaultDriver($this->guard);
$this->middleware('auth:' . $this->guard, ['only' => ['get', 'update', 'destroy']]);
$this->_config = request('_config');
$this->customerRepository = $customerRepository;
@ -69,7 +69,7 @@ class SessionController extends Controller
Event::fire('customer.after.login', request()->input('email'));
$customer = auth($this->guard)->user();
return response()->json([
'token' => $jwtToken,
'message' => 'Logged in successfully.',

View File

@ -25,7 +25,7 @@
<div class="control-group" :class="[errors.has('password') ? 'has-error' : '']">
<label for="password">{{ __('admin::app.users.sessions.password') }}</label>
<input type="password" v-validate="'required|min:6'" class="control" id="password" name="password" data-vv-as="&quot;{{ __('admin::app.users.sessions.password') }}&quot;"/>
<input type="password" v-validate="'required|min:6'" class="control" id="password" name="password" data-vv-as="&quot;{{ __('admin::app.users.sessions.password') }}&quot;" value=""/>
<span class="control-error" v-if="errors.has('password')">@{{ errors.first('password') }}</span>
</div>

View File

@ -11,6 +11,7 @@ use Webkul\Sales\Repositories\OrderRepository;
use Webkul\Discount\Helpers\Cart\CouponAbleRule as Coupon;
use Webkul\Discount\Helpers\Cart\NonCouponAbleRule as NonCoupon;
use Webkul\Discount\Helpers\Cart\ValidatesDiscount;
use Webkul\Customer\Repositories\CustomerRepository;
/**
* Chekout controller for the customer and guest for placing order
@ -52,6 +53,11 @@ class OnepageController extends Controller
*/
protected $validatesDiscount;
/**
* customerRepository instance object
*/
protected $customerRepository;
/**
* Create a new controller instance.
*
@ -62,7 +68,8 @@ class OnepageController extends Controller
OrderRepository $orderRepository,
Coupon $coupon,
NonCoupon $nonCoupon,
ValidatesDiscount $validatesDiscount
ValidatesDiscount $validatesDiscount,
CustomerRepository $customerRepository
)
{
$this->coupon = $coupon;
@ -73,6 +80,8 @@ class OnepageController extends Controller
$this->validatesDiscount = $validatesDiscount;
$this->customerRepository = $customerRepository;
$this->_config = request('_config');
}
@ -324,4 +333,41 @@ class OnepageController extends Controller
], 422);
}
}
/**
* Check Customer is exist or not
*
* @return Response
*/
public function checkExistCustomer()
{
//check customer is exist or not
$customer = $this->customerRepository->findOneWhere([
'email' => request()->email
]);
//if customer is exist
if (! is_null($customer)) {
return 'true';
}
return 'false';
}
//login for checkout
public function loginForCheckout()
{
$this->validate(request(), [
'email' => 'required|email',
'password' => 'required'
]);
if (! auth()->guard('customer')->attempt(request(['email', 'password']))) {
return response()->json(['error' => trans('shop::app.customer.login-form.invalid-creds')]);
}
//Event passed to prepare cart after login
Cart::mergeCart();
return response()->json(['success' => 'Login successfully']);
}
}

View File

@ -165,6 +165,12 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function
//resend verification email
Route::get('/resend/verification/{email}', 'Webkul\Customer\Http\Controllers\RegistrationController@resendVerificationEmail')->name('customer.resend.verification-email');
// for customer login checkout
Route::post('/customer/exist', 'Webkul\Shop\Http\Controllers\OnepageController@checkExistCustomer')->name('customer.checkout.exist');
// for customer login checkout
Route::post('/customer/checkout/login', 'Webkul\Shop\Http\Controllers\OnepageController@loginForCheckout')->name('customer.checkout.login');
// Auth Routes
Route::group(['middleware' => ['customer']], function () {

View File

@ -496,7 +496,9 @@ return [
'money-desc' => 'Money Transfer',
'paypal-desc' => 'Paypal Standard',
'free-desc' => 'This is a free shipping',
'flat-desc' => 'This is a flat rate'
'flat-desc' => 'This is a flat rate',
'password' => 'Password',
'login-exist-message' => 'You already have an account with us, Sign in or continue as guest.'
],
'total' => [

View File

@ -0,0 +1,27 @@
<div class="control-group" id="password" :class="[errors.has('address-form.password') ? 'has-error' : '']">
<label for="password" class="required">
{{ __('shop::app.checkout.onepage.password') }}
</label>
<input type="password" v-validate="'required|min:6'" class="control" id="password" name="password" v-model="address.billing.password" data-vv-as="&quot;{{ __('shop::app.checkout.onepage.password') }}&quot;"/>
<span class="control-error" v-if="errors.has('address-form.password')">
@{{ errors.first('address-form.password') }}
</span> <br>
<span>{{ __('shop::app.checkout.onepage.login-exist-message') }}</span>
</div>
<div class="control-group" id="login-and-forgot-btn">
<div class="forgot-password-link" style="float: right;margin-right: 503px; margin-top: 11px;">
<a href="{{ route('customer.forgot-password.create') }}">{{ __('shop::app.customer.login-form.forgot_pass') }}</a>
<div class="mt-10">
@if (Cookie::has('enable-resend'))
@if (Cookie::get('enable-resend') == true)
<a href="{{ route('customer.resend.verification-email', Cookie::get('email-for-resend')) }}">{{ __('shop::app.customer.login-form.resend-verification') }}</a>
@endif
@endif
</div>
</div>
<input type='button' id="" class="btn btn-primary btn-lg btn-login" value="{{ __('shop::app.customer.login-form.button_title') }}" />
</div>

View File

@ -43,7 +43,7 @@
</ul>
</div>
</div>
<div id="message"></div>
<div class="control-group" :class="[errors.has('address-form.billing[address_id]') ? 'has-error' : '']">
<span class="control-error" v-if="errors.has('address-form.billing[address_id]')">
@{{ errors.first('address-form.billing[address_id]') }}
@ -67,12 +67,6 @@
<div class="form-header">
<h1>{{ __('shop::app.checkout.onepage.billing-address') }}</h1>
@guest('customer')
<a class="btn btn-lg btn-primary" href="{{ route('customer.session.index') }}">
{{ __('shop::app.checkout.onepage.sign-in') }}
</a>
@endguest
@auth('customer')
@if(count(auth('customer')->user()->addresses))
<a class="btn btn-lg btn-primary" @click = backToSavedBillingAddress()>
@ -82,6 +76,23 @@
@endauth
</div>
<div class="control-group" :class="[errors.has('address-form.billing[email]') ? 'has-error' : '']">
<label for="billing[email]" class="required">
{{ __('shop::app.checkout.onepage.email') }}
</label>
<input type="text" v-validate="'required|email'" class="control" id="billing[email]" name="billing[email]" v-model="address.billing.email" data-vv-as="&quot;{{ __('shop::app.checkout.onepage.email') }}&quot;"/>
<span class="control-error" v-if="errors.has('address-form.billing[email]')">
@{{ errors.first('address-form.billing[email]') }}
</span>
</div>
{{-- for customer login checkout --}}
@if (! auth()->guard('customer')->check())
@include('shop::checkout.onepage.customer-checkout')
@endif
<div class="control-group" :class="[errors.has('address-form.billing[first_name]') ? 'has-error' : '']">
<label for="billing[first_name]" class="required">
{{ __('shop::app.checkout.onepage.first-name') }}
@ -106,18 +117,6 @@
</span>
</div>
<div class="control-group" :class="[errors.has('address-form.billing[email]') ? 'has-error' : '']">
<label for="billing[email]" class="required">
{{ __('shop::app.checkout.onepage.email') }}
</label>
<input type="text" v-validate="'required|email'" class="control" id="billing[email]" name="billing[email]" v-model="address.billing.email" data-vv-as="&quot;{{ __('shop::app.checkout.onepage.email') }}&quot;"/>
<span class="control-error" v-if="errors.has('address-form.billing[email]')">
@{{ errors.first('address-form.billing[email]') }}
</span>
</div>
<div class="control-group" :class="[errors.has('address-form.billing[address1][]') ? 'has-error' : '']">
<label for="billing_address_0" class="required">
{{ __('shop::app.checkout.onepage.address1') }}
@ -454,3 +453,80 @@
@endif
</form>
@push('scripts')
<script>
var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
$(document).ready(function() {
$("#password").hide();
$('#login-and-forgot-btn').hide();
$("[name='billing[email]']").on('blur', function() {
//get the given emai
var email = $("[name='billing[email]']").val();
$.ajax({
/* the route pointing to the post function */
url: '{{ route('customer.checkout.exist') }}',
type: 'POST',
/* send the csrf-token and the input to the controller with data */
data: {'_token': CSRF_TOKEN,
'email': email },
dataType: 'JSON',
/* remind that 'data' is the response of the OnePageController */
success: function (data) {
if (data == true) {
$("#password").show();
$('#login-and-forgot-btn').show();
} else {
$("#password").hide();
$('#login-and-forgot-btn').hide();
}
}
});
});
});
$(document).ready(function() {
$('.btn-login').click(function(e) {
var email = $("[name='billing[email]']").val();
var password = $("[name='password']").val();
event.preventDefault();
$.ajax({
/* the route pointing to the post function */
url: '{{ route('customer.checkout.login') }}',
type: 'POST',
/* send the csrf-token and the input to the controller with data */
data: {'_token': CSRF_TOKEN,
'email': email,
'password': password
},
dataType: 'JSON',
/* remind that 'data' is the response of the OnePageController */
success: function (response) {
if (response.success) {
window.location.href = "{{ route('shop.checkout.onepage.index') }}";
} else {
var appendData = '<div class="alert alert-error"><span class="icon white-cross-sm-icon"></span><p>'+response.error+'</p></div>';
$('.alert-wrapper').html('');
$('.alert-wrapper').append(appendData);
setTimeout(function () {
$('.alert-error').hide();
}, 5000);
Success = false;
}
},
});
});
});
</script>
@endpush

View File

@ -28,7 +28,7 @@
<div class="control-group" :class="[errors.has('password') ? 'has-error' : '']">
<label for="password" class="required">{{ __('shop::app.customer.login-form.password') }}</label>
<input type="password" class="control" name="password" v-validate="'required'" value="{{ old('password') }}" data-vv-as="&quot;{{ __('shop::app.customer.login-form.password') }}&quot;">
<input type="password" v-validate="'required|min:6'" class="control" id="password" name="password" data-vv-as="&quot;{{ __('admin::app.users.sessions.password') }}&quot;" value=""/>
<span class="control-error" v-if="errors.has('password')">@{{ errors.first('password') }}</span>
</div>
@ -53,4 +53,5 @@
{!! view_render_event('bagisto.shop.customers.login.after') !!}
</div>
@endsection
@stop

View File

@ -36,7 +36,7 @@ class SessionController extends Controller
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\View\View
* @return \Illuminate\View\View
*/
public function create()
{