when we click on login it should be navigated to corresponding page based on the login paramsĀ
_.extend(LoginRegisterForgotPasswordView.prototype, {
template: jj_login_register_forgot_password_tpl,
events: _.extend({}, LoginRegistrationView.prototype.events, {
'click .login-button': 'showLoginView',
'click .signup-button': 'showRegisterView'
}),
showLoginView: function () {
this.updateUrlAndCookie(false);
this.$('.login-register-wrapper-login').show();
this.$('.login-register-wrapper-register').hide();
},
showRegisterView: function () {
this.updateUrlAndCookie(true);
this.$('.login-register-wrapper-login').hide();
this.$('.login-register-wrapper-register').show();
},
updateUrlAndCookie: function (loginParam) {
document.cookie = "LoginParam=" + loginParam + ";path=/";
let url = new URL(window.location.href);
url.searchParams.set("loginParam", loginParam.toString());
window.history.replaceState(null, null, url);
this.render();
},
getContext: _.wrap(LoginRegisterForgotPasswordView.prototype.getContext, function (fn) {
var context = fn.apply(this, _.toArray(arguments).slice(1));
var url = new URL(window.location.href);
var loginParam = url.searchParams.get("loginParam");
context.loginParam = loginParam === 'true';
return context;
}),
});
template
<div class="login-buttons-containers">
<button class="login-button {{#if loginParam}}text-green{{/if}}">
<a class="forgot-login" href="/login-register">
{{translate 'Login'}}
</a>
</button>
<button class="signup-button {{#unless loginParam}}text-green{{/unless}}">
<a class="forgot-sigunp" data-action="LoginRegister" loginparam="true"href="#">
{{translate 'Sign Up'}}
</a>
</button>
</div>