StoreHippo offers the feature of Restricted Login to make login a compulsory function for your store. This functionality is used to ensure the security of your website. You can also use the email ids, thus collected for marketing purposes to promote your business to your customers.
To enable the restricted login in your store, you need to add a startup script to your store.
Follow the below steps to enable restricted login:
// On page change event is trigger and user will redirect to login
ms.bind('ms.page_loaded', function(event) {
//condition if user is not loggedin.
if(!ms.user.isLoggedIn && ms.page.url.indexOf('/user') == '-1'){
//specify on which location you want to redirect
ms.goTo('/user/login')
}
});
ms.bind('ms.page_loaded', function(event) {
//condition for substore
if(ms.substore && ms.substore.alias == 'delhi'){
//condition if user is not loggedin.
if(!ms.user.isLoggedIn && ms.page.url.indexOf('user') == '-1'){
//specify on which location you want to redirect
ms.goTo('/user/login')
}
}
})
ms.app.addPrehook({entity: "ms.carts", command: "addItem"}, function (req, res, next) {
if (!ms.user.isLoggedIn) {
ms.goTo('/user/login')
}
else next()
})