mirror of
https://github.com/chenasraf/snpr.git
synced 2026-05-18 01:39:01 +00:00
* 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)
38 lines
1.2 KiB
Ruby
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
|