Files
snpr/app/controllers/open_humans_profiles_controller.rb
Bastian Greshake Tzovaras 7d0382b93c Integrate Open Humans, remove Fitbit (closes #392)
* adds Open Humans connection (incl. at least some tests)
* removes the capability to add fitbit data (was broken in any case)
* display current fitbit data is still included, will be removed after grace period (needs to be announced to users)
2017-11-21 09:32:45 -08:00

38 lines
1.2 KiB
Ruby

# frozen_string_literal: true
class OpenHumansProfilesController < ApplicationController
before_action :require_user, except: [:index]
def index
@oh_profiles = OpenHumansProfile
.includes(:user)
.order(created_at: :desc)
.paginate(page: params[:page], per_page: 15)
@user = current_user if current_user
end
def start_auth
# there's little to do for the start. Just read the .env for our client_id
# then lead ppl to OH.org to give us a key
client_id = ENV.fetch('OH_CLIENT_ID')
base_url = 'https://www.openhumans.org/direct-sharing/projects/oauth2/authorize/?client_id='
redirect_to base_url + "#{client_id}&response_type=code"
end
def authorize
# let's get the current user and their code
user = current_user
oh_service = OpenHumansService.new(user)
oh_service.authenticate(params[:code])
flash[:achievement] = 'Connected your account to Open Humans'
redirect_to user
end
def destroy
oh_profile = current_user.open_humans_profile
oh_profile.delete
flash[:notice] = 'Your Open Humans connection was deleted.'
redirect_to current_user
end
end