Commit 524373dba6e746bce012b57f7a0752ae09ebe451
1 parent
cebdccf8
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Needs to be compatible with older versions
Showing
3 changed files
with
14 additions
and
4 deletions
Show diff stats
app/models/user.rb
@@ -94,6 +94,12 @@ class User < ActiveRecord::Base | @@ -94,6 +94,12 @@ class User < ActiveRecord::Base | ||
94 | end | 94 | end |
95 | end | 95 | end |
96 | 96 | ||
97 | + def signup | ||
98 | + User.transaction do | ||
99 | + self.person.save if self.save | ||
100 | + end | ||
101 | + end | ||
102 | + | ||
97 | has_one :person, :dependent => :destroy | 103 | has_one :person, :dependent => :destroy |
98 | belongs_to :environment | 104 | belongs_to :environment |
99 | 105 |
lib/noosfero/api/entities.rb
@@ -112,6 +112,7 @@ module Noosfero | @@ -112,6 +112,7 @@ module Noosfero | ||
112 | root 'users', 'user' | 112 | root 'users', 'user' |
113 | expose :id | 113 | expose :id |
114 | expose :login | 114 | expose :login |
115 | + expose :email | ||
115 | expose :person, :using => Profile | 116 | expose :person, :using => Profile |
116 | expose :activated?, as: :activated | 117 | expose :activated?, as: :activated |
117 | expose :permissions do |user, options| | 118 | expose :permissions do |user, options| |
lib/noosfero/api/session.rb
@@ -43,11 +43,14 @@ module Noosfero | @@ -43,11 +43,14 @@ module Noosfero | ||
43 | # this return is just to improve the clarity of the execution path | 43 | # this return is just to improve the clarity of the execution path |
44 | return unless test_captcha(remote_ip, params, environment) | 44 | return unless test_captcha(remote_ip, params, environment) |
45 | user = User.new(attrs) | 45 | user = User.new(attrs) |
46 | - if user.save | ||
47 | - user.generate_private_token! if user.activated? | ||
48 | - present user, :with => Entities::UserLogin | 46 | + person = Person.new(name: params[:name], identifier: user.login) |
47 | + user.person = person | ||
48 | + if user.signup | ||
49 | + user.generate_private_token! if user.activated? | ||
50 | + present user, :with => Entities::UserLogin | ||
49 | else | 51 | else |
50 | - message = user.errors.to_json | 52 | + user.destroy |
53 | + message = user.errors.as_json.merge(person.errors.as_json).to_json | ||
51 | render_api_error!(message, 400) | 54 | render_api_error!(message, 400) |
52 | end | 55 | end |
53 | end | 56 | end |