Friends I am having a strange issue with no idea what went wrong.
my company asked me to show a opopup with login options in opencart i.e. user cant browse products unless he/she register or login.
i used the following script to do that
ISSUE
it works fine once or twice after that the popup shows blank.
Codes
<script type="text/javascript">
$(document).ready(function(){
$("#logpop").append('<div id="loginbox" class="loginbox"></div>');var a=$("#welcome a").first().html();
$("#welcome a").first().html('<span class="login"></span>');$("#welcome a .login").html(a);-1!=$("#welcome a[href]").first().attr("href").indexOf("register")?($("#loginbox").load("index.php?route=account/login .right form"), $("#loginbox").css("right","50px")):
($("#loginbox").load("index.php?route=account/account #content"),$("#loginbox").css("right","40px"));
$("#welcome > a .login").live("hover",function(){$("#welcome").addClass("active");$("#loginbox .breadcrumb").remove();$("#loginbox h1").remove();});
});
$(document).ready(function(){
-1==$(location).attr("href").indexOf("account/logout")&&$.cookie("url",$(location).attr("href"));$("#welcome a").first().removeAttr("href");$("#logpop").first().css("display","none");$("#login_dimming").first().css("display","none");
});
</script>
friends can you please help me fix this problem
Instead of doing this via JS I'd suggest implementing a preAction that will check whether the user is logged-in and if not, it will redirect to the login/register screen.
How to implement a preAction: look into index.php where a preAction for maintenance mode is registered:
// Maintenance Mode
$controller->addPreAction(new Action('common/maintenance'));
You can add a new one:
// Logged-in user required
$controller->addPreAction(new Action('common/login'));
and then of course look into the catalog/controller/common/maintenance.php to see how it is done. You can implement something similar in Your new catalog/controller/common/login.php:
<?php
class ControllerCommonLogin extends Controller {
public function index() {
if (!$this->customer->isLogged()) {
return $this->forward('account/login');
}
}
}
This is much easier, more MVC and better way of checking whether user is logged-in before he can start shopping.
Related
I've been making some research these hours and without any success. I will explain my situation and I hope you help me in some way.
I'm making a project for my university, on my site I use the database on a local server with PHP my admin, PHP coding js functions, and html/css. My problem is that when I load the "dashboard site" I want to popup a modal from bootstrap which is a form to complete the second phase of registration, and that popup I do it with :
<script type="text/javascript">
$(window).on('load',function(){
$('#exampleModal3').modal('show');
});
</script>
I've tried to use "include_once" PHP function , or with JS use some tricks like: if(!stuffdone){doSomething ... stuffdone=true;}, but it's not working, when I load the dashboard the popup appears again and I cant make it show only once. My idea is to make it appear only once on the first login of the user and then it won't appear anymore and instead, it will be a button to change the user data which will call the modal popup. Also sorry for my English, is terrible.
Thank you
You could try localstorage to get the registration modal going. But you will have to store it in db and write a function in php that checks users registration progress. and keep in mind that localstorage is just clientside on that particular browser. Something like this pseudocode:
var hasRegged = localstorage.getItem('hasreg');
function checkReg(){
if (hasRegged===null){
$('#exampleModal3').modal('show');
localstorage.setItem('hasreg','1');
}
}
$(window).on('load',function(){
checkReg();
});
$(document).on('click','.finishedregbutton', function(){
//Save the clickdata to db
});
you could also do this with ajax:
function checkReg(){
$.ajax({
"url":"regcheck.php",
"data":"uuid=<?php echo $_SESSION['uuid'];?>",
"type":"POST",
"dataType":"JSON",
"success": function(data){
if(data.status=='completed'){
$('#exampleModal3').modal('show');
}
});
}
$(window).on('load',function(){
checkReg();
});
After login I am showing some user modules on html page. I want to hide it when user not have an access for that module by admin. I am use sencha/ ExtJs for front-end.
I want to hide this component after user login if he don't have permission for it.
here is my code(please see below Image)
I want to hide this Live Tracking On user login if user don't have access for this.
Design for this is bellow
I want to Create a function in App.js (In controller).
Can you help me for this...
Whenever you are validating the user or when it logs in, whenever that happens add style display:none
using javascript
document.getElementsByClassName('live-tracking').style.display= "none"
Your controller {
validateAndLogin : function () {
var isValidated = // check validation according your requirement.
if(isValidated) {
//display your html view and do following after adding id attribute to that
//div which you want to hide.
document.getElementById('livetracking').style.display='none';
}
}
I have a form on my contract form, which submits to a third party site and then I can define a URL to return the user to. I currently return the user to the same /contact page but I wanted to give them a message that it had submitted (since ajax forms don't work with the third party) and I don't want to have a whole page for it.
Therefore I had the idea to return the user to /contact#thanks
I have some code on my site which goes like this:
<div id="alert" class="hidden">Form Submitted. We will reply soon.</div>
Now I want a small bit of javascript on my page which detects if the URL has the #thanks tag on it, as above, and then removes the hidden class from my alert div. Is javascript able to detect this and if so, how do I go about it?
Include jquery and script. I test and work
$(document).ready(function(){
if(window.location.hash) {
$("#alert").show()
}
});
Siii = Yes use hash
I'm not totally sure that I've understood what are you trying to achieve, but this might help you:
if (window.location.hash === '#thanks') {
document.getElementById('alert').classList.remove('hidden');
}
I am not sure if this is possible or maybe I am just doing it the wrong way.
What I want to do is to call a function which checks the database to get the skype id (user B) and verify if user A is login. If user A is login and a Skype ID for user B is found then start up Skype. If not, nothing happens. Sounds simple enough....
A function is called when a user (user A) click on an image button on a form.
For example on start.html
<img src="images/chat.png" >
skypeme is a javascript function like this:
<script>
function skypeme(a,b) {
window.location = 'skypeme.cfm?a=' + a + '&b=' + b;
}
</script>
which calls skypeme.cfm to do all the database checking:
check the database and see if user A is login....
if user A is login, check if user B has skype ID
if skype id is found for user B do this
<script language="javascript">
window.location = 'skype:#skype_id#?chat';
</script>
else do nothing
else user A is not login
<script language="javascript">
signin('#a#','#b#');
</script>
The skypeme.cfm is doing its job and start up Skype when everything is checked out fine. However, the problem is when user click on the button on start.html, he is directed to a blank page skypeme.cfm (skypeme.cfm doesn't display anything but checking) then the skype starts.
Is there any way to do it so that when the user click on the chat button on start.html, he will REMAIN on the start.html page while skype.cfm check the database and kick up Skype with javascript code? This maybe something simple but I just can't get it to do that. Any help is appreciated. Thanks in advance.
Use to redirect to the link
window.location = 'skype:' + phone + '?call';
Instead of pointing window.location to skypeme.cfm, load it inside an iframe (you can either dynamically attach an iframe to the document or just change it's src). Redirecting the iframe to a skype: uri works just as fine.
Not quite sure how to explain this the best way, but i'll give it a go!
I have a php site that uses Fancybox. At the moment, if anyone clicks Login, an overlay appears with the login form. If someone clicks to post a new listing and they're not logged in, I'd like the fancybox overlay to appear again, allowing a user to login.
At the moment, I have a couple lines of php code that check if a session is active - if not, it redirects to a login page, I want this to activate a fancybox popup with the login form... if possible?
I'm not sure how best to achieve this? Any help would be awesome! :)
I'm not sure what programing language you are writing in besides jQuery, but a high-level solution might be to drop a cookie when the user logs in. Then, when they click to post a new listing, check for that cookie. If it's there, let them post. If not show the login window. Here's some pseudo code using the jQuery.Cookie plugin:
$(function(){
$('.login-button').click(function(){
//send login info via ajax
$(this).hide("slow",function(){
// drop a cookie
$.cookie( 'login', '1', { expires: 1, path: '/' } );
});
});
// When the post button is clicked, check for the cookie
// If there's no cookie, show the login box
$('.post-button').click(function(){
if( $.cookie('Login') === null ) {
$("#login-box").fancybox();
} else {
// do nothing
}
});
});
There can be multiple ways of doing so.
First of all, how are you identifying that someone is logged in? Suppose if I can do so with an if condition:
if(user==null) {
//no login
}
I can trigger the click of anchor link for LOGIN and thus, open the fancybox again.
if(user==null) {
$("a#login").trigger('click');
}
Hope it gives you some help.