Commit 6cee467c2475ddb082382416859e21fa7fb850b3
1 parent
b29e7d78
Exists in
theme-brasil-digital-from-staging
and in
7 other branches
api: method to resend activation code
Showing
2 changed files
with
29 additions
and
0 deletions
Show diff stats
lib/noosfero/api/session.rb
| @@ -128,6 +128,24 @@ module Noosfero | @@ -128,6 +128,24 @@ module Noosfero | ||
| 128 | end | 128 | end |
| 129 | end | 129 | end |
| 130 | 130 | ||
| 131 | + # Resend activation code. | ||
| 132 | + # | ||
| 133 | + # Parameters: | ||
| 134 | + # value (required) - Email or login | ||
| 135 | + # Example Request: | ||
| 136 | + # POST /resend_activation_code?value=some@mail.com | ||
| 137 | + post "/resend_activation_code" do | ||
| 138 | + requestors = fetch_requestors(params[:value]) | ||
| 139 | + not_found! if requestors.blank? | ||
| 140 | + remote_ip = (request.respond_to?(:remote_ip) && request.remote_ip) || (env && env['REMOTE_ADDR']) | ||
| 141 | + # test_captcha will render_api_error! and exit in case of any problem | ||
| 142 | + # this return is just to improve the clarity of the execution path | ||
| 143 | + return unless test_captcha(remote_ip, params, environment) | ||
| 144 | + requestors.each do |requestor| | ||
| 145 | + requestor.user.resend_activation_code | ||
| 146 | + end | ||
| 147 | + end | ||
| 148 | + | ||
| 131 | params do | 149 | params do |
| 132 | requires :code, type: String, desc: _("Forgot password code") | 150 | requires :code, type: String, desc: _("Forgot password code") |
| 133 | end | 151 | end |
test/unit/api/session_test.rb
| @@ -210,4 +210,15 @@ class SessionTest < ActiveSupport::TestCase | @@ -210,4 +210,15 @@ class SessionTest < ActiveSupport::TestCase | ||
| 210 | assert !json['user']['private_token'].present? | 210 | assert !json['user']['private_token'].present? |
| 211 | end | 211 | end |
| 212 | 212 | ||
| 213 | + should 'resend activation code for an inactive user' do | ||
| 214 | + user = create_user | ||
| 215 | + params = {:value => user.login} | ||
| 216 | + Delayed::Job.destroy_all | ||
| 217 | + assert_difference 'ActionMailer::Base.deliveries.size' do | ||
| 218 | + post "/api/v1/resend_activation_code?#{params.to_query}" | ||
| 219 | + process_delayed_job_queue | ||
| 220 | + end | ||
| 221 | + assert_equal user.email, ActionMailer::Base.deliveries.last['to'].to_s | ||
| 222 | + end | ||
| 223 | + | ||
| 213 | end | 224 | end |