diff --git a/app/api/mobile/apis/auth.rb b/app/api/mobile/apis/auth.rb index 33eff26ad..fa6fec6e2 100644 --- a/app/api/mobile/apis/auth.rb +++ b/app/api/mobile/apis/auth.rb @@ -20,8 +20,8 @@ module Mobile if user ::ApiKey.delete_all(user_id: user.id) key = ::ApiKey.create!(user_id: user.id) - api_user = UserService.new.show_user(user.id) - present :data, {token: key, user: api_user}, using: Mobile:Entities::Auth + api_user = ::UsersService.new.show_user({id:user.id}) + present :data, {token: key.access_token, user: api_user}, using: Entities::Auth present :status, 0 else {status: 1, message: 'Unauthorized.'} diff --git a/app/api/mobile/entities/user.rb b/app/api/mobile/entities/user.rb index 33ae3f049..38230b7a0 100644 --- a/app/api/mobile/entities/user.rb +++ b/app/api/mobile/entities/user.rb @@ -1,19 +1,22 @@ module Mobile module Entities class User < Grape::Entity + expose :id #头像 + expose :img_url #昵称 - expose :login + expose :nickname #性别 - expose :gender do |user, opt| - user.user_extentions.gender - end + expose :gender #我的二维码 #工作单位 + expose :work_unit #邮箱地址 expose :mail #地区 + expose :location #签名 + expose :brief_introduction end end diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 3579b8a87..17ecc1598 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -39,10 +39,10 @@ class UsersService #显示用户 #id用户id - def show_user + def show_user(params) @user = User.find(params[:id]) img_url = url_to_avatar(@user) - gender = user.user_extensions.gender.nil? ? 0 : user.user_extensions.gender + gender = @user.user_extensions.gender.nil? ? 0 : @user.user_extensions.gender work_unit = "" if @user.user_extensions.identity == 0 || @user.user_extensions.identity == 1 work_unit = @user.user_extensions.school.name unless @user.user_extensions.school.nil? @@ -52,8 +52,8 @@ class UsersService work_unit = @user.firstname end location = "" - location << @user.user_extensions.location - location << @user.user_extensions.location_city + location << (@user.user_extensions.location || '') + location << (@user.user_extensions.location_city || '') {:id => @user.id,:img_url =>img_url,:nickname => @user.login,:gender => gender,:work_unit => work_unit,:mail => @user.mail,:location => location,:brief_introduction => @user.user_extensions.brief_introduction} end