Commit 1bbcf76f0d220316b6abd62557ea879d958e7c18
1 parent
a8028635
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
refactor of register
Showing
1 changed file
with
9 additions
and
20 deletions
Show diff stats
lib/noosfero/api/session.rb
| ... | ... | @@ -43,27 +43,16 @@ module Noosfero |
| 43 | 43 | # this return is just to improve the clarity of the execution path |
| 44 | 44 | return unless test_captcha(remote_ip, params, environment) |
| 45 | 45 | user = User.new(attrs) |
| 46 | - if params[:name].present? | |
| 47 | - #adds user and person | |
| 48 | - person = Person.new(name: params[:name], identifier: user.login) | |
| 49 | - user.person = person | |
| 50 | - if user.signup | |
| 51 | - user.generate_private_token! if user.activated? | |
| 52 | - present user, :with => Entities::UserLogin | |
| 53 | - else | |
| 54 | - user.destroy | |
| 55 | - message = user.errors.as_json.merge(person.errors.as_json).to_json | |
| 56 | - render_api_error!(message, 400) | |
| 57 | - end | |
| 46 | + params[:name].present? ? name = params[:name] : name = attrs[:email] | |
| 47 | + person = Person.new(name: name, identifier: user.login) | |
| 48 | + user.person = person | |
| 49 | + if user.signup | |
| 50 | + user.generate_private_token! if user.activated? | |
| 51 | + present user, :with => Entities::UserLogin | |
| 58 | 52 | else |
| 59 | - #adds user only | |
| 60 | - if user.save | |
| 61 | - user.generate_private_token! if user.activated? | |
| 62 | - present user, :with => Entities::UserLogin | |
| 63 | - else | |
| 64 | - message = user.errors.to_json | |
| 65 | - render_api_error!(message, 400) | |
| 66 | - end | |
| 53 | + user.destroy | |
| 54 | + message = user.errors.as_json.merge(person.errors.as_json).to_json | |
| 55 | + render_api_error!(message, 400) | |
| 67 | 56 | end |
| 68 | 57 | end |
| 69 | 58 | ... | ... |