登录后返回用户资料
This commit is contained in:
parent
dbb46b07a6
commit
c054852b4e
|
@ -20,8 +20,8 @@ module Mobile
|
||||||
if user
|
if user
|
||||||
::ApiKey.delete_all(user_id: user.id)
|
::ApiKey.delete_all(user_id: user.id)
|
||||||
key = ::ApiKey.create!(user_id: user.id)
|
key = ::ApiKey.create!(user_id: user.id)
|
||||||
api_user = UserService.new.show_user(user.id)
|
api_user = ::UsersService.new.show_user({id:user.id})
|
||||||
present :data, {token: key, user: api_user}, using: Mobile:Entities::Auth
|
present :data, {token: key.access_token, user: api_user}, using: Entities::Auth
|
||||||
present :status, 0
|
present :status, 0
|
||||||
else
|
else
|
||||||
{status: 1, message: 'Unauthorized.'}
|
{status: 1, message: 'Unauthorized.'}
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
module Mobile
|
module Mobile
|
||||||
module Entities
|
module Entities
|
||||||
class User < Grape::Entity
|
class User < Grape::Entity
|
||||||
|
expose :id
|
||||||
#头像
|
#头像
|
||||||
|
expose :img_url
|
||||||
#昵称
|
#昵称
|
||||||
expose :login
|
expose :nickname
|
||||||
#性别
|
#性别
|
||||||
expose :gender do |user, opt|
|
expose :gender
|
||||||
user.user_extentions.gender
|
|
||||||
end
|
|
||||||
#我的二维码
|
#我的二维码
|
||||||
#工作单位
|
#工作单位
|
||||||
|
expose :work_unit
|
||||||
#邮箱地址
|
#邮箱地址
|
||||||
expose :mail
|
expose :mail
|
||||||
#地区
|
#地区
|
||||||
|
expose :location
|
||||||
#签名
|
#签名
|
||||||
|
expose :brief_introduction
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -39,10 +39,10 @@ class UsersService
|
||||||
|
|
||||||
#显示用户
|
#显示用户
|
||||||
#id用户id
|
#id用户id
|
||||||
def show_user
|
def show_user(params)
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
img_url = url_to_avatar(@user)
|
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 = ""
|
work_unit = ""
|
||||||
if @user.user_extensions.identity == 0 || @user.user_extensions.identity == 1
|
if @user.user_extensions.identity == 0 || @user.user_extensions.identity == 1
|
||||||
work_unit = @user.user_extensions.school.name unless @user.user_extensions.school.nil?
|
work_unit = @user.user_extensions.school.name unless @user.user_extensions.school.nil?
|
||||||
|
@ -52,8 +52,8 @@ class UsersService
|
||||||
work_unit = @user.firstname
|
work_unit = @user.firstname
|
||||||
end
|
end
|
||||||
location = ""
|
location = ""
|
||||||
location << @user.user_extensions.location
|
location << (@user.user_extensions.location || '')
|
||||||
location << @user.user_extensions.location_city
|
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}
|
{: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
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue