mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-14 18:27:44 +02:00
Server: Added way to disable signup page, and added links between signup and login pages
This commit is contained in:
parent
e8a02c26d0
commit
75d79f373a
@ -35,6 +35,8 @@ export interface EnvVariables {
|
||||
STRIPE_SECRET_KEY?: string;
|
||||
STRIPE_PUBLISHABLE_KEY?: string;
|
||||
STRIPE_WEBHOOK_SECRET?: string;
|
||||
|
||||
SIGNUP_ENABLED?: string;
|
||||
}
|
||||
|
||||
let runningInDocker_: boolean = false;
|
||||
@ -144,6 +146,7 @@ export async function initConfig(envType: Env, env: EnvVariables, overrides: any
|
||||
baseUrl,
|
||||
apiBaseUrl: env.API_BASE_URL ? env.API_BASE_URL : baseUrl,
|
||||
userContentBaseUrl: env.USER_CONTENT_BASE_URL ? env.USER_CONTENT_BASE_URL : baseUrl,
|
||||
signupEnabled: env.SIGNUP_ENABLED === '1',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { SubPath, redirect } from '../../utils/routeUtils';
|
||||
import { SubPath, redirect, makeUrl, UrlType } from '../../utils/routeUtils';
|
||||
import Router from '../../utils/Router';
|
||||
import { RouteType } from '../../utils/types';
|
||||
import { AppContext } from '../../utils/types';
|
||||
@ -9,7 +9,10 @@ import { View } from '../../services/MustacheService';
|
||||
|
||||
function makeView(error: any = null): View {
|
||||
const view = defaultView('login');
|
||||
view.content.error = error;
|
||||
view.content = {
|
||||
error,
|
||||
signupUrl: config().signupEnabled ? makeUrl(UrlType.Signup) : '',
|
||||
};
|
||||
view.navbar = false;
|
||||
return view;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { SubPath, redirect } from '../../utils/routeUtils';
|
||||
import { SubPath, redirect, makeUrl, UrlType } from '../../utils/routeUtils';
|
||||
import Router from '../../utils/Router';
|
||||
import { RouteType } from '../../utils/types';
|
||||
import { AppContext } from '../../utils/types';
|
||||
@ -9,11 +9,15 @@ import { View } from '../../services/MustacheService';
|
||||
import { checkPassword } from './users';
|
||||
import { NotificationKey } from '../../models/NotificationModel';
|
||||
import { AccountType, accountTypeProperties } from '../../models/UserModel';
|
||||
import { ErrorForbidden } from '../../utils/errors';
|
||||
|
||||
function makeView(error: Error = null): View {
|
||||
const view = defaultView('signup');
|
||||
view.content.error = error;
|
||||
view.content.postUrl = `${config().baseUrl}/signup`;
|
||||
view.content = {
|
||||
error,
|
||||
postUrl: makeUrl(UrlType.Signup),
|
||||
loginUrl: makeUrl(UrlType.Login),
|
||||
};
|
||||
view.navbar = false;
|
||||
return view;
|
||||
}
|
||||
@ -34,6 +38,8 @@ router.get('signup', async (_path: SubPath, _ctx: AppContext) => {
|
||||
});
|
||||
|
||||
router.post('signup', async (_path: SubPath, ctx: AppContext) => {
|
||||
if (!config().signupEnabled) throw new ErrorForbidden('Signup is not enabled');
|
||||
|
||||
try {
|
||||
const formUser = await bodyFields<FormUser>(ctx.req);
|
||||
const password = checkPassword(formUser, true);
|
||||
|
@ -2,7 +2,7 @@ import { baseUrl } from '../config';
|
||||
import { Item, ItemAddressingType } from '../db';
|
||||
import { ErrorBadRequest, ErrorForbidden, ErrorNotFound } from './errors';
|
||||
import Router from './Router';
|
||||
import { AppContext, HttpMethod } from './types';
|
||||
import { AppContext, HttpMethod, RouteType } from './types';
|
||||
import { URL } from 'url';
|
||||
|
||||
const { ltrimSlashes, rtrimSlashes } = require('@joplin/lib/path-utils');
|
||||
@ -249,3 +249,12 @@ export function respondWithItemContent(koaResponse: any, item: Item, content: Bu
|
||||
koaResponse.set('Content-Length', content.byteLength);
|
||||
return new Response(ResponseType.KoaResponse, koaResponse);
|
||||
}
|
||||
|
||||
export enum UrlType {
|
||||
Signup = 'signup',
|
||||
Login = 'login',
|
||||
}
|
||||
|
||||
export function makeUrl(urlType: UrlType): string {
|
||||
return `${baseUrl(RouteType.Web)}/${urlType}`;
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ export interface Config {
|
||||
baseUrl: string;
|
||||
apiBaseUrl: string;
|
||||
userContentBaseUrl: string;
|
||||
signupEnabled: boolean;
|
||||
database: DatabaseConfig;
|
||||
mailer: MailerConfig;
|
||||
stripe: StripeConfig;
|
||||
|
@ -1,5 +1,5 @@
|
||||
<section class="section login-box">
|
||||
<div class="container">
|
||||
<div class="container block">
|
||||
{{> errorBanner}}
|
||||
<form action="{{{global.baseUrl}}}/login" method="POST">
|
||||
<div class="field">
|
||||
@ -19,4 +19,9 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{{#signupUrl}}
|
||||
<div class="container block">
|
||||
Or <a href="{{signupUrl}}">sign up</a> to create a new account.
|
||||
</div>
|
||||
{{/signupUrl}}
|
||||
</section>
|
@ -1,30 +1,37 @@
|
||||
{{> errorBanner}}
|
||||
<form action="{{{postUrl}}}" method="POST">
|
||||
<div class="field">
|
||||
<label class="label">Full name</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" name="full_name" value="{{user.full_name}}"/>
|
||||
</div>
|
||||
<section class="section login-box">
|
||||
<div class="container block">
|
||||
<form action="{{{postUrl}}}" method="POST">
|
||||
<div class="field">
|
||||
<label class="label">Full name</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" name="full_name" value="{{user.full_name}}"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">Email</label>
|
||||
<div class="control">
|
||||
<input class="input" type="email" name="email" value="{{user.email}}"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">Password</label>
|
||||
<div class="control">
|
||||
<input class="input" type="password" name="password" autocomplete="new-password"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">Repeat password</label>
|
||||
<div class="control">
|
||||
<input class="input" type="password" name="password2" autocomplete="new-password"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control">
|
||||
<input type="submit" name="post_button" class="button is-primary" value="Sign up" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">Email</label>
|
||||
<div class="control">
|
||||
<input class="input" type="email" name="email" value="{{user.email}}"/>
|
||||
</div>
|
||||
<div class="container block">
|
||||
Or <a href="{{loginUrl}}">login</a> if you already have an account.
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">Password</label>
|
||||
<div class="control">
|
||||
<input class="input" type="password" name="password" autocomplete="new-password"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">Repeat password</label>
|
||||
<div class="control">
|
||||
<input class="input" type="password" name="password2" autocomplete="new-password"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control">
|
||||
<input type="submit" name="post_button" class="button is-primary" value="Sign up" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user