Class: CollavreGithub::AuthController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- CollavreGithub::AuthController
- Defined in:
- app/controllers/collavre_github/auth_controller.rb
Instance Method Summary collapse
Instance Method Details
#callback ⇒ Object
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"] account = CollavreGithub::Account.find_or_initialize_by(github_uid: auth.uid) if account.new_record? unless Current.user redirect_to collavre.new_session_path, alert: I18n.t("collavre_github.auth.login_first") return end account.user_id = Current.user.id end account.token = auth.credentials.token account.login = auth.info.nickname account.name = auth.info.name account.avatar_url = auth.info.image account.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 |
#setup ⇒ Object
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.(Current.user, :admin) render plain: I18n.t("collavre_github.errors.forbidden"), status: :forbidden return end render layout: false end |
#store_creative ⇒ Object
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 |