Sha256: c259e15c737b4d9ad1e01a5895354cafd314c938b3f50f39aefc7502e5b9fb1c
Contents?: true
Size: 1.08 KB
Versions: 26
Compression:
Stored size: 1.08 KB
Contents
require_dependency "writefully/application_controller" module Writefully class SessionsController < ApplicationController def new @github_app = Writefully.github_app end def create @auth = Writefully.github_app.get_token(params[:code]) @github = Github.new oauth_token: @auth.token @github_user = @github.users.get @owner = find_or_create_owner refresh_token session[:wf_authorship_id] = @owner.id redirect_to root_path, notice: 'signed_in' end def destroy session[:wf_authorship_id] = nil redirect_to root_path, notice: 'signed_out' end protected def refresh_token @owner.update_attributes(data: @owner.data.merge({ auth_token: @auth.token })) end def find_or_create_owner find_owner || create_owner end def find_owner Authorship.find_by_uid(@github_user.id) end def create_owner if Authorship.count == 0 Authorship.create_from_data(@github_user) else return redirect_to root_path, notice: 'owner_exists' end end end end
Version data entries
26 entries across 26 versions & 1 rubygems