Skip to content

Commit

Permalink
Implement username login
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyfurion committed Dec 7, 2021
1 parent 7c4a6dd commit 6c19277
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 10 deletions.
10 changes: 5 additions & 5 deletions client/src/components/LoginScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function LoginScreen() {
event.preventDefault();
const data = new FormData(event.currentTarget);
auth.loginUser({
email: data.get('email'),
userName: data.get('username'),
password: data.get('password')
}, store).catch(function (error) {
auth.showError(error.response.data.errorMessage);
Expand Down Expand Up @@ -78,10 +78,10 @@ export default function LoginScreen() {
margin="normal"
required
fullWidth
id="email"
label="Email Address"
name="email"
autoComplete="email"
id="username"
label="Username"
name="username"
autoComplete="username"
autoFocus
/>
<TextField
Expand Down
10 changes: 5 additions & 5 deletions server/controllers/user-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ registerUser = async (req, res) => {

loginUser = async (req, res) => {
try {
const { email, password } = req.body;
if (!email || !password) {
const { userName, password } = req.body;
if (!userName || !password) {
return res
.status(400)
.json({ errorMessage: "Please enter all required fields." });
}
const existingUser = await User.findOne({ email: email });
const existingUser = await User.findOne({ userName: userName });
if (!existingUser) {
return res
.status(400)
.json({
success: false,
errorMessage: "Incorrect email or password."
errorMessage: "Incorrect username or password."
});
}
const authenticated = await bcrypt.compare(password, existingUser.passwordHash);
Expand All @@ -102,7 +102,7 @@ loginUser = async (req, res) => {
.status(400)
.json({
success: false,
errorMessage: "Incorrect email or password."
errorMessage: "Incorrect username or password."
})
}

Expand Down
249 changes: 249 additions & 0 deletions test/top5lists.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
[{
"_id": {
"$oid": "61aeddceffd294401cd5c4ad"
},
"items": [
"Zhong Li",
"Eula",
"Ayaka",
"Ei",
"Kokomi"
],
"likes": [],
"dislikes": [],
"name": "Genshin Impact Characters",
"ownerEmail": "[email protected]",
"ownerName": "Cyfurion",
"published": true,
"publishedDate": "December 6, 2021",
"views": 2,
"comments": [],
"communityPoints": [],
"createdAt": {
"$date": "2021-12-07T04:06:38.740Z"
},
"updatedAt": {
"$date": "2021-12-07T04:13:53.807Z"
},
"__v": 1
},{
"_id": {
"$oid": "61aede17ffd294401cd5c4dd"
},
"items": [
"Zhong Li",
"Eula",
"Raiden Shogun",
"Ayaka",
"Ei"
],
"likes": [],
"dislikes": [],
"name": "Genshin Impact Characters",
"ownerEmail": "community",
"ownerName": "Community List",
"published": true,
"publishedDate": "December 6, 2021",
"views": 7,
"comments": [
{
"_id": {
"$oid": "61aedf1bffd294401cd5c5cd"
},
"name": "Cyfurion",
"body": "cap"
},
{
"_id": {
"$oid": "61aedf0fffd294401cd5c5aa"
},
"name": "Guardian",
"body": "Razor best boi"
}
],
"communityPoints": [
{
"_id": {
"$oid": "61aede17ffd294401cd5c4de"
},
"item": "Zhong Li",
"points": 9
},
{
"_id": {
"$oid": "61aede17ffd294401cd5c4df"
},
"item": "Eula",
"points": 7
},
{
"_id": {
"$oid": "61aedee7ffd294401cd5c572"
},
"item": "Raiden Shogun",
"points": 5
},
{
"_id": {
"$oid": "61aede17ffd294401cd5c4e0"
},
"item": "Ayaka",
"points": 3
},
{
"_id": {
"$oid": "61aede17ffd294401cd5c4e1"
},
"item": "Ei",
"points": 2
},
{
"_id": {
"$oid": "61aedee7ffd294401cd5c575"
},
"item": "Ai",
"points": 2
},
{
"_id": {
"$oid": "61aede17ffd294401cd5c4e2"
},
"item": "Kokomi",
"points": 1
},
{
"_id": {
"$oid": "61aedee7ffd294401cd5c577"
},
"item": "Paimon",
"points": 1
}
],
"createdAt": {
"$date": "2021-12-07T04:07:51.350Z"
},
"updatedAt": {
"$date": "2021-12-07T04:12:11.805Z"
},
"__v": 10
},{
"_id": {
"$oid": "61aede78ffd294401cd5c520"
},
"items": [
"Raiden Shogun",
"Zhong Li",
"Eula",
"Ai",
"Paimon"
],
"likes": [],
"dislikes": [],
"name": "Genshin Impact Characters",
"ownerEmail": "[email protected]",
"ownerName": "Guardian",
"published": true,
"publishedDate": "December 6, 2021",
"views": 1,
"comments": [],
"communityPoints": [],
"createdAt": {
"$date": "2021-12-07T04:09:28.812Z"
},
"updatedAt": {
"$date": "2021-12-07T04:11:37.709Z"
},
"__v": 2
},{
"_id": {
"$oid": "61aedf5dffd294401cd5c5dc"
},
"items": [
"B",
"C",
"D",
"A",
"F"
],
"likes": [],
"dislikes": [],
"name": "Letters",
"ownerEmail": "[email protected]",
"ownerName": "Cyfurion",
"published": true,
"publishedDate": "December 6, 2021",
"views": 5,
"comments": [],
"communityPoints": [],
"createdAt": {
"$date": "2021-12-07T04:13:17.523Z"
},
"updatedAt": {
"$date": "2021-12-07T04:13:57.463Z"
},
"__v": 1
},{
"_id": {
"$oid": "61aedf7effd294401cd5c60a"
},
"items": [
"B",
"C",
"D",
"A",
"F"
],
"likes": [],
"dislikes": [],
"name": "Letters",
"ownerEmail": "community",
"ownerName": "Community List",
"published": true,
"publishedDate": "December 6, 2021",
"views": 0,
"comments": [],
"communityPoints": [
{
"_id": {
"$oid": "61aedf7effd294401cd5c60b"
},
"item": "B",
"points": 5
},
{
"_id": {
"$oid": "61aedf7effd294401cd5c60c"
},
"item": "C",
"points": 4
},
{
"_id": {
"$oid": "61aedf7effd294401cd5c60d"
},
"item": "D",
"points": 3
},
{
"_id": {
"$oid": "61aedf7effd294401cd5c60e"
},
"item": "A",
"points": 2
},
{
"_id": {
"$oid": "61aedf7effd294401cd5c60f"
},
"item": "F",
"points": 1
}
],
"createdAt": {
"$date": "2021-12-07T04:13:50.890Z"
},
"updatedAt": {
"$date": "2021-12-07T04:13:50.890Z"
},
"__v": 0
}]
29 changes: 29 additions & 0 deletions test/users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[{
"_id": {
"$oid": "61aed8a3e07b3a26381609ba"
},
"userName": "Cyfurion",
"email": "[email protected]",
"passwordHash": "$2a$10$bw8OPf72khyZfGneC5sSFeTUFgpLVW80k6RUOkeQyN0hlbZ9lSwbe",
"createdAt": {
"$date": "2021-12-07T03:44:35.656Z"
},
"updatedAt": {
"$date": "2021-12-07T03:44:35.656Z"
},
"__v": 0
},{
"_id": {
"$oid": "61aede67ffd294401cd5c511"
},
"userName": "Guardian",
"email": "[email protected]",
"passwordHash": "$2a$10$NthfuchDwOPKTHqmv.4UKubRltfg6TH0jGWojZ9HYqav7ZFARhkou",
"createdAt": {
"$date": "2021-12-07T04:09:11.552Z"
},
"updatedAt": {
"$date": "2021-12-07T04:09:11.552Z"
},
"__v": 0
}]

0 comments on commit 6c19277

Please sign in to comment.