mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-26 18:58:21 +02:00
This commit is contained in:
parent
2fd985b9ac
commit
3ee8da0cae
@ -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 limiterLoginBruteForce from '../../utils/request/limiterLoginBruteForce';
|
||||
import { cookieSet } from '../../utils/cookies';
|
||||
import { homeUrl } from '../../utils/urlUtils';
|
||||
|
||||
function makeView(error: any = null): View {
|
||||
const view = defaultView('login', 'Login');
|
||||
@ -22,7 +23,10 @@ const router: Router = new Router(RouteType.Web);
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user