Skip to content

Commit 4b1919d

Browse files
authored
Merge pull request #17 from sleeptil3/feature/reset-pw
reset PW implimented
2 parents 6226f66 + e368008 commit 4b1919d

File tree

6 files changed

+229
-102
lines changed

6 files changed

+229
-102
lines changed

.yarn/install-state.gz

85 Bytes
Binary file not shown.

src/API/apiData.js

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SHOW
22
export const getAllUsers = async (BASE_URL, token) => {
33
try {
4-
const response = await fetch(`${BASE_URL}/admin/users`, {
4+
const response = await fetch(`${ BASE_URL }/admin/users`, {
55
method: 'GET',
66
headers: {
77
"Content-Type": "application/json",
8-
Authorization: `Bearer ${token}`
8+
Authorization: `Bearer ${ token }`
99
}
1010
})
1111
const data = await response.json()
@@ -17,11 +17,11 @@ export const getAllUsers = async (BASE_URL, token) => {
1717

1818
export const getUserData = async (BASE_URL, username, token) => {
1919
try {
20-
const response = await fetch(`${BASE_URL}/user/${username}`, {
20+
const response = await fetch(`${ BASE_URL }/user/${ username }`, {
2121
method: 'GET',
2222
headers: {
2323
"Content-Type": "application/json",
24-
Authorization: `Bearer ${token}`
24+
Authorization: `Bearer ${ token }`
2525
}
2626
})
2727
const data = await response.json()
@@ -33,11 +33,11 @@ export const getUserData = async (BASE_URL, username, token) => {
3333

3434
export const getAllSnippets = async (BASE_URL, username, token, user_id) => {
3535
try {
36-
const response = await fetch(`${BASE_URL}/user/${username}/${user_id}/allsnippets`, {
36+
const response = await fetch(`${ BASE_URL }/user/${ username }/${ user_id }/allsnippets`, {
3737
method: 'GET',
3838
headers: {
3939
"Content-Type": "application/json",
40-
Authorization: `Bearer ${token}`
40+
Authorization: `Bearer ${ token }`
4141
}
4242
})
4343
const data = await response.json()
@@ -49,11 +49,11 @@ export const getAllSnippets = async (BASE_URL, username, token, user_id) => {
4949

5050
export const getFriendSnippets = async (BASE_URL, username, token) => {
5151
try {
52-
const response = await fetch(`${BASE_URL}/user/${username}/friendsnippets`, {
52+
const response = await fetch(`${ BASE_URL }/user/${ username }/friendsnippets`, {
5353
method: 'GET',
5454
headers: {
5555
"Content-Type": "application/json",
56-
Authorization: `Bearer ${token}`
56+
Authorization: `Bearer ${ token }`
5757
}
5858
})
5959
const data = await response.json()
@@ -65,11 +65,11 @@ export const getFriendSnippets = async (BASE_URL, username, token) => {
6565

6666
export const getAdminCounts = async (BASE_URL, token) => {
6767
try {
68-
const response = await fetch(`${BASE_URL}/admin/count`, {
68+
const response = await fetch(`${ BASE_URL }/admin/count`, {
6969
method: 'GET',
7070
headers: {
7171
"Content-Type": "application/json",
72-
Authorization: `Bearer ${token}`
72+
Authorization: `Bearer ${ token }`
7373
}
7474
})
7575
const data = await response.json()
@@ -83,7 +83,7 @@ export const getAdminCounts = async (BASE_URL, token) => {
8383
export const createUser = async (BASE_URL, formData) => {
8484
const body = { ...formData }
8585
try {
86-
const response = await fetch(`${BASE_URL}/register`, {
86+
const response = await fetch(`${ BASE_URL }/register`, {
8787
method: 'POST',
8888
headers: {
8989
"Content-Type": "application/json"
@@ -100,11 +100,11 @@ export const createUser = async (BASE_URL, formData) => {
100100
export const createSnippet = async (BASE_URL, username, token, formData, user_id) => {
101101
const body = { ...formData, owner: user_id }
102102
try {
103-
const response = await fetch(`${BASE_URL}/user/${username}/${formData.parentFolder}/addsnippet`, {
103+
const response = await fetch(`${ BASE_URL }/user/${ username }/${ formData.parentFolder }/addsnippet`, {
104104
method: 'POST',
105105
headers: {
106106
"Content-Type": "application/json",
107-
Authorization: `Bearer ${token}`
107+
Authorization: `Bearer ${ token }`
108108
},
109109
body: JSON.stringify(body)
110110
})
@@ -120,11 +120,11 @@ export const createSnippet = async (BASE_URL, username, token, formData, user_id
120120
export const addFolder = async (BASE_URL, username, token, formData) => {
121121
const body = { ...formData }
122122
try {
123-
const response = await fetch(`${BASE_URL}/user/${username}/addfolder`, {
123+
const response = await fetch(`${ BASE_URL }/user/${ username }/addfolder`, {
124124
method: 'POST',
125125
headers: {
126126
"Content-Type": "application/json",
127-
Authorization: `Bearer ${token}`
127+
Authorization: `Bearer ${ token }`
128128
},
129129
body: JSON.stringify(body)
130130
})
@@ -140,11 +140,11 @@ export const addFolder = async (BASE_URL, username, token, formData) => {
140140
export const editSnippet = async (BASE_URL, username, token, formData) => {
141141
const body = { ...formData }
142142
try {
143-
const response = await fetch(`${BASE_URL}/user/${username}/snippets/${formData.snippet_id}/edit`, {
143+
const response = await fetch(`${ BASE_URL }/user/${ username }/snippets/${ formData.snippet_id }/edit`, {
144144
method: 'PUT',
145145
headers: {
146146
"Content-Type": "application/json",
147-
Authorization: `Bearer ${token}`
147+
Authorization: `Bearer ${ token }`
148148
},
149149
body: JSON.stringify(body)
150150
})
@@ -158,11 +158,11 @@ export const editSnippet = async (BASE_URL, username, token, formData) => {
158158
export const editUser = async (BASE_URL, username, token, formData) => {
159159
const body = { ...formData }
160160
try {
161-
const response = await fetch(`${BASE_URL}/user/${username}/edit`, {
161+
const response = await fetch(`${ BASE_URL }/user/${ username }/edit`, {
162162
method: 'PUT',
163163
headers: {
164164
"Content-Type": "application/json",
165-
Authorization: `Bearer ${token}`
165+
Authorization: `Bearer ${ token }`
166166
},
167167
body: JSON.stringify(body)
168168
})
@@ -176,11 +176,11 @@ export const editUser = async (BASE_URL, username, token, formData) => {
176176
export const editFolder = async (BASE_URL, username, token, folder_id, formData) => {
177177
const body = { ...formData }
178178
try {
179-
const response = await fetch(`${BASE_URL}/user/${username}/folders/${folder_id}/edit`, {
179+
const response = await fetch(`${ BASE_URL }/user/${ username }/folders/${ folder_id }/edit`, {
180180
method: 'PUT',
181181
headers: {
182182
"Content-Type": "application/json",
183-
Authorization: `Bearer ${token}`
183+
Authorization: `Bearer ${ token }`
184184
},
185185
body: JSON.stringify(body)
186186
})
@@ -193,11 +193,11 @@ export const editFolder = async (BASE_URL, username, token, folder_id, formData)
193193

194194
export const approveFriend = async (BASE_URL, username, token, friend_id) => {
195195
try {
196-
const response = await fetch(`${BASE_URL}/user/${username}/approvefriend/${friend_id}`, {
196+
const response = await fetch(`${ BASE_URL }/user/${ username }/approvefriend/${ friend_id }`, {
197197
method: 'PUT',
198198
headers: {
199199
"Content-Type": "application/json",
200-
Authorization: `Bearer ${token}`
200+
Authorization: `Bearer ${ token }`
201201
}
202202
})
203203
const data = await response.json()
@@ -209,11 +209,11 @@ export const approveFriend = async (BASE_URL, username, token, friend_id) => {
209209

210210
export const denyFriend = async (BASE_URL, username, token, friend_id) => {
211211
try {
212-
const response = await fetch(`${BASE_URL}/user/${username}/denyfriend/${friend_id}`, {
212+
const response = await fetch(`${ BASE_URL }/user/${ username }/denyfriend/${ friend_id }`, {
213213
method: 'PUT',
214214
headers: {
215215
"Content-Type": "application/json",
216-
Authorization: `Bearer ${token}`
216+
Authorization: `Bearer ${ token }`
217217
}
218218
})
219219
const data = await response.json()
@@ -225,11 +225,11 @@ export const denyFriend = async (BASE_URL, username, token, friend_id) => {
225225

226226
export const requestFriend = async (BASE_URL, username, token, friend_username) => {
227227
try {
228-
const response = await fetch(`${BASE_URL}/user/${username}/addfriend/${friend_username}`, {
228+
const response = await fetch(`${ BASE_URL }/user/${ username }/addfriend/${ friend_username }`, {
229229
method: 'PUT',
230230
headers: {
231231
"Content-Type": "application/json",
232-
Authorization: `Bearer ${token}`
232+
Authorization: `Bearer ${ token }`
233233
}
234234
})
235235
const data = await response.json()
@@ -239,15 +239,39 @@ export const requestFriend = async (BASE_URL, username, token, friend_username)
239239
}
240240
}
241241

242+
export const forgotPassword = async (BASE_URL, PWR_USER, PWR_PASS, userEmail) => {
243+
try {
244+
const res = await fetch(`${ BASE_URL }/pwr/auth`, {
245+
method: 'POST',
246+
headers: {
247+
"Content-Type": "application/json",
248+
},
249+
body: {
250+
"PWR_USER": PWR_USER,
251+
"PWR_PASS": PWR_PASS,
252+
"userEmail": userEmail
253+
}
254+
})
255+
const data = res.json()
256+
if (data.error) {
257+
console.error("Error: forgotPassword error message from codelockr-api", data)
258+
return data
259+
}
260+
else return data
261+
} catch (error) {
262+
console.error("Error: forgotPassword failed (codelockr-react)", error)
263+
}
264+
}
265+
242266
// DELETE
243267

244268
export const deleteSnippet = async (BASE_URL, username, token, snippet_id) => {
245269
try {
246-
const response = await fetch(`${BASE_URL}/user/${username}/snippets/${snippet_id}/delete`, {
270+
const response = await fetch(`${ BASE_URL }/user/${ username }/snippets/${ snippet_id }/delete`, {
247271
method: 'DELETE',
248272
headers: {
249273
"Content-Type": "application/json",
250-
Authorization: `Bearer ${token}`
274+
Authorization: `Bearer ${ token }`
251275
}
252276
})
253277
const data = await response.json()
@@ -259,11 +283,11 @@ export const deleteSnippet = async (BASE_URL, username, token, snippet_id) => {
259283

260284
export const deleteFolder = async (BASE_URL, username, token, folder_id) => {
261285
try {
262-
const response = await fetch(`${BASE_URL}/user/${username}/folders/${folder_id}/delete`, {
286+
const response = await fetch(`${ BASE_URL }/user/${ username }/folders/${ folder_id }/delete`, {
263287
method: 'DELETE',
264288
headers: {
265289
"Content-Type": "application/json",
266-
Authorization: `Bearer ${token}`
290+
Authorization: `Bearer ${ token }`
267291
}
268292
})
269293
const data = await response.json()
@@ -275,11 +299,11 @@ export const deleteFolder = async (BASE_URL, username, token, folder_id) => {
275299

276300
export const deleteUser = async (BASE_URL, username, token) => {
277301
try {
278-
const response = await fetch(`${BASE_URL}/user/${username}/delete/`, {
302+
const response = await fetch(`${ BASE_URL }/user/${ username }/delete/`, {
279303
method: 'DELETE',
280304
headers: {
281305
"Content-Type": "application/json",
282-
Authorization: `Bearer ${token}`
306+
Authorization: `Bearer ${ token }`
283307
}
284308
})
285309
const data = await response.json()

src/App.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import { useState, useEffect, createContext } from "react";
2-
import { Route, Switch, useHistory } from "react-router-dom";
3-
import Landing from "./Pages/Landing/Landing";
4-
import Admin from "./Pages/Admin/Admin";
5-
import User from "./Pages/User/User";
6-
export const DataContext = createContext();
1+
import { useState, useEffect, createContext } from "react"
2+
import { Route, Switch, useHistory } from "react-router-dom"
3+
import Landing from "./Pages/Landing/Landing"
4+
import Admin from "./Pages/Admin/Admin"
5+
import User from "./Pages/User/User"
6+
export const DataContext = createContext()
77

88
export default function App() {
9-
const [ showRegistration, setShowRegistration ] = useState(false);
10-
const history = useHistory();
11-
const [ loggedIn, setLoggedIn ] = useState({
9+
const [showRegistration, setShowRegistration] = useState(false)
10+
const history = useHistory()
11+
const [loggedIn, setLoggedIn] = useState({
1212
state: false,
1313
isAdmin: false,
1414
username: "",
1515
firstName: "",
1616
lastName: "",
17-
});
18-
const BASE_URL = "https://codelockr-api.herokuapp.com";
17+
})
18+
const BASE_URL = "https://codelockr-api.herokuapp.com"
1919
// const BASE_URL = 'http://localhost:3030'
2020

2121
const handleLogout = () => {
22-
window.localStorage.clear();
22+
window.localStorage.clear()
2323
setLoggedIn({
2424
state: false,
2525
isAdmin: false,
2626
username: "",
2727
firstName: "",
2828
lastName: "",
29-
});
30-
history.push("/");
31-
};
29+
})
30+
history.push("/")
31+
}
3232

3333
// IF on page load, there is a token in LS, set loggedIn data
3434
useEffect(() => {
@@ -39,25 +39,25 @@ export default function App() {
3939
username: window.localStorage.getItem("username"),
4040
firstName: "",
4141
lastName: "",
42-
});
42+
})
4343
} else if (window.localStorage.getItem("token")) {
4444
setLoggedIn({
4545
state: true,
4646
isAdmin: false,
4747
username: window.localStorage.getItem("username"),
4848
firstName: "",
4949
lastName: "",
50-
});
50+
})
5151
} else {
5252
setLoggedIn({
5353
state: false,
5454
isAdmin: false,
5555
username: "",
5656
firstName: "",
5757
lastName: "",
58-
});
58+
})
5959
}
60-
}, []);
60+
}, [])
6161

6262
return (
6363
<div>
@@ -69,5 +69,5 @@ export default function App() {
6969
</Switch>
7070
</DataContext.Provider>
7171
</div>
72-
);
72+
)
7373
}

0 commit comments

Comments
 (0)