mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-04 14:48:42 +00:00
fix redirect after login (#824)
if you are in buildView and login, go back to this buildView again
This commit is contained in:
parent
d06dfc86b4
commit
70af29f9a2
7 changed files with 32 additions and 19 deletions
|
@ -37,14 +37,9 @@ func HandleLogin(c *gin.Context) {
|
||||||
)
|
)
|
||||||
if err := r.FormValue("error"); err != "" {
|
if err := r.FormValue("error"); err != "" {
|
||||||
http.Redirect(w, r, "/login/error?code="+err, 303)
|
http.Redirect(w, r, "/login/error?code="+err, 303)
|
||||||
} else {
|
|
||||||
intendedURL := r.URL.Query()["url"]
|
|
||||||
if len(intendedURL) > 0 {
|
|
||||||
http.Redirect(w, r, "/authorize?url="+intendedURL[0], 303)
|
|
||||||
} else {
|
} else {
|
||||||
http.Redirect(w, r, "/authorize", 303)
|
http.Redirect(w, r, "/authorize", 303)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleAuth(c *gin.Context) {
|
func HandleAuth(c *gin.Context) {
|
||||||
|
@ -141,12 +136,7 @@ func HandleAuth(c *gin.Context) {
|
||||||
|
|
||||||
httputil.SetCookie(c.Writer, c.Request, "user_sess", tokenString)
|
httputil.SetCookie(c.Writer, c.Request, "user_sess", tokenString)
|
||||||
|
|
||||||
intendedURL := c.Request.URL.Query()["url"]
|
|
||||||
if len(intendedURL) > 0 {
|
|
||||||
c.Redirect(303, intendedURL[0])
|
|
||||||
} else {
|
|
||||||
c.Redirect(303, "/")
|
c.Redirect(303, "/")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetLogout(c *gin.Context) {
|
func GetLogout(c *gin.Context) {
|
||||||
|
|
|
@ -26,6 +26,9 @@ var (
|
||||||
|
|
||||||
// Generate an SVG badge based on a build
|
// Generate an SVG badge based on a build
|
||||||
func Generate(build *model.Build) string {
|
func Generate(build *model.Build) string {
|
||||||
|
if build == nil {
|
||||||
|
return badgeNone
|
||||||
|
}
|
||||||
switch build.Status {
|
switch build.Status {
|
||||||
case model.StatusSuccess:
|
case model.StatusSuccess:
|
||||||
return badgeSuccess
|
return badgeSuccess
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
import useConfig from '~/compositions/useConfig';
|
import useConfig from '~/compositions/useConfig';
|
||||||
|
import useUserConfig from '~/compositions/useUserConfig';
|
||||||
|
|
||||||
export default () =>
|
export default () =>
|
||||||
({
|
({
|
||||||
isAuthenticated: useConfig().user,
|
isAuthenticated: !!useConfig().user,
|
||||||
|
|
||||||
user: useConfig().user,
|
user: useConfig().user,
|
||||||
|
|
||||||
authenticate(origin?: string) {
|
authenticate(url?: string) {
|
||||||
const url = `/login?url=${origin || ''}`;
|
if (url) {
|
||||||
window.location.href = url;
|
const config = useUserConfig();
|
||||||
|
config.setUserConfig('redirectUrl', url);
|
||||||
|
}
|
||||||
|
window.location.href = '/login';
|
||||||
},
|
},
|
||||||
} as const);
|
} as const);
|
||||||
|
|
|
@ -4,10 +4,12 @@ const USER_CONFIG_KEY = 'woodpecker-user-config';
|
||||||
|
|
||||||
type UserConfig = {
|
type UserConfig = {
|
||||||
isBuildFeedOpen: boolean;
|
isBuildFeedOpen: boolean;
|
||||||
|
redirectUrl: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultUserConfig: UserConfig = {
|
const defaultUserConfig: UserConfig = {
|
||||||
isBuildFeedOpen: false,
|
isBuildFeedOpen: false,
|
||||||
|
redirectUrl: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
function loadUserConfig(): UserConfig {
|
function loadUserConfig(): UserConfig {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { Component } from 'vue';
|
import { Component } from 'vue';
|
||||||
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
|
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
|
||||||
|
|
||||||
import useAuthentication from './compositions/useAuthentication';
|
import useAuthentication from '~/compositions/useAuthentication';
|
||||||
|
import useUserConfig from '~/compositions/useUserConfig';
|
||||||
|
|
||||||
const routes: RouteRecordRaw[] = [
|
const routes: RouteRecordRaw[] = [
|
||||||
{
|
{
|
||||||
|
@ -26,7 +27,6 @@ const routes: RouteRecordRaw[] = [
|
||||||
name: 'repos-owner',
|
name: 'repos-owner',
|
||||||
component: (): Component => import('~/views/ReposOwner.vue'),
|
component: (): Component => import('~/views/ReposOwner.vue'),
|
||||||
props: true,
|
props: true,
|
||||||
meta: { authentication: 'required' },
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/:repoOwner/:repoName',
|
path: '/:repoOwner/:repoName',
|
||||||
|
@ -133,6 +133,13 @@ const router = createRouter({
|
||||||
});
|
});
|
||||||
|
|
||||||
router.beforeEach(async (to, _, next) => {
|
router.beforeEach(async (to, _, next) => {
|
||||||
|
const config = useUserConfig();
|
||||||
|
const { redirectUrl } = config.userConfig.value;
|
||||||
|
if (redirectUrl !== '') {
|
||||||
|
config.setUserConfig('redirectUrl', '');
|
||||||
|
next(redirectUrl);
|
||||||
|
}
|
||||||
|
|
||||||
const authentication = useAuthentication();
|
const authentication = useAuthentication();
|
||||||
if (to.meta.authentication === 'required' && !authentication.isAuthenticated) {
|
if (to.meta.authentication === 'required' && !authentication.isAuthenticated) {
|
||||||
next({ name: 'login', query: { url: to.fullPath } });
|
next({ name: 'login', query: { url: to.fullPath } });
|
||||||
|
|
|
@ -53,7 +53,7 @@ export default defineComponent({
|
||||||
const errorMessage = ref<string>();
|
const errorMessage = ref<string>();
|
||||||
|
|
||||||
function doLogin() {
|
function doLogin() {
|
||||||
const url = typeof route.query.origin === 'string' ? route.query.origin : '';
|
const url = typeof route.query.url === 'string' ? route.query.url : '';
|
||||||
authentication.authenticate(url);
|
authentication.authenticate(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ import FluidContainer from '~/components/layout/FluidContainer.vue';
|
||||||
import Tab from '~/components/tabs/Tab.vue';
|
import Tab from '~/components/tabs/Tab.vue';
|
||||||
import Tabs from '~/components/tabs/Tabs.vue';
|
import Tabs from '~/components/tabs/Tabs.vue';
|
||||||
import useApiClient from '~/compositions/useApiClient';
|
import useApiClient from '~/compositions/useApiClient';
|
||||||
|
import useAuthentication from '~/compositions/useAuthentication';
|
||||||
import useNotifications from '~/compositions/useNotifications';
|
import useNotifications from '~/compositions/useNotifications';
|
||||||
import { RepoPermissions } from '~/lib/api/types';
|
import { RepoPermissions } from '~/lib/api/types';
|
||||||
import BuildStore from '~/store/builds';
|
import BuildStore from '~/store/builds';
|
||||||
|
@ -72,6 +73,7 @@ export default defineComponent({
|
||||||
const buildStore = BuildStore();
|
const buildStore = BuildStore();
|
||||||
const apiClient = useApiClient();
|
const apiClient = useApiClient();
|
||||||
const notifications = useNotifications();
|
const notifications = useNotifications();
|
||||||
|
const { isAuthenticated } = useAuthentication();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
@ -86,6 +88,11 @@ export default defineComponent({
|
||||||
repoPermissions.value = await apiClient.getRepoPermissions(repoOwner.value, repoName.value);
|
repoPermissions.value = await apiClient.getRepoPermissions(repoOwner.value, repoName.value);
|
||||||
if (!repoPermissions.value.pull) {
|
if (!repoPermissions.value.pull) {
|
||||||
notifications.notify({ type: 'error', title: 'Not allowed to access this repository' });
|
notifications.notify({ type: 'error', title: 'Not allowed to access this repository' });
|
||||||
|
// no access and not authenticated, redirect to login
|
||||||
|
if (!isAuthenticated) {
|
||||||
|
await router.replace({ name: 'login', query: { url: route.fullPath } });
|
||||||
|
return;
|
||||||
|
}
|
||||||
await router.replace({ name: 'home' });
|
await router.replace({ name: 'home' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue