Class: CustomerServiceIm::UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/customer_service_im/users_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#render_200, #render_401, #render_422, #render_500

Instance Method Details

#loginObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/customer_service_im/users_controller.rb', line 4

def 
  mp = MiniProgram::Client.new(appid: CustomerServiceIm.appid, app_secret: CustomerServiceIm.app_secret )
  result = mp.(params.require(:code))

  if result.failure?
    render_500 errors: result.errors
  end

  open_id = result.data[:openid]

  user = User.find_or_create_mp_user(open_id)

  render_200 user.as_json.merge({ token: token_user(user), conversation_id: user.conversation_ids.first })
end

#updateObject



19
20
21
22
23
24
25
26
# File 'app/controllers/customer_service_im/users_controller.rb', line 19

def update
  user = logged_user
  if user.update(user_params)
    render_200  result: :ok
  else
    render_500 errors: user.errors
  end
end