devise_phone 0.0.1662 → 0.0.1663
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/devise/phone_verifications_controller.rb +26 -16
- data/app/views/devise/phone/_activate_phone.html.erb +1 -1
- data/app/views/devise/phone/_resend_code.html.erb +1 -1
- data/lib/devise_phone/routes.rb +2 -2
- data/lib/devise_phone/version.rb +1 -1
- data/lib/models/phone.rb +27 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa23d1176a07078e34df9bc26d23abf25f3aadb8
|
4
|
+
data.tar.gz: 810341f073168f9a0eec605c52b491c33adaaa0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0ddc5397e5d6f53c93682e028479c83001e75d626806f67a3ea943a476b4ebc67f0476b36cbf057626e4c61a97368b34c3e46184f0cd3a8fcfded3dbff14c3d
|
7
|
+
data.tar.gz: 43a835f4e774d7b1aba4ba499a7d7cb3117d57336e589e839f4145da3ecdb0d437a90bb6f01eaf2b142281f64af83c3ebce578c09bc1ba93e74607f55ad9a54e
|
@@ -1,28 +1,38 @@
|
|
1
1
|
class Devise::PhoneVerificationsController < DeviseController
|
2
2
|
|
3
3
|
# GET /resource/phone_verification/new
|
4
|
-
def new
|
5
|
-
|
6
|
-
|
7
|
-
end
|
4
|
+
# def new
|
5
|
+
# build_resource({})
|
6
|
+
# render :new
|
7
|
+
# end
|
8
8
|
|
9
9
|
# POST /resource/phone_verification
|
10
|
-
def create
|
11
|
-
end
|
10
|
+
# def create
|
11
|
+
# end
|
12
12
|
|
13
|
-
# GET /resource/phone_verification/
|
14
|
-
def
|
13
|
+
# GET /resource/phone_verification/send_code
|
14
|
+
def send_code
|
15
15
|
current_user.generate_verification_code_and_send_sms
|
16
|
-
|
17
|
-
|
16
|
+
# render nothing: true
|
17
|
+
respond_to do |format|
|
18
|
+
msg = { :status => "ok", :message => "SMS sent!" }
|
19
|
+
format.json { render :json => msg } # don't do msg.to_json
|
20
|
+
end
|
18
21
|
end
|
19
22
|
|
20
|
-
# GET or POST /resource/phone_verification/
|
21
|
-
def
|
22
|
-
current_user.verify_phone_number_with_code_entered(params[:code_entered])
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
# GET or POST /resource/phone_verification/verify_code
|
24
|
+
def verify_code
|
25
|
+
verify_success = current_user.verify_phone_number_with_code_entered(params[:code_entered])
|
26
|
+
# render nothing: true
|
27
|
+
respond_to do |format|
|
28
|
+
if verify_success
|
29
|
+
message_response = "verification successful"
|
30
|
+
else
|
31
|
+
message_response = "verification fail"
|
32
|
+
end
|
33
|
+
msg = { :status => "ok", :message => message_response }
|
34
|
+
format.json { render :json => msg } # don't do msg.to_json
|
35
|
+
end
|
26
36
|
end
|
27
37
|
|
28
38
|
protected
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= form_for(resource, :as => resource_name, :url =>
|
1
|
+
<%= form_for(resource, :as => resource_name, :url => verify_code_user_phone_verification_path(resource_name), :html => { :method => :post }, remote: true) do |f| %>
|
2
2
|
|
3
3
|
<p><%=label_tag :code_entered %><br />
|
4
4
|
<%=text_field_tag :code_entered, "" %></p>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= form_for(resource, :as => resource_name, :url =>
|
1
|
+
<%= form_for(resource, :as => resource_name, :url => send_code_user_phone_verification_path(resource_name), :html => { :method => :get }, remote: true) do |f| %>
|
2
2
|
<%= devise_error_messages! %>
|
3
3
|
|
4
4
|
<%= f.submit "Resend Phone Verification Code" %>
|
data/lib/devise_phone/routes.rb
CHANGED
@@ -4,8 +4,8 @@ module ActionDispatch::Routing
|
|
4
4
|
protected
|
5
5
|
def devise_phone_verification(mapping, controllers)
|
6
6
|
resource :phone_verification, :only => [:new, :create], :path => mapping.path_names[:phone_verification], :controller => controllers[:phone_verifications] do
|
7
|
-
post :
|
8
|
-
get :
|
7
|
+
post :verify_code, :path => mapping.path_names[:verify_code], :as => :verify_code
|
8
|
+
get :send_code, :path => mapping.path_names[:send_code], :as => :send_code
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
data/lib/devise_phone/version.rb
CHANGED
data/lib/models/phone.rb
CHANGED
@@ -31,9 +31,9 @@ module Devise
|
|
31
31
|
|
32
32
|
included do
|
33
33
|
before_create :set_unverified_phone_attributes, :if => :phone_verification_needed?
|
34
|
-
after_create :private_generate_verification_code_and_send_sms, :if => :phone_verification_needed?
|
34
|
+
# after_create :private_generate_verification_code_and_send_sms, :if => :phone_verification_needed?
|
35
35
|
# before_save :remember_old_phone_number
|
36
|
-
|
36
|
+
after_save :private_generate_verification_code_and_send_sms, :if => :regenerate_phone_verification_needed?
|
37
37
|
end
|
38
38
|
|
39
39
|
def generate_verification_code_and_send_sms
|
@@ -45,7 +45,10 @@ module Devise
|
|
45
45
|
|
46
46
|
def verify_phone_number_with_code_entered(code_entered)
|
47
47
|
if phone_verification_needed? && (code_entered == self.phone_verification_code)
|
48
|
-
|
48
|
+
mark_phone_as_verified!
|
49
|
+
true
|
50
|
+
else
|
51
|
+
false
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
@@ -108,6 +111,23 @@ module Devise
|
|
108
111
|
end
|
109
112
|
end
|
110
113
|
|
114
|
+
def regenerate_phone_verification_needed?
|
115
|
+
if phone_number.present?
|
116
|
+
if phone_number_changed?
|
117
|
+
# puts "condition 1"
|
118
|
+
true
|
119
|
+
else
|
120
|
+
# puts "condition 2"
|
121
|
+
false
|
122
|
+
end
|
123
|
+
# self.errors.add(:phone_verification_code, :empty_phone_number_field)
|
124
|
+
# false
|
125
|
+
else
|
126
|
+
# puts "condition 3"
|
127
|
+
false
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
111
131
|
# set attributes to user indicating the phone number is unverified
|
112
132
|
def set_unverified_phone_attributes
|
113
133
|
self.phone_number_verified = false
|
@@ -130,13 +150,13 @@ module Devise
|
|
130
150
|
number_to_send_to = self.phone_number
|
131
151
|
verification_code = self.phone_verification_code
|
132
152
|
|
133
|
-
twilio_sid = Rails.application.
|
134
|
-
twilio_token = Rails.application.
|
135
|
-
twilio_phone_number = Rails.application.
|
153
|
+
twilio_sid = Rails.application.config.twilio[:sid]
|
154
|
+
twilio_token = Rails.application.config.twilio[:token]
|
155
|
+
twilio_phone_number = Rails.application.config.twilio[:phone_number]
|
136
156
|
|
137
157
|
@twilio_client = Twilio::REST::Client.new twilio_sid, twilio_token
|
138
158
|
|
139
|
-
@twilio_client.account.
|
159
|
+
@twilio_client.account.messages.create(
|
140
160
|
:from => "+1#{twilio_phone_number}",
|
141
161
|
:to => number_to_send_to,
|
142
162
|
:body => "Hi! This is MathCrunch. Your verification code is #{verification_code}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_phone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1663
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hubert Theodore
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|