templates/security/register.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block stylesheets %}
  3.     {{ parent() }}
  4.     <style>
  5.         h4 {margin: 0;}
  6.         #send_verification_sms {
  7.             background-color: #337ab7;
  8.             border-color: #2e6da4;
  9.         }
  10.         #send_verification_sms:hover {color: #fff;}
  11.         #register_btn {display: none}
  12.         .errorCaptcha{ border: 1px solid #FF0000 }
  13.         .errorCaptchaMsg {color: #FF0000}
  14.          .tooltip-inner {color: #f00; border: 1px solid #f00}
  15.          input:invalid {color: #f00; border: 1px solid #f00}
  16.          input[type="text"]:valid {color: #008000; border: 1px solid #008000}
  17.          .red-bg{ background: #f6b3b3; color: #000 !important;}
  18.         /*input,
  19.         input:valid {
  20.             border-color: #ccc;
  21.         }*/
  22. /*
  23.         input{color: #f00; border: 1px solid #f00}
  24. */
  25.     </style>
  26. {% endblock %}
  27. {% block page_title %}{{ 'register new account' | trans({}, 'clients') }}{% endblock %}
  28. {% block flash_messages %}
  29.     {{ parent() }}
  30.     {# this is to display form global validation messages #}
  31.     {% if form_errors(form) is not empty %}
  32.         <div class="alert alert-danger" role="alert">
  33.             {{ form_errors(form) }}
  34.         </div>
  35.     {% endif %}
  36. {% endblock %}
  37. {% block body %}
  38.     <section class="section-padding error-page pattern-bg0 ">
  39.         <!-- Main Container -->
  40.         <div class="container">
  41.             <!-- Row -->
  42.             <div class="row">
  43.                 <!-- Middle Content Area -->
  44.                 <div class="col-md-12 col-sm-12 col-xs-12">
  45.                     <div class="form-grid required">{{ 'registration announcement message' | trans({'%{newline}':"<br />"}, 'clients')|raw }}</div>
  46.                     <br />
  47.                     <!--  Form -->
  48.                     <div class="form-grid">
  49.                         {{ form_start(form, {'attr': {'id': 'register_form'}} ) }}
  50.                             <div class="row">
  51.                                 <div class="form-group col-md-4 col-xs-12">
  52.                                     {{ form_label(form.userIdentityInfo.firstnameAr, null, {'label_attr' : {'class': 'black'} }) }} <span class='required'>*</span>
  53.                                     {{ form_widget(form.userIdentityInfo.firstnameAr) }}
  54.                                     {{ form_errors(form.userIdentityInfo.firstnameAr) }}
  55.                                 </div>
  56.                                 <div class="form-group col-md-4 col-xs-12">
  57.                                     {{ form_label(form.userIdentityInfo.fourthnameAr, null, {'label_attr' : {'class': 'black'} }) }} <span class='required'>*</span>
  58.                                     {{ form_widget(form.userIdentityInfo.fourthnameAr) }}
  59.                                     {{ form_errors(form.userIdentityInfo.fourthnameAr) }}
  60.                                 </div>
  61.                                 <div class="form-group col-md-4 col-xs-12" id="id_num_div">
  62.                                     {{ form_label(form.userIdentityInfo.identificationNumber, null, {'label_attr' : {'class': 'black'} }) }} <span class='required'>*</span>
  63.                                     {{ form_widget(form.userIdentityInfo.identificationNumber) }}
  64.                                     {{ form_errors(form.userIdentityInfo.identificationNumber) }}
  65.                                 </div>
  66.                             </div>
  67.                             <div class="row">
  68.                                 <div class="col-md-4 col-xs-12">
  69.                                     <div class="form-group col-md-6 col-xs-6">
  70.                                         <label>{{ 'enter the captcha code' | trans({}, 'clients') }}: <span class="required">*</span></label>
  71.                                         <input type="text" class="form-control {% if errorCaptcha %}{{ errorCaptcha }} {% endif %}" name="userCaptcha" id="userCaptcha" required="required" maxlength="4" validate-msg="{{ 'you should enter the captcha code' | trans({}, 'validators') }}" />
  72.                                             <span class="errorCaptchaMsg" style="font-size:12px;color:#e74c3c;display: {% if errorCaptcha %}{{ 'block' }} {% else %} {{ 'none' }} {% endif %}"> {{ 'captcha code is wrong' | trans({}, 'validators') }} </span>
  73.                                     </div>
  74.                                     <div class="form-group col-md-4 col-xs-4">
  75.                                         <label>&nbsp;</label>
  76.                                         <img id="captcha" src="{{ builder.inline }}" style="height: 50px !important; width: 115px !important;">
  77.                                     </div>
  78.                                     <div class="form-group col-md-2 col-xs-2">
  79.                                         <label>&nbsp;</label>
  80.                                         <p class="btn btn-light" id="refresh" style="padding:8px !important; margin-top:8px;">
  81.                                             <i class="fa fa-undo" style="font-size:14px" ></i>
  82.                                         </p>
  83.                                     </div>
  84.                                 </div>
  85.                                 <div class="form-group col-md-4 col-xs-12" id="mobile_num_div">
  86.                                     {{ form_label(form.mobileNumber, null, {'label_attr' : {'class': 'black'} }) }} <span class='required'>*</span>
  87.                                     <div class="input-group">
  88.                                         {{ form_widget(form.mobileNumber) }}
  89.                                         <div class="input-group-btn">
  90.                                             <input type="button" name="send_verification_sms" id="send_verification_sms" value="{{ 'send verification' | trans({}, 'clients') }}" class="form-control btn btn-light">
  91.                                         </div>
  92.                                     </div>
  93.                                     {{ form_errors(form.mobileNumber) }}
  94.                                 </div>
  95.                                 <div class="form-group col-md-4 col-xs-12" id="verification_code" style="display: none">
  96.                                     <label>{{ 'enter verification code' | trans({}, 'clients') }}: <span class="required">*</span></label>
  97.                                     <input type="text" name="sms_code" id="sms_code" required maxlength="3" minlength="3" validate-msg="{{ 'you should enter the verification code' | trans({}, 'validators') }}" class="form-control">
  98.                                 </div>
  99.                             </div>
  100.                             <div class="row">
  101.                                 <div class="col-md-3 col-xs-12 pull-right">
  102.                                     <input type="submit" value="{{ 'register' | trans({}, 'clients') }}" id="register_btn"  class="btn btn-theme btn-lg btn-block" style="width: 50% !important; margin: auto">
  103.                                 </div>
  104.                             </div>
  105.                         {{ form_end(form) }}
  106.                     </div>
  107.                     <!-- Form -->
  108.                 </div>
  109.                 <!-- Middle Content Area  End -->
  110.             </div>
  111.             <!-- Row End -->
  112.         </div>
  113.         <!-- Main Container End -->
  114.     </section>
  115.     <div class="footer-area">
  116.         <div class="footer-copyright">
  117.             <div class="">
  118.                 <a href="https://wa.me/966559661234" target="_blank" style="color: white;">
  119.                     <div dir="ltr" style="direction: ltr;">
  120.                         {{ 'support whatsapp contact' | trans}}
  121.                         <br /><img src="{{ asset('w1.png')}}" width="40" />
  122.                         +966-55-966-1234
  123.                     </div>
  124.                 </a>
  125.             </div>
  126.         </div>
  127.     </div>
  128. {% endblock %}
  129. {% block javascripts %}
  130.     
  131.     {{ parent() }}
  132.     <script type="text/javascript">
  133.         $(function(){
  134.             //loop on all form input fields to set validation messages according to validate-msg attribute
  135.             $("form :input").each(function(){
  136.                 var input = $(this);
  137.                 var msg   = input.attr('validate-msg');
  138.                 input.on('change invalid input', function(){
  139.                     input[0].setCustomValidity('');
  140.                     if (! input[0].validity.valid) {
  141.                         input[0].setCustomValidity(msg);
  142.                     }
  143.                 });
  144.             });
  145.             $('#send_verification_sms').click(function() {
  146.                 $("#appbundle_users_registration_mobileNumber,#appbundle_users_registration_userIdentityInfo_identificationNumber,#userCaptcha").removeClass("red-bg");
  147.                 //manually validating (on demand validation) form fields, except the sms_code field, before requesting a verification code on mobile
  148.                 var block_send_sms= false;
  149.                 $("form :input").not( "#sms_code" ).each(function(){
  150.                     var input = $(this);
  151.                     if (!input[0].checkValidity()) {
  152.                         var msg = input.attr('validate-msg');
  153.                         //manually marking the form field as invalid and immediately show validation message
  154.                         input[0].reportValidity(msg);
  155.                         block_send_sms= true;
  156.                     }
  157.                 });
  158.                 //dont proceed if even a single field validation failed
  159.                 if(block_send_sms){
  160.                     return;
  161.                 }
  162.                 // clear error messages in order not to confused with the current sending verification SMS result
  163.                 $("#mobile_num_div ul li").text( "" );
  164.                 $("#id_num_div ul li").text( "" );
  165.                 var mobileField = $('#appbundle_users_registration_mobileNumber');
  166.                 if (mobileField[0].checkValidity()) {
  167.                     // show remaining seconds count-down inside verification code button
  168.                     var counter = 30;
  169.                     var couterIntervalId = setInterval(function() {
  170.                         counter--;
  171.                         if (counter >= 0) {
  172.                             $('#send_verification_sms').prop('value', "{{ 'send verification' | trans({}, 'clients') }}"+' ('+counter+')');
  173.                         }
  174.                         if (counter === 0) {
  175.                             clearInterval(counter);
  176.                             $('#send_verification_sms').prop('value', "{{ 'send verification' | trans({}, 'clients') }}");
  177.                             btn.prop('disabled', false);
  178.                         }
  179.                     }, 1000); // end counter
  180.                     var mobileNumber = mobileField.val();
  181.                     var btn = $(this);
  182.                     check_ajax = false ;
  183.                     captchaPhrase = '{{ app.session.get('captchaPhrase') }}';
  184.                     btn.prop('disabled', true);
  185.                     var request = $.ajax({
  186.                         url:'{{ path('send_code_sms') }}',
  187.                         type: "POST",
  188.                         dataType: "json",
  189.                         data: {
  190.                             "mobileNumber": mobileNumber,
  191.                             "identification": $("#appbundle_users_registration_userIdentityInfo_identificationNumber").val(),
  192.                             "captchaPhrase": $("#userCaptcha").val()
  193.                     },
  194.                         async: true
  195.                     });
  196.                     request.done( function ( response ){
  197.                         // check SMS Delivery Status
  198.                         GetDeliveryStatus(response.mobileNumber,response.MessageID,couterIntervalId );
  199.                         $("#verification_code").css("display", "block");
  200.                         $("#register_btn").css("display", "block");
  201.                         $("#appbundle_users_registration_mobileNumber,#appbundle_users_registration_userIdentityInfo_identificationNumber,#userCaptcha").removeClass("red-bg");
  202.                         $(".errorCaptchaMsg").css("display",'none');
  203.                     });
  204.                     request.fail( function ( jqXHR ) {
  205.                         //create a validation message container for mobile number field if none exist
  206.                         if( $("#mobile_num_div ul li").length === 0){
  207.                             $("#mobile_num_div").append('<ul><li></li></ul>');
  208.                         }
  209.                         //create a validation message container for id number (username) field if none exist
  210.                         if( $("#id_num_div ul li").length === 0){
  211.                             $("#id_num_div").append('<ul><li></li></ul>');
  212.                         }
  213.                         var mobile_validation_container= $("#mobile_num_div ul li");
  214.                         var id_validation_container= $("#id_num_div ul li");
  215.                         if (jqXHR.responseText == "illegal access") {
  216.                             mobile_validation_container.text( "{{ 'illegal access' | trans({}, 'clients') }}" );
  217.                         }
  218.                         else if (jqXHR.responseText == "server error") {
  219.                             mobile_validation_container.text( "{{ 'server error' | trans({}, 'clients') }}" );
  220.                         }
  221.                         else if (jqXHR.responseText == "invalid mobile number") {
  222.                             mobile_validation_container.text( "{{ 'invalid mobile number' | trans({}, 'clients') }}" );
  223.                             $("#appbundle_users_registration_mobileNumber").addClass("red-bg");
  224.                         }
  225.                         else if (jqXHR.responseText == "mobile number already registered") {
  226.                             mobile_validation_container.html( "{{ 'mobile number already registered. click %{start_link}here%{end_link} to recover your password' | trans({'%{start_link}': '<a href=\'' ~ path("forgot_password") ~ '\'>', '%{end_link}': '</a>'}, 'clients')| raw }}" );
  227.                             $("#appbundle_users_registration_mobileNumber").addClass("red-bg");
  228.                         }
  229.                         else if (jqXHR.responseText == "identification number already registered") {
  230.                             id_validation_container.html( "{{ 'identification number already registered. click %{start_link}here%{end_link} to recover your password' | trans({'%{start_link}': '<a href=\'' ~ path("forgot_password") ~ '\'>', '%{end_link}': '</a>'}, 'clients')| raw }}" );
  231.                             $("#appbundle_users_registration_userIdentityInfo_identificationNumber").addClass("red-bg");
  232.                         }else if (jqXHR.responseText == "Error in captcha Phrase") {
  233.                             $(".errorCaptchaMsg").css("display",'block');
  234.                             $("#userCaptcha").addClass("red-bg");
  235.                         }
  236.                         else if (jqXHR.status == 403 || jqXHR.status == 404 ) {
  237.                             //handle other unexpected errors
  238.                             mobile_validation_container.text( "{{ 'error occured while sending verification code' | trans({}, 'clients') }}" );
  239.                         }
  240.                         clearInterval(couterIntervalId); //stop the send verification sms button counter
  241.                         $('#send_verification_sms').prop('value', "{{ 'send verification' | trans({}, 'clients') }}"); //reset send verification sms button label
  242.                         btn.prop('disabled', false);
  243.                     });
  244.                 } else {
  245.                     var msg = mobileField.attr('validate-msg');
  246.                     mobileField[0].reportValidity(msg);
  247.                 }
  248.             });
  249.         });
  250.         function GetDeliveryStatus(mobileNumber,MessageID,couterIntervalId) {
  251.             $.ajax({
  252.                 url: '{{ path('get_sms_status') }}',
  253.                 type: "POST",
  254.                 dataType: "json",
  255.                 data: {
  256.                     "mobileNumber": mobileNumber,
  257.                     "MessageID"   : MessageID,
  258.                 },
  259.                 success: function(result)
  260.                 {
  261.                     if(result == false){
  262.                         setTimeout(function(){
  263.                             GetDeliveryStatus(mobileNumber,MessageID,couterIntervalId)
  264.                         }, 3000);
  265.                     }else {
  266.                         clearInterval(couterIntervalId); //stop the send verification sms button counter
  267.                         $('#send_verification_sms').prop('value', "{{ 'verification code sent' | trans({}, 'clients') }}"); //set new label for send verification sms button
  268.                     }
  269.                 },
  270.                 error: function(jqXHR) {
  271.                     //create a validation container for mobile number field if none exist
  272.                     if( $("#mobile_num_div ul li").length === 0){
  273.                         $("#mobile_num_div").append('<ul><li></li></ul>');
  274.                     }
  275.                     var mobile_validation_container= $("#mobile_num_div ul li");
  276.                     if (jqXHR.responseText == "invalid mobile number") {
  277.                         mobile_validation_container.text( "{{ 'invalid mobile number' | trans({}, 'clients') }}" );
  278.                         clearInterval(couterIntervalId); //stop the send verification sms button counter
  279.                         $('#send_verification_sms').prop('value', "{{ 'send verification' | trans({}, 'clients') }}"); //reset send verification sms button label
  280.                         btn.prop('disabled', false);
  281.                     }
  282.                     else if (jqXHR.responseText == "sms not delivered") {
  283.                         mobile_validation_container.text( "{{ 'sms not delivered' | trans({}, 'clients') }}" );
  284.                     }
  285.                     clearInterval(couterIntervalId); //stop the send verification sms button counter
  286.                     $('#send_verification_sms').prop('value', "{{ 'send verification' | trans({}, 'clients') }}"); //reset send verification sms button label
  287.                     btn.prop('disabled', false);
  288.                 }
  289.             });
  290.         }
  291.         $('#refresh').click(function() {
  292.             $.ajax({
  293.                 url:'{{ (path('get_captcha_ajax')) }}',
  294.                 type: "POST",
  295.                 dataType: "json",
  296.                 async: true,
  297.                 success: function (data)
  298.                 {
  299.                   $("#captcha").attr('src',data.builder);
  300.                 }
  301.             });
  302.         });
  303.     </script>
  304. {% endblock %}