A
A
Askhat Bikmetov2014-05-10 20:37:50
ruby
Askhat Bikmetov, 2014-05-10 20:37:50

How to implement SMS-confirmation of registration?

The site is built on Sintra and the actions have the following code:

post '/registration/sms/:number' do
  code = Random.rand(1111..9999).to_s
  phone = params[:phone].to_s
  HTTParty.get('http://sms.ru/sms/send?api_id=' + api_id +'&to=' + phone + '&text=' + code)
  # check code
end

And such a twist:
%form{:method => "post"}
  %div.form-group
    %label Телефон
    %input#phone.form-control{:name => "phone", :placeholder => "7 950 123 45 67"}
    %p.help-block Введите доступный Вам номер, на него будет отправлен код активации
  %div.checkbox
  %button#sendsms.btn.btn-default{"data-toggle" => "modal", "data-target" => "#myModal"} Отправить

With this JavaScript:
$("#sendsms").click(function(){
  var phone = $("#phone").value();
  $.ajax({
    url: "/registration/sms",
    data: {"phone": phone},
    type: "post"
  })
})

According to my understanding, JS should send a post request to /registration/sms with the phone parameter , which, being processed by the action, creates a new request to sms.ru , which actually sends sms. However, this does not happen and I have no idea how to make it work.
Thanks in advance for any help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Askhat Bikmetov, 2014-05-11
@askhat

The action doesn't need a :number parameter , so it should look like this:

post '/registration/sms' do
  # code..
end

You also need to fix the assignment to the phone variable in JS, like this:
var phone = $("#phone").val();

E
Eugene Obrezkov, 2014-05-10
@ghaiklor

The first thing that catches your eye:
Receive via this route - post '/registration/sms/:number' do
And send via another url: "/coop/sms".
Without debugging, we will not help. There can be many reasons: the SMS-ok apish hangs, the parameters do not come on the backend, the parameters do not take on the frontend.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question