Skip to content

Commit

Permalink
FEATURE: Register as a new user.
Browse files Browse the repository at this point in the history
  • Loading branch information
benel committed Sep 3, 2024
1 parent 088bc21 commit 7a532fb
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ services:
alias put="curl -X PUT -u '${COUCHDB_USER}:${COUCHDB_PASSWORD}'"
put backend:5984/hyperglosae
put backend:5984/hyperglosae/_security --data '{"members":{"roles":[]},"admins":{"roles":["_admin"]}}'
put backend:5984/_node/nonode@nohost/_config/couchdb/users_db_security_editable --data '"true"'
put backend:5984/_users/_security --data '{"members":{"roles":[]},"admins":{"roles":["_admin"]}}'
depends_on:
backend:
condition: service_healthy
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { NotificationContainer, NotificationManager } from 'react-notifications'
import 'react-notifications/lib/notifications.css';
import { TypesContext } from './components/TypesContext.js';
import LecternBlank from './routes/LecternBlank';
import Registration from './routes/Registration';

const backend = new Hyperglosae(
x => NotificationManager.warning(x, '', 2000)
Expand All @@ -35,6 +36,7 @@ function App() {
<Routes>
<Route path="/" element={<Bookshelf {...{backend, user}} />} />
<Route path="/blank" element={<LecternBlank {...{backend}}/>} />
<Route path="/registration" element={<Registration {...{backend}}/>} />
<Route path="/:id" element={<Lectern {...{backend, user}} />} />
</Routes>
</TypesContext.Provider>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/hyperglosae.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function Hyperglosae(logger) {
});
};

this.putDocument = (doc) =>
fetch(`${service}/${doc._id}`, {
this.putDocument = (doc, uri) =>
fetch(`${service}/${uri || doc._id}`, {
method: 'PUT',
headers: basicAuthentication({force: false}),
body: JSON.stringify(doc)
Expand Down
51 changes: 51 additions & 0 deletions frontend/src/routes/Registration.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Form from 'react-bootstrap/Form';
import Button from 'react-bootstrap/Button';
import { NotificationManager } from 'react-notifications';

function Registration({backend}) {

const handleSubmit = (e) => {
e.preventDefault();
let user = {
name: e.target[0].value,
password: e.target[1].value,
type: 'user',
roles: [],
created: new Date()
};
backend.putDocument(user, `_users/org.couchdb.user:${user.name}`)
.then(() => {
NotificationManager.success(`${user.name} is now registered!`);
e.target.reset();
});
};

return (
<Form className="screen container" onSubmit={handleSubmit}>
<Form.Group className="mb-3" controlId="name">
<Form.Label>Email address</Form.Label>
<Form.Control type="email"/>
<Form.Text className="text-muted">
<p>Please use your e-mail address given by your organization
(university company, NGO...).</p>
<p>Do not use addresses created anonymously (such as GMail, Yahoo...).</p>
</Form.Text>
</Form.Group>

<Form.Group className="mb-3" controlId="password">
<Form.Label>Password</Form.Label>
<Form.Control type="password" />
<Form.Text className="text-muted">
<p>Set a <b>new</b> password, a password you never used anywhere else.</p>
<p>Especially, do not reuse the password associated with your e-mail service.</p>
</Form.Text>
</Form.Group>
<Button variant="light" type="submit">
Submit
</Button>
</Form>
);
}

export default Registration;

5 changes: 5 additions & 0 deletions frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export default defineConfig({
server: {
port: 3000,
proxy: {
'/api/_users': {
target: 'http://localhost:5984/_users',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api\/_users/, ''),
},
'/api': {
target: 'http://localhost:5984/hyperglosae',
changeOrigin: true,
Expand Down
1 change: 1 addition & 0 deletions settings/haproxy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ frontend http-in
backend couchdb
option httpchk GET /_up
http-check disable-on-404
http-request replace-path /api/_users/(.*) /_users/\1
http-request replace-path /api(/)?(.*) /hyperglosae/\2
server couchdb1 backend:5984 check inter 5s

Expand Down

0 comments on commit 7a532fb

Please sign in to comment.