otp sms codeigniter

<?php

step2:
  public function send_regotp($number) {
        if (!empty($number)) {
            $number = '91' . $number;
            //echo $number;
            $otpId = $this->User_Model->send_otp($number);
            return $otpId;
         
        } else {
            echo '<h4 style="color:red">Please Enter Valid Number..</h4>';
        }
    }
step2.1:
public function send_otp($number){
        require('Textlocal.class.php');
   
      $data['otp'] = random_string('numeric',4);
        $data['otp_id'] = random_string('alnum',6);
        $this->db->insert('otp',$data);
        $res = $this->db->where('oid',$this->db->insert_id())->get('otp')->row();

$Textlocal = new Textlocal(false, false, 'hFtRWqxqYHM-nxAWhDMS6qKp4cKYAEHwPbIh1MVLXG');

$numbers = array($number);
$sender = 'CASINO';
//$message = 'Please enter the OTP :'. $data['otp'].' ';
        $message = 'Thank you for registering with us. Please enter your OTP : '.$data['otp'].' to verify your account.';

$response = $Textlocal->sendSms($numbers, $message, $sender);
        return $res->otp_id;
     
     
    }
step 1: $("#register-form").on('submit', function (event) {
                                                        event.preventDefault();
                                                        // alert();

                                                        $.ajax({
                                                            url: "<?= base_url('User/user_registration222') ?>",
                                                            type: "POST",
                                                            data: new FormData(this),
                                                            cache: false,
                                                            contentType: false,
                                                            processData: false,
                                                            success: function (response) {
                                                                // var data = JSON.stringify(response);

                                                                var obj = JSON.parse(response);
                                                                if (obj.success === 'success') {
                                                                 
              /**calling step3 ID = OTPVerifForm**/   $(".reg_sucs").html('<form id="OTPVerifForm" method="post">\n\
                          <div class="col-xs-12">\n\
                          <div class="form-group">\n\
    <input type="number" name="otp" class=" form-control" maxlength="6" placeholder="Enter OTP..." required>\n\
    <input type="hidden" name="otp_id" value="' + obj.otpid + '">\n\
                        \n\
                        </div>\n\
                            </div>\n\
                            <div class="col-xs-12 text-center">\n\
                            <div class="form-group">\n\
                        <button type="submit" class="btn btn-primary">VERIFY</button>\n\
                            </div>\n\
                            </div>\n\
                            \n\
                        </form>\n\
           <p>Click <a href="javascript:;" id="otp_again" data-num="' + obj.number + '"><span class="label label-danger label-mini">here</span></a> to re-generate OTP</p>');

                                                                } else {
                                                                    $(".reg_sucs").html('<div class="alert alert-danger"> <strong>Fail!</strong> your registration is failure.</div>');
                                                                }
                                                            }
                                                        });
                                                    });

    public function otp_response() {
        $data['otpId'] = $this->input->post('otpId');
        $data['num'] = $this->input->post('number');

        // $this->load->view('templates/header');
        $this->load->view('user/otp_resp', $data);
        //  $this->load->view('templates/footer');
    }

 








                                    /**step3 javscirpt of stp 3**/                $("body").on('submit', '#OTPVerifForm', (function (e) {
                                                        //$("#OTPVerifForm").('submit', (function (e) {
                                                        // $(".roller-clue").addClass("roller");
                                                        $('#otp_msg_resp').html('<img src="<?= base_url('assets/images/load.gif') ?>" alt="" width="80" height="80" />');
                                                        e.preventDefault();
                                                        $.ajax({
                                                            url: "<?= base_url('User/verify_otp') ?>", // Url to which the request is send
                                                            type: "POST", // Type of request to be send, called as method
                                                            data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
                                                            contentType: false, // The content type used when sending data to the server.
                                                            cache: false, // To unable request pages to be cached
                                                            processData: false, // To send
                                                            success: function (data) {
                                                             //   alert(data);
                                                                if (data === 'success') {
                                                                    $('#otp_msg_resp').html('<img class="text-center" src="<?= base_url('assets/images/right.png') ?>" alt="" width="50" height="50" /> <br> <span style="color:green">Verified</span>');
                                                                    $("#otp_msg_resp").delay(3000).fadeOut(1500);
                                                                    $("#otp_msg_resp").show();
                                                                    setTimeout(function () {
                                                                        $("#otp_msg_cls").click();
                                                                    }, 3000);

                                                                    setTimeout(function () {
                                                                        location.reload();
                                                                    }, 4000);
                                                                } else {
                                                                    $('#otp_msg_resp').html('<img src="<?= base_url('assets/images/wrong.jpeg') ?>" alt="" width="50" height="50" /><br> <span style="color:red">Not Verified</span>');
                                                                    $("#otp_msg_resp").delay(3000).fadeOut(1500);
                                                                    $("#otp_msg_resp").show();
                                                                    setTimeout(function () {
                                                                        location.reload();
                                                                    }, 2000);
                                                                }

                                                                //$("#succes_msg").delay(6000).fadeOut(1500);
                                                            }

                                                        });


                                                    }));


 /**step 4 **/public function verify_otp() {
     echo   $otp_id = $this->input->post('otp_id');
        $ver_otp = $this->User_Model->verify_otp($otp_id);
        if ($ver_otp->otp == $this->input->post('otp')) {
            $this->db->where('otp_id', $this->input->post('otp_id'))->delete('otp');
         
        }
    }
/**step 4.1 **/
    public function verify_otp($otp_id){
        $res = $this->db->where('otp_id',$otp_id)->get('otp')->row();
        return $res;
    }



                                                $('#otp_again').click(function () {
                                                    var num = $(this).attr('data-num');
                                                    //alert(num);
                                                    $('#otp_msg_resp').html('<img src="<?= base_url('assets/images/load.gif') ?>" alt="" width="80" height="80" />');
                                                    $.ajax({
                                                        url: '<?= base_url() ?>Users/sendOTPagain',
                                                        type: 'POST',
                                                        data: {
                                                            num: num
                                                        },
                                                        success: function (data) {
                                                            $('#otp_msg_resp').html(data);
                                                        }

                                                    });
                                                });

Comments

Popular posts from this blog

mysql 1