登录后返回用户资料
This commit is contained in:
parent
dbb46b07a6
commit
c054852b4e
|
@ -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.'}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue