73 lines
2.2 KiB
Ruby
73 lines
2.2 KiB
Ruby
#coding=utf-8
|
|
module Mobile
|
|
module Apis
|
|
class Users < Grape::API
|
|
resource :users do
|
|
|
|
desc "注册用户"
|
|
params do
|
|
requires :login, type: String, desc: 'username'
|
|
requires :mail, type: String, desc: 'mail'
|
|
requires :password, type: String, desc: 'password'
|
|
end
|
|
post do
|
|
us = UsersService.new
|
|
user = us.register params.merge(:password_confirmation => params[:password],
|
|
:should_confirmation_password => true)
|
|
raise "register failed #{user.errors.full_messages}" if user.new_record?
|
|
present :data, user, with: Mobile::Entities::User
|
|
present :status, 0
|
|
end
|
|
|
|
|
|
desc "修改用户"
|
|
params do
|
|
requires :token, type: String
|
|
#optional :file, type: File, desc: 'avatar'
|
|
optional :occupation, type: String
|
|
optional :brief_introduction, type: String
|
|
optional :province, type: String
|
|
optional :city, type: String
|
|
optional :gender, type: Integer
|
|
end
|
|
put ':id' do
|
|
authenticate!
|
|
us = UsersService.new
|
|
ue = us.edit_user params.merge(id: current_user.id)
|
|
present :data, user, with: Mobile::Entities::User
|
|
present :status, 0
|
|
end
|
|
|
|
|
|
desc '修改密码'
|
|
params do
|
|
requires :token, type: String
|
|
requires :password, type:String , desc: '原密码'
|
|
requires :new_password, type: String, desc: '新密码'
|
|
end
|
|
post 'password' do
|
|
authenticate!
|
|
us = UsersService.new
|
|
ue = us.change_password params.merge(new_password_confirmation: params[:new_password])
|
|
present :data, user, with: Mobile::Entities::User
|
|
present :status, 0
|
|
end
|
|
|
|
desc "用户搜索"
|
|
params do
|
|
requires :name, type: String, desc: '用户名关键字'
|
|
end
|
|
get 'search' do
|
|
us = UsersService.new
|
|
user = us.search_user params
|
|
present :data, user, with: Mobile::Entities::User
|
|
present :status, 0
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|