Class: CollavreGithub::AuthController

Inherits:
ApplicationController show all
Defined in:
app/controllers/collavre_github/auth_controller.rb

Instance Method Summary collapse

Instance Method Details

#callbackObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/collavre_github/auth_controller.rb', line 6

def callback
  auth = request.env["omniauth.auth"]
   = CollavreGithub::Account.find_or_initialize_by(github_uid: auth.uid)

  if .new_record?
    unless Current.user
      redirect_to collavre.new_session_path, alert: I18n.t("collavre_github.auth.login_first")
      return
    end
    .user_id = Current.user.id
  end

  .token = auth.credentials.token
  . = auth.info.nickname
  .name = auth.info.name
  .avatar_url = auth.info.image
  .save!

  creative_id = session.delete(:github_creative_id)
  if creative_id.present?
    redirect_to setup_auth_path(creative_id: creative_id)
  else
    redirect_to collavre.creatives_path, notice: I18n.t("collavre_github.auth.connected")
  end
end

#setupObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/collavre_github/auth_controller.rb', line 32

def setup
  @creative_id = params[:creative_id]
  unless @creative_id.present?
    render plain: I18n.t("collavre_github.integration.missing_creative"), status: :bad_request
    return
  end

  @creative = Collavre::Creative.find_by(id: @creative_id)
  unless @creative
    render plain: I18n.t("collavre_github.integration.missing_creative"), status: :not_found
    return
  end

  unless @creative.has_permission?(Current.user, :admin)
    render plain: I18n.t("collavre_github.errors.forbidden"), status: :forbidden
    return
  end

  render layout: false
end

#store_creativeObject



53
54
55
56
# File 'app/controllers/collavre_github/auth_controller.rb', line 53

def store_creative
  session[:github_creative_id] = params[:creative_id]
  head :ok
end