~vpzom/bracketmonster

7cf64d0c003e8ecd858878a4b8726cfe642aab64 — Colin Reeder 5 months ago 3f93e6a
no-js register
2 files changed, 26 insertions(+), 1 deletions(-)

M rosebush/src/client/pages/register.tsx
M rosebush/src/server/index.tsx
M rosebush/src/client/pages/register.tsx => rosebush/src/client/pages/register.tsx +1 -1
@@ 37,7 37,7 @@ export default class RegisterPage extends Component<Props, State> {

					<h1><Text id="register" /></h1>
					{userInfo !== null && <p><Text id="pages_register_anonymousUpgrade" /></p>}
					<form onSubmit={this.submit.bind(this)}>
					<form method="POST" action="/formSubmit/register" onSubmit={this.submit.bind(this)}>
						<p>
							<label>
								<Text id="username" />: <input type="text" name="username" />

M rosebush/src/server/index.tsx => rosebush/src/server/index.tsx +25 -0
@@ 183,6 183,31 @@ http.createServer(async (req_, res) => {
				res.write("Successfully logged in.");
				res.end();
			}
			else if(rest === "register") {
				const resp = await apiFetchRaw(req, "v1/users", {method: "POST", body: JSON.stringify({
					username: fields.username,
					password: fields.password,
				})});

				if(resp.status < 200 || resp.status >= 300) {
					const text = await resp.text();
					res.writeHead(resp.status);
					res.write(text);
					res.end();
					return;
				}

				const result = await resp.json();

				const token = result.token;

				res.writeHead(
					303,
					{"Set-Cookie": "rosebushToken=" + token + "; Path=/; Max-Age=" + COOKIE_AGE, Location: fields.continue || "/myBrackets"}
				);
				res.write("Successfully logged in.");
				res.end();
			}
			else if(rest === "newBracket") {
				let newUserToken = null;
				const newHeaders: {[key: string]: string} = {};