Ported from gitlab to gitea
This commit is contained in:
		@@ -24,22 +24,28 @@ pub struct GitlabUser {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub static REDIRECT_URL: Lazy<String> = Lazy::new(|| CONFIG.gitlab_redirect_url.clone() + "/api/auth/gitlab_callback");
 | 
			
		||||
pub static TOKEN_URL: Lazy<String> = Lazy::new(|| format!("{}/oauth/token", CONFIG.gitlab_api_url.clone()));
 | 
			
		||||
pub static USER_URL: Lazy<String> = Lazy::new(|| format!("{}/api/v4/user", CONFIG.gitlab_api_url.clone()));
 | 
			
		||||
pub static AUTHORIZE_URL: Lazy<String> = Lazy::new(|| format!("{}/oauth/authorize", CONFIG.gitlab_url.clone()));
 | 
			
		||||
pub static TOKEN_URL: Lazy<String> = Lazy::new(|| format!("{}/login/oauth/access_token", CONFIG.gitlab_api_url.clone()));
 | 
			
		||||
pub static USER_URL: Lazy<String> = Lazy::new(|| format!("{}/api/v1/user", CONFIG.gitlab_api_url.clone()));
 | 
			
		||||
pub static AUTHORIZE_URL: Lazy<String> = Lazy::new(|| format!("{}/login/oauth/authorize", CONFIG.gitlab_url.clone()));
 | 
			
		||||
 | 
			
		||||
pub fn get_gitlab_token(span: &Span, code_or_token: String, token: bool) -> Option<GitlabTokens> {
 | 
			
		||||
    let _span = metrics::span("get_gitlab_token", span);
 | 
			
		||||
    let mut req = ureq::post(&TOKEN_URL)
 | 
			
		||||
        .query("redirect_uri", &REDIRECT_URL)
 | 
			
		||||
        .query("client_id", &CONFIG.gitlab_id)
 | 
			
		||||
        .query("client_secret", &CONFIG.gitlab_secret);
 | 
			
		||||
    if token {
 | 
			
		||||
        req = req.query("refresh_token", &code_or_token).query("grant_type", "refresh_token");
 | 
			
		||||
    } else {
 | 
			
		||||
        req = req.query("code", &code_or_token).query("grant_type", "authorization_code");
 | 
			
		||||
    }
 | 
			
		||||
    req.call().ok()?.into_json().ok()
 | 
			
		||||
    let grant_type = match token {
 | 
			
		||||
        true => "refresh_token",
 | 
			
		||||
        false => "authorization_code"
 | 
			
		||||
    };
 | 
			
		||||
    let code_name = match token {
 | 
			
		||||
        true => "refresh_token",
 | 
			
		||||
        false => "code"
 | 
			
		||||
    };
 | 
			
		||||
    ureq::post(&TOKEN_URL)
 | 
			
		||||
        .send_json(ureq::json! ({
 | 
			
		||||
            "grant_type": grant_type,
 | 
			
		||||
            "client_id": &CONFIG.gitlab_id,
 | 
			
		||||
            "client_secret": &CONFIG.gitlab_secret,
 | 
			
		||||
            "redirect_uri": *REDIRECT_URL,
 | 
			
		||||
            code_name: code_or_token
 | 
			
		||||
        })).ok()?.into_json().ok()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn get_gitlab_user(span: &Span, token: String) -> Option<GitlabUser> {
 | 
			
		||||
 
 | 
			
		||||
@@ -102,7 +102,7 @@ const columns: DataTableColumn<Responses.GetUsersEntry>[] = [
 | 
			
		||||
		title: 'Type',
 | 
			
		||||
		key: 'gitlab',
 | 
			
		||||
		render(user) {
 | 
			
		||||
			return user.gitlab ? 'Gitlab' : 'Password';
 | 
			
		||||
			return user.gitlab ? 'Gitea' : 'Password';
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
@@ -3,17 +3,7 @@ import type { TokenInjectType } from '@/api';
 | 
			
		||||
import { ref, inject } from 'vue';
 | 
			
		||||
import { Auth, FS, isErrorResponse } from '@/api';
 | 
			
		||||
import { useRouter } from 'vue-router';
 | 
			
		||||
import {
 | 
			
		||||
	useMessage,
 | 
			
		||||
	NInput,
 | 
			
		||||
	NGrid,
 | 
			
		||||
	NGi,
 | 
			
		||||
	NButton,
 | 
			
		||||
	NIcon,
 | 
			
		||||
	NH4,
 | 
			
		||||
	NCard
 | 
			
		||||
} from 'naive-ui';
 | 
			
		||||
import { LogoGitlab } from '@vicons/ionicons5';
 | 
			
		||||
import { useMessage, NInput, NGrid, NGi, NButton, NH4, NCard } from 'naive-ui';
 | 
			
		||||
import { loadingMsgWrapper } from '@/utils';
 | 
			
		||||
 | 
			
		||||
const router = useRouter();
 | 
			
		||||
@@ -105,14 +95,11 @@ function onKey(event: KeyboardEvent) {
 | 
			
		||||
				<n-gi style="text-align: right">
 | 
			
		||||
					<n-button
 | 
			
		||||
						ghost
 | 
			
		||||
						color="#fc6d27"
 | 
			
		||||
						color="#16ab39"
 | 
			
		||||
						text-color="#000"
 | 
			
		||||
						@click="loginGitlab"
 | 
			
		||||
					>
 | 
			
		||||
						<template #icon>
 | 
			
		||||
							<n-icon color="#fc6d27"><LogoGitlab /></n-icon>
 | 
			
		||||
						</template>
 | 
			
		||||
						Login with gitlab
 | 
			
		||||
						Login with gitea
 | 
			
		||||
					</n-button>
 | 
			
		||||
				</n-gi>
 | 
			
		||||
				<n-gi>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user