Subversion Repositories SmartDukaan

Rev

Rev 13739 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13736 anikendra 1
<div class="container mobileverification">
2
	<div class="askformobileverification text-center">Please give a missed call to verify your mobile number</div>
3
	<div class="telecaller"><img src="/img/telecaller.png" class="img "/></div>
4
	<div class="telecaller hidden" id="callbtncontainer"><a id="callbtn"><img src="/img/callbtn.png" class="img "/></a></div>
5
	<div class="verificationcontrols">
6
		<?php if(empty($logged_user['User']['mobile_number'])):?>
7
		<form id="enter_number">
8
			<p>Enter your phone number:</p>
13747 anikendra 9
			<p><input type="number" name="phone_number" id="phone_number" /></p>
13736 anikendra 10
			<p><input type="submit" name="submit" value="Verify" /></p>
11
		</form>
12
		<?php endif;?>
13
		<div id="dial2verify" class="hidden">
14
			<p id="waiting_msg"></p>
15
			<p id="Image">Loading ..</strong></p>
16
            <p id="status">Loading ..</strong></p>
17
		</div>
18
	</div>
19
	<div class="pull-right skipbtn">
20
		<a href="/users/skipmobileverification"><img src="/img/skipbtn.png" class="img "/></a>
21
	</div>
22
</div>
23
<script type="text/javascript">
24
	var attempt=1;
25
	var SID="";
26
 
27
	$(document).ready(function(){
28
		$("#enter_number").submit(function(e) {
29
			 e.preventDefault();
30
			 initiateDial2Verify();
31
	  	});
32
	});
33
 
34
	function initiateDial2Verify() {
35
		showCodeForm(1); 
36
		GetVerificationImage();
37
	}
38
 
39
	function showCodeForm(code) {
40
		$("#dial2verify").toggleClass('hidden');
41
		$("#dial2verify").fadeIn();
42
		$("#enter_number").fadeOut();
43
		$("#waiting_msg").text("Waiting for missed call from "+$("#phone_number").val());
44
	}
45
 
46
	function GetVerificationImage() {
47
		$.post("/users/getdial2verifynumber", { phone_number : $("#phone_number").val() }, 
48
			function(data) { updateImage(data.ImageUrl,data.SessionId,data.VerificationNode); }, "json");
49
	}	
50
 
51
 
52
	function updateImage(ImageURL, vSID, telnum) {		
53
        if ( ImageURL === "Err" || ImageURL === ""  ) { 
54
        	Err(); 
55
        } else {
56
         	$("#Image").html("Please give a missed call to <br><img src=\""+ImageURL+"\"/>");
57
     		SID = vSID;
58
     		$('#callbtncontainer').removeClass('hidden');
13739 anikendra 59
     		$('#callbtn').attr('href','tel:'+telnum);
13736 anikendra 60
     		PollStart("UnVerified");
61
        }
62
    }
63
 
64
	function CheckStatus() {
65
		$.post("/users/getdial2verifystatus", { SID : SID }, 
66
		   function(data) { PollStart(data.VerificationStatus); }, "json");
67
	}
68
 
69
 
70
	function PollStart(vStatus)	{
71
		attempt =attempt+1;
72
		if ( attempt >= 90  ) { 
73
			TimeoutCheck(); 
74
		} else if (vStatus === "UnVerified") { 
75
			$("#status").html("Please give a missed call in  <b><i>"+(90-attempt) +"</i></b> seconds");
76
			setTimeout(CheckStatus, 1000);
77
		} else if (vStatus === "VERIFIED") {
78
			success(); 
79
		} else{
80
			TimeoutCheck();
81
		}
82
	}	
83
 
84
    function Err() {
85
	    $("#status").html("Error!<br>Sorry something went wrong, Please cross check your telephone number."); 
86
    }
87
 
88
	function success() {
89
		$("#status").text("Congrats !!! Phone number is Verified!");
90
		var dt = new Date();
91
		var str = dt.toYMD();
92
		$.post("/users/edit/"+me, { mobile_number : $("#phone_number").val(),'mobile_verified' : 1, 'mobile_number_last_updated' : str, 'id' : me}, 
93
			function(data) { 
94
				if(data,success) {
95
					$.get("/users/reauthenticate/"+me,function(authdata){
96
						document.location = '/deals/mine/?user_id='+me;
97
					},'json'); 
98
				}				
99
			}, "json");
100
	}
101
 
102
	function TimeoutCheck() {
103
		$("#status").text("Verification Failed!");
104
	}
105
 
106
	(function() {
107
    Date.prototype.toYMD = Date_toYMD;
108
    function Date_toYMD() {
109
        var year, month, day;
110
        year = String(this.getFullYear());
111
        month = String(this.getMonth() + 1);
112
        if (month.length == 1) {
113
            month = "0" + month;
114
        }
115
        day = String(this.getDate());
116
        if (day.length == 1) {
117
            day = "0" + day;
118
        }
119
        return year + "-" + month + "-" + day;
120
    }
121
})();
13739 anikendra 122
</script>