You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-03 23:50:33 +02:00
This commit is contained in:
@ -72,4 +72,38 @@ describe('index_login', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should redirect if already logged in', async () => {
|
||||||
|
const user = await createUser(1);
|
||||||
|
|
||||||
|
const context = await doLogin(user.email, '123456');
|
||||||
|
const sessionId = cookieGet(context, 'sessionId');
|
||||||
|
|
||||||
|
const getContext = await koaAppContext({
|
||||||
|
sessionId: sessionId,
|
||||||
|
request: {
|
||||||
|
method: 'GET',
|
||||||
|
url: '/login',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await routeHandler(getContext);
|
||||||
|
|
||||||
|
expect(getContext.response.status).toBe(302);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not redirect if sessionId is not valid', async () => {
|
||||||
|
|
||||||
|
const getContext = await koaAppContext({
|
||||||
|
sessionId: 'no-sense',
|
||||||
|
request: {
|
||||||
|
method: 'GET',
|
||||||
|
url: '/login',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await routeHandler(getContext);
|
||||||
|
|
||||||
|
expect(getContext.response.status).toBe(200);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -8,6 +8,7 @@ import defaultView from '../../utils/defaultView';
|
|||||||
import { View } from '../../services/MustacheService';
|
import { View } from '../../services/MustacheService';
|
||||||
import limiterLoginBruteForce from '../../utils/request/limiterLoginBruteForce';
|
import limiterLoginBruteForce from '../../utils/request/limiterLoginBruteForce';
|
||||||
import { cookieSet } from '../../utils/cookies';
|
import { cookieSet } from '../../utils/cookies';
|
||||||
|
import { homeUrl } from '../../utils/urlUtils';
|
||||||
|
|
||||||
function makeView(error: any = null): View {
|
function makeView(error: any = null): View {
|
||||||
const view = defaultView('login', 'Login');
|
const view = defaultView('login', 'Login');
|
||||||
@ -22,7 +23,10 @@ const router: Router = new Router(RouteType.Web);
|
|||||||
|
|
||||||
router.public = true;
|
router.public = true;
|
||||||
|
|
||||||
router.get('login', async (_path: SubPath, _ctx: AppContext) => {
|
router.get('login', async (_path: SubPath, ctx: AppContext) => {
|
||||||
|
if (ctx.joplin.owner) {
|
||||||
|
return redirect(ctx, homeUrl());
|
||||||
|
}
|
||||||
return makeView();
|
return makeView();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user