From 4214f39bae44b85595ec3f0c253a7df68cc1094f Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Thu, 4 Dec 2014 10:11:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B3=A8=E5=86=8Capi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/users.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 8b7edd155..33ea075a7 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -5,6 +5,7 @@ module Mobile get do ['hello'] end + desc "add a user" params do requires :login, type: String, desc: 'username' @@ -12,16 +13,13 @@ module Mobile requires :password, type: String, desc: 'password' end post do - user = User.new - user.login = params[:login] - user.mail = params[:mail] - user.password = params[:password] - user.password_confirmation = params[:password] - user.activate - if user.save! - UserStatus.create(:user_id => user.id, :changsets_course => 0, :watchers_count => 0) + user_service = UsersService.new + begin + user = user_service.register(params) + {status: 0, data: user} + rescue Exception => e + {status: 1, message: e.message} end - user end end end