diff --git a/api/views.py b/api/views.py
index 5321d517..5bed2b98 100644
--- a/api/views.py
+++ b/api/views.py
@@ -140,10 +140,16 @@ class UserGenerator(APIView):
# Create new credentials if nickname is new
if len(User.objects.filter(username=nickname)) == 0:
User.objects.create_user(username=nickname, password=token, is_staff=False)
-
else:
+ ## TODO only report a match was found if it has
+ ## been at least 30 minutes since user creation
+ ## Why: frontend gets confused to say Welcome back too soon
context['found'] = 'A matching nickname was found'
+ # TODO, "A matching nickname was found, but it is not yours!"
+ # why? It is unlikely but there is only 20 billion names
+ # but if the token is not exact
+
# TODO Keep user authenticated.
# BaseBackend.authenticate(self, request=None,username=nickname, password=token)
diff --git a/frontend/package-lock.json b/frontend/package-lock.json
index 56fec1f1..4e559c3d 100644
--- a/frontend/package-lock.json
+++ b/frontend/package-lock.json
@@ -2303,6 +2303,14 @@
"semver": "^6.0.0"
}
},
+ "material-ui-image": {
+ "version": "3.3.2",
+ "resolved": "https://registry.npmjs.org/material-ui-image/-/material-ui-image-3.3.2.tgz",
+ "integrity": "sha512-WE5QE0Rjdx9jPKuI0LWI7s8VQ9cifPIXObu8AUCRcidXGV3NqPI9C8c9A/C0MofKpkZ3buG8+IT9N7GgSmxXeg==",
+ "requires": {
+ "prop-types": "^15.5.8"
+ }
+ },
"merge-stream": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
diff --git a/frontend/package.json b/frontend/package.json
index fc5e2a34..280eda3e 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -24,6 +24,7 @@
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@material-ui/core": "^4.12.3",
"@material-ui/icons": "^4.11.2",
+ "material-ui-image": "^3.3.2",
"react-router-dom": "^5.2.0"
}
}
diff --git a/frontend/src/components/App.js b/frontend/src/components/App.js
index f03c5e97..6ac372c9 100644
--- a/frontend/src/components/App.js
+++ b/frontend/src/components/App.js
@@ -10,7 +10,7 @@ export default class App extends Component {
render() {
return (
-
+
);
diff --git a/frontend/src/components/UserGenPage.js b/frontend/src/components/UserGenPage.js
index 69f22298..2789a5ea 100644
--- a/frontend/src/components/UserGenPage.js
+++ b/frontend/src/components/UserGenPage.js
@@ -1,4 +1,7 @@
import React, { Component } from "react";
+import { Button , Grid, Typography, TextField, Select, FormHelperText, MenuItem, FormControl, Radio, FormControlLabel, RadioGroup, Menu} from "@material-ui/core"
+import { Link } from 'react-router-dom'
+import Image from 'material-ui-image'
export default class UserGenPage extends Component {
constructor(props) {
@@ -6,7 +9,7 @@ export default class UserGenPage extends Component {
this.state = {
token: this.genBase62Token(32),
};
- this.getGeneratedUser();
+ this.getGenerateUser();
}
// sort of cryptographically strong function to generate Base62 token client-side
@@ -20,30 +23,87 @@ export default class UserGenPage extends Component {
.substring(0, length);
}
- getGeneratedUser() {
+ getGenerateUser() {
fetch('/api/usergen' + '?token=' + this.state.token)
.then((response) => response.json())
.then((data) => {
this.setState({
nickname: data.nickname,
bit_entropy: data.token_bits_entropy,
+ avatar_url: 'static/assets/avatars/' + data.nickname + '.png',
shannon_entropy: data.token_shannon_entropy,
bad_request: data.bad_request,
+ found: data.found,
});
});
}
+ // Fix next two handler functions so they work sequentially
+ // at the moment they make the request generate a new user in parallel
+ // to updating the token in the state. So the it works a bit weird.
+
+ handleAnotherButtonPressed=(e)=>{
+ this.setState({
+ token: this.genBase62Token(32),
+ })
+ this.getGenerateUser();
+ }
+
+ handleChangeToken=(e)=>{
+ this.setState({
+ token: e.target.value,
+ })
+ this.getGenerateUser();
+ }
render() {
return (
-