[Git][noosfero/noosfero][master] 2 commits: Added API method to change user password
Victor Costa
gitlab at mg.gitlab.com
Mon Apr 3 11:12:51 BRT 2017
Victor Costa pushed to branch master at Noosfero / noosfero
Commits:
798c5ceb by Josafá Souza Jr at 2017-04-03T14:12:37+00:00
Added API method to change user password
- - - - -
8389449f by Victor Costa at 2017-04-03T14:12:38+00:00
Merge branch 'change-password-api' into 'master'
Added API method to change user password
See merge request !1158
- - - - -
2 changed files:
- app/api/v1/users.rb
- test/api/users_test.rb
Changes:
=====================================
app/api/v1/users.rb
=====================================
--- a/app/api/v1/users.rb
+++ b/app/api/v1/users.rb
@@ -36,6 +36,19 @@ module Api
present output
end
+ patch ":id" do
+ authenticate!
+ begin
+ current_person.user.change_password!(params[:current_password],
+ params[:new_password],
+ params[:new_password_confirmation])
+ present({ success: true })
+ rescue Exception
+ render_api_error!(current_person.user.errors.details, Api::Status::BAD_REQUEST)
+ end
+
+ end
+
end
end
=====================================
test/api/users_test.rb
=====================================
--- a/test/api/users_test.rb
+++ b/test/api/users_test.rb
@@ -137,4 +137,14 @@ class UsersTest < ActiveSupport::TestCase
refute json.has_key?("activated")
end
+ should 'change password successfully' do
+ login_api
+ params[:current_password] = 'testapi';
+ params[:new_password] = 'USER_NEW_PASSWORD';
+ params[:new_password_confirmation] = 'USER_NEW_PASSWORD';
+ patch "/api/v1/users/#{user.id}?#{params.to_query}"
+ json = JSON.parse(last_response.body)
+ assert json['success'], true
+ end
+
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/03cf8bac6447dafbab90f31ebaa3b110a5ab9c35...8389449fafb93b0eb067277d811ff16f96df2bd1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170403/bb88b933/attachment-0001.html>
More information about the Noosfero-dev
mailing list