我想知道是否有任何帳戶恢復寶石的Rails密碼的紅寶石,允許應用程序發送用戶到他的短信一針以重置其密碼在用戶忘記它的事件?谷歌搜索,但沒有看到任何東西,我想在這裏問我的谷歌搜索字符串只是寫得不好。是否有任何使用SMS的軌道上的紅寶石帳戶恢復寶石?
ruby on rails account recovery via sms
我想知道是否有任何帳戶恢復寶石的Rails密碼的紅寶石,允許應用程序發送用戶到他的短信一針以重置其密碼在用戶忘記它的事件?谷歌搜索,但沒有看到任何東西,我想在這裏問我的谷歌搜索字符串只是寫得不好。是否有任何使用SMS的軌道上的紅寶石帳戶恢復寶石?
ruby on rails account recovery via sms
不,我直接察覺,但https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=sms給出了短信互動一些寶石。
這是我看起來的第一個地方之一,以及直接在github.com上搜索。 RubyForge是查找寶石的另一個很好的信息來源。
https://rubyforge.org/search/?type_of_search=soft&words=sms&Search=Search
我不知道任何寶石的,但是這聽起來像的東西,不會是非常難以實現。正如vgoff所說,有很多短信服務可供您使用。
沿(沒有測試)東西線:
class SMSReset < ActiveRecord::Base
TOKEN_LENGTH = 4
EXPIRY_TIME = 15.minutes
belongs_to :user
before_create :generate_token, :set_expiry
def dispatch_sms!
MySMSProvider.send_sms(to: user.mobile_number, body: "Your SMS token is: #{token}")
end
def has_not_expired?
expires_at > Time.now
end
private
def generate_token
self[:token] = SecureRandom.hex[0..TOKEN_LENGTH - 1].downcase
end
def set_expiry
self[:expires_at] = EXPIRY_TIME.from_now
end
end
class PasswordResetController < ApplicationController
def new
end
def create
@user = User.where(email: params[:email]).first
if @user
sms_reset = @user.create_sms_reset!
sms_reset.dispatch_sms!
flash.now[:success] = "Please enter the code that was sent to your phone in the field below"
else
flash.now[:error] = "No user was found by that email address"
render :new
end
end
def validate_token
sms_reset = SMSReset.where(user_id: params[:user_id], token: params[:token])
if sms_reset.present? && sms_reset.has_not_expired?
@user = sms_reset.user
render :password_reset_form
else
flash.now[:error] = "Sorry, that code wasn't recognized"
render :new
end
end
end
你要處理錯誤,並有改進的餘地,但希望主旨是有道理的。
這確實是。我不是一個Rails大師,所以有一些腿部工作要走,但這裏的想法似乎很紮實。我正在和Devise和Cancan合作。我喜歡MySMSProvider :)對於高質量的任何好建議?我正在考慮http://www.twilio.com/ – Codejoy
@Codejoy根據我的經驗,它們大都可以互換。您可以花費很少的精力抽象出您正在使用的提供商。去Twilio,看看它是如何爲你工作的。 – Aupajo