From aaeec77d237f5fcc1eee88915ba1284bd53bc708 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Thu, 23 Jun 2022 16:15:03 +0800 Subject: [PATCH] add login by giteatoken --- app/controllers/oauth_controller.rb | 9 +++++++++ config/routes.rb | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/oauth_controller.rb b/app/controllers/oauth_controller.rb index f2ca2cc2..5e243342 100644 --- a/app/controllers/oauth_controller.rb +++ b/app/controllers/oauth_controller.rb @@ -88,4 +88,13 @@ class OauthController < ApplicationController end end + def token_login + @user = User.find_by_gitea_token(params[:token]) + if @user.present? + successful_authentication(@user) + redirect_to root_url + else + render json: { error: "用户不存在" } + end + end end diff --git a/config/routes.rb b/config/routes.rb index e1058714..28a77f8e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -938,7 +938,7 @@ Rails.application.routes.draw do get 'oauth/get_code', to: 'oauth#get_code' get 'oauth/get_token_callback', to: 'oauth#get_token_callback' - + get 'oauth/token_login', to: 'oauth#token_login' root 'main#index'