Commit 6c26a4a9fc8b172a651288010bb47778602c8be9
1 parent
fec92470
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
api: fix user registration
Showing
2 changed files
with
7 additions
and
8 deletions
Show diff stats
lib/noosfero/api/session.rb
@@ -45,16 +45,14 @@ module Noosfero | @@ -45,16 +45,14 @@ module Noosfero | ||
45 | # test_captcha will render_api_error! and exit in case of any problem | 45 | # test_captcha will render_api_error! and exit in case of any problem |
46 | # this return is just to improve the clarity of the execution path | 46 | # this return is just to improve the clarity of the execution path |
47 | return unless test_captcha(remote_ip, params, environment) | 47 | return unless test_captcha(remote_ip, params, environment) |
48 | - user = User.new(attrs) | ||
49 | - params[:name].present? ? name = params[:name] : name = attrs[:email] | ||
50 | - person = Person.new(name: name, identifier: user.login) | ||
51 | - user.person = person | ||
52 | - if user.signup | 48 | + name = params[:name].present? ? params[:name] : attrs[:email] |
49 | + user = User.new(attrs.merge(:name => name)) | ||
50 | + if user.signup! | ||
53 | user.generate_private_token! if user.activated? | 51 | user.generate_private_token! if user.activated? |
54 | present user, :with => Entities::UserLogin | 52 | present user, :with => Entities::UserLogin |
55 | else | 53 | else |
56 | user.destroy | 54 | user.destroy |
57 | - message = user.errors.as_json.merge(person.errors.as_json).to_json | 55 | + message = user.errors.as_json.merge(user.person.errors.as_json).to_json |
58 | render_api_error!(message, 400) | 56 | render_api_error!(message, 400) |
59 | end | 57 | end |
60 | end | 58 | end |
test/unit/api/session_test.rb
@@ -26,8 +26,9 @@ class SessionTest < ActiveSupport::TestCase | @@ -26,8 +26,9 @@ class SessionTest < ActiveSupport::TestCase | ||
26 | post "/api/v1/register?#{params.to_query}" | 26 | post "/api/v1/register?#{params.to_query}" |
27 | assert_equal 201, last_response.status | 27 | assert_equal 201, last_response.status |
28 | json = JSON.parse(last_response.body) | 28 | json = JSON.parse(last_response.body) |
29 | - assert json['activated'] | ||
30 | - assert json['private_token'].present? | 29 | + assert User['newuserapi'].activated? |
30 | + assert json['user']['activated'] | ||
31 | + assert json['user']['private_token'].present? | ||
31 | end | 32 | end |
32 | 33 | ||
33 | should 'register a user with name' do | 34 | should 'register a user with name' do |