Skip to content

Commit 5475f4d

Browse files
authored
Merge pull request #52 from CodeForPhilly/basic_auth
Basic auth
2 parents f545e50 + f4cf895 commit 5475f4d

File tree

13 files changed

+249
-120
lines changed

13 files changed

+249
-120
lines changed
File renamed without changes.

frontend/src/components/Header/Header.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ const Header = () => {
5151
"xl:px-50 mx-auto hidden h-20 items-center justify-between border-b border-gray-300 bg-white px-4 sm:px-6 md:px-8 lg:flex lg:px-8 2xl:px-56"
5252
}
5353
>
54-
<Link to="/">
55-
<span className="header_logo ml-72 text-xl font-bold">
56-
Balancer
57-
</span>
58-
</Link>
54+
<Link to="/">
55+
<span className="header_logo ml-72 text-xl font-bold">Balancer</span>
56+
</Link>
5957
<nav className="flex w-full items-center justify-center font-satoshi text-base">
6058
<div
6159
onMouseEnter={handleMouseEnter}
@@ -66,8 +64,8 @@ const Header = () => {
6664
<span
6765
className={` mr-9 text-black ${
6866
showFeaturesMenu
69-
? "cursor-pointer mx-4 border-b-2 border-blue-600 hover:border-b-2 hover:border-blue-600 hover:no-underline"
70-
: "cursor-pointer mx-4 hover:border-b-2 hover:border-blue-600 hover:text-black hover:no-underline"
67+
? "mx-4 cursor-pointer border-b-2 border-blue-600 hover:border-b-2 hover:border-blue-600 hover:no-underline"
68+
: "mx-4 cursor-pointer hover:border-b-2 hover:border-blue-600 hover:text-black hover:no-underline"
7169
}`}
7270
>
7371
Features
@@ -106,11 +104,8 @@ const Header = () => {
106104
<Chat showChat={showChat} setShowChat={setShowChat} />
107105
</>
108106
</nav>
109-
110-
<span className="text-white mr-72 text-xl font-bold">
111-
Balancer
112-
</span>
113-
107+
108+
<span className="mr-72 text-xl font-bold text-white">Balancer</span>
114109
</div>
115110
<MdNavBar />
116111
</header>

frontend/src/pages/Feedback/FeedbackForm.tsx

Lines changed: 121 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ interface FormValues {
88
name: string;
99
email: string;
1010
message: string;
11-
image: string,
11+
image: string;
1212
}
1313

1414
const FeedbackForm = () => {
1515
const [feedback, setFeedback] = useState("");
1616
const [errorMessage, setErrorMessage] = useState("");
1717
const [isPressed, setIsPressed] = useState(false);
18-
const [selectedImage, setSelectedImage] = useState(null);
18+
const [selectedImage, setSelectedImage] = useState<File | null>(null);
1919

2020
const feedbackValidation = object().shape({
2121
name: string().required("Name is a required field"),
@@ -27,13 +27,12 @@ const FeedbackForm = () => {
2727

2828
// implement useEffect to ensure that submit button causes changes in state
2929
useEffect(() => {
30-
31-
// Update a feedback message div to render after Submit
30+
// Update a feedback message div to render after Submit
3231
const feedbackMessage = document.getElementById("feedback-message");
3332
if (feedbackMessage) {
3433
feedbackMessage.innerText = feedback;
3534
}
36-
35+
3736
// Update an error message div after Submit
3837
const errorMessageDiv = document.getElementById("error-message");
3938
if (errorMessageDiv) {
@@ -42,7 +41,7 @@ const FeedbackForm = () => {
4241
}, [feedback, errorMessage]);
4342

4443
//reset the form fields and states when clicking cancel
45-
const handleCancel =() => {
44+
const handleCancel = () => {
4645
resetForm();
4746
setFeedback("");
4847
setErrorMessage("");
@@ -51,7 +50,7 @@ const FeedbackForm = () => {
5150
const handleMouseDown = () => {
5251
setIsPressed(true);
5352
};
54-
53+
5554
const handleMouseUp = () => {
5655
setIsPressed(false);
5756
};
@@ -89,17 +88,20 @@ const FeedbackForm = () => {
8988
setFeedback("");
9089
try {
9190
// Call 1: Create Feedback request
92-
const response = await axios.post("http://localhost:8000/api/jira/create_new_feedback/", {
93-
name: values.name,
94-
email: values.email,
95-
message: values.message,
96-
},
97-
{
98-
headers: {
99-
"Content-Type": "application/json",
91+
const response = await axios.post(
92+
"http://localhost:8000/api/jira/create_new_feedback/",
93+
{
94+
name: values.name,
95+
email: values.email,
96+
message: values.message,
10097
},
101-
});
102-
98+
{
99+
headers: {
100+
"Content-Type": "application/json",
101+
},
102+
}
103+
);
104+
103105
// check to see if request was successful and get the issue key
104106
if (response.data.status === 201) {
105107
const issueKey = response.data.issueKey;
@@ -143,50 +145,79 @@ const FeedbackForm = () => {
143145
} else {
144146
setErrorMessage("Error uploading the image.");
145147
console.log(response2);
146-
}
148+
}
147149
} else {
148150
setFeedback("Feedback submitted successfully!");
149151
resetForm();
150-
}
151-
} else {
152-
setErrorMessage("Error creating a new feedback request.");
153152
}
154-
} catch (error) {
155-
setErrorMessage("An error occurred while submitting the form");
153+
} else {
154+
setErrorMessage("Error creating a new feedback request.");
155+
}
156+
} catch (error) {
157+
setErrorMessage("An error occurred while submitting the form");
156158
}
157159
},
158160
validationSchema: feedbackValidation,
159161
});
160162

161163
return (
162164
<>
163-
<div className="flex w-[100%] justify-between">
164-
<h2 className="header_logo cursor-pointer font-satoshi text-xl font-bold text-gray-600 hover:text-blue-600 ">
165-
Leave Us Feedback!
166-
</h2>
167-
</div>
165+
<div className="flex w-[100%] justify-between">
166+
<h2 className="header_logo cursor-pointer font-satoshi text-xl font-bold text-gray-600 hover:text-blue-600 ">
167+
Leave Us Feedback!
168+
</h2>
169+
</div>
168170
<section className="mx-auto w-full">
169171
<form onSubmit={handleSubmit} className="mt-2">
170172
<div className="summary_box font_body">
171-
<fieldset className="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
172-
<dt className="flex text-sm font-semibold leading-6 text-gray-900">Feedback Type:</dt>
173-
<dd className="mt-2 pl-24 text-sm text-gray-900 sm:col-span-2 sm:mt-0">
174-
<div className="flex items-center gap-x-3 pr-16">
175-
<input id="feature-request" name="feedback-type" type="radio" className="h-4 w-4 border-gray-300 text-indigo-600 focus:ring-indigo-600" value="Yes" />
176-
<label className="block text-sm font-medium leading-6 text-gray-900" htmlFor="psychotic-yes">
177-
Feature Request
178-
</label>
179-
<input id="bug" name="feedback-type" type="radio" className="h-4 w-4 border-gray-300 text-indigo-600 focus:ring-indigo-600" value="No" />
180-
<label className="block text-sm font-medium leading-6 text-gray-900" htmlFor="psychotic-no">
181-
Bug
182-
</label>
183-
<input id="general-improvements" name="feedback-type" type="radio" className="h-4 w-4 border-gray-300 text-indigo-600 focus:ring-indigo-600" value="No" />
184-
<label className="block text-sm font-medium leading-6 text-gray-900" htmlFor="psychotic-no">
185-
General Improvements
186-
</label>
187-
</div>
188-
</dd>
189-
</fieldset>
173+
<fieldset className="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
174+
<dt className="flex text-sm font-semibold leading-6 text-gray-900">
175+
Feedback Type:
176+
</dt>
177+
<dd className="mt-2 pl-24 text-sm text-gray-900 sm:col-span-2 sm:mt-0">
178+
<div className="flex items-center gap-x-3 pr-16">
179+
<input
180+
id="feature-request"
181+
name="feedback-type"
182+
type="radio"
183+
className="h-4 w-4 border-gray-300 text-indigo-600 focus:ring-indigo-600"
184+
value="Yes"
185+
/>
186+
<label
187+
className="block text-sm font-medium leading-6 text-gray-900"
188+
htmlFor="psychotic-yes"
189+
>
190+
Feature Request
191+
</label>
192+
<input
193+
id="bug"
194+
name="feedback-type"
195+
type="radio"
196+
className="h-4 w-4 border-gray-300 text-indigo-600 focus:ring-indigo-600"
197+
value="No"
198+
/>
199+
<label
200+
className="block text-sm font-medium leading-6 text-gray-900"
201+
htmlFor="psychotic-no"
202+
>
203+
Bug
204+
</label>
205+
<input
206+
id="general-improvements"
207+
name="feedback-type"
208+
type="radio"
209+
className="h-4 w-4 border-gray-300 text-indigo-600 focus:ring-indigo-600"
210+
value="No"
211+
/>
212+
<label
213+
className="block text-sm font-medium leading-6 text-gray-900"
214+
htmlFor="psychotic-no"
215+
>
216+
General Improvements
217+
</label>
218+
</div>
219+
</dd>
220+
</fieldset>
190221
<div className="mb-4">
191222
<fieldset className="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
192223
<dt className="flex text-sm font-semibold leading-6 text-gray-900">
@@ -279,39 +310,38 @@ const FeedbackForm = () => {
279310
</label>
280311
</dt>
281312
<dd className="mt-2 pl-24 text-sm text-gray-900 sm:col-span-2 sm:mt-0">
282-
<div className="relative rounded-xl border-dashed border-2 border-gray-500 p-4 bg-gray-100">
283-
<label
284-
htmlFor="image"
285-
className="cursor-pointer block"
286-
>
287-
<div className="w-32 h-32 mx-auto mb-2">
313+
<div className="relative rounded-xl border-2 border-dashed border-gray-500 bg-gray-100 p-4">
314+
<label htmlFor="image" className="block cursor-pointer">
315+
<div className="mx-auto mb-2 h-32 w-32">
288316
{selectedImage ? (
289317
<>
290-
<img
318+
<img
291319
src={URL.createObjectURL(selectedImage)}
292320
alt="Selected Image"
293-
className="h-full w-full object-cover rounded-lg"
321+
className="h-full w-full rounded-lg object-cover"
294322
/>
295323
<button
296324
type="button"
297325
onClick={(e) => {
298326
e.preventDefault();
299327
setSelectedImage(null);
300-
const fileInput = document.getElementById("image");
328+
const fileInput = document.getElementById(
329+
"image"
330+
) as HTMLInputElement;
301331
if (fileInput) {
302332
fileInput.value = "";
303333
}
304334
}}
305-
className="absolute top-2 right-2 bg-white rounded-full p-1.5 cursor-pointer"
335+
className="absolute right-2 top-2 cursor-pointer rounded-full bg-white p-1.5"
306336
>
307337
X
308338
</button>
309339
</>
310340
) : (
311341
<img
312-
src="../src/assets/upload-image-icon.png"
342+
src="../src/assets/upload-image-icon.png"
313343
alt="Upload Image"
314-
className="h-full w-full object-cover rounded-lg"
344+
className="h-full w-full rounded-lg object-cover"
315345
/>
316346
)}
317347
</div>
@@ -321,9 +351,9 @@ const FeedbackForm = () => {
321351
id="image"
322352
name="image"
323353
onChange={(e) => {
324-
const file = e.target.files?.[0];
354+
const file = e.target.files?.[0];
325355
if (file) {
326-
// Handle the selected file
356+
// Handle the selected file
327357
setSelectedImage(file);
328358
handleChange({
329359
target: {
@@ -333,44 +363,46 @@ const FeedbackForm = () => {
333363
});
334364
}
335365
}}
336-
className="hidden"
366+
className="hidden"
337367
/>
338368
</div>
339369
</dd>
340370
</fieldset>
341371
</div>
342372
<div className="flex items-center justify-end">
343-
<div className="flex w-full justify-end">
373+
<div className="flex w-full justify-end">
374+
<button
375+
type="button"
376+
className="btnGray mr-5"
377+
onClick={handleCancel}
378+
>
379+
Cancel
380+
</button>
381+
</div>
344382
<button
345-
type="button"
346-
className="btnGray mr-5"
347-
onClick={handleCancel}
383+
type="submit"
384+
className={`btnBlue ${
385+
isPressed &&
386+
"transition-transform focus:outline-none focus:ring focus:ring-blue-200"
387+
}${
388+
isLoading
389+
? "bg-white-600 transition-transform focus:outline-none focus:ring focus:ring-blue-500"
390+
: ""
391+
}`}
392+
onMouseDown={handleMouseDown}
393+
onMouseUp={handleMouseUp}
394+
disabled={isLoading}
348395
>
349-
Cancel
396+
{isLoading ? (
397+
<div className="flex items-center justify-center">
398+
<div className="mr-2 h-4 w-4 animate-ping rounded-full bg-white"></div>
399+
<p>Loading...</p>
400+
</div>
401+
) : (
402+
<p>Submit</p>
403+
)}
350404
</button>
351405
</div>
352-
<button
353-
type="submit"
354-
className={`btnBlue ${isPressed &&
355-
"transition-transform focus:outline-none focus:ring focus:ring-blue-200"
356-
}${isLoading
357-
? "bg-white-600 transition-transform focus:outline-none focus:ring focus:ring-blue-500"
358-
: ""
359-
}`}
360-
onMouseDown={handleMouseDown}
361-
onMouseUp={handleMouseUp}
362-
disabled={isLoading}
363-
>
364-
{isLoading ? (
365-
<div className="flex items-center justify-center">
366-
<div className="mr-2 h-4 w-4 animate-ping rounded-full bg-white"></div>
367-
<p>Loading...</p>
368-
</div>
369-
) : (
370-
<p>Submit</p>
371-
)}
372-
</button>
373-
</div>
374406
<div id="feedback-message">{feedback}</div>
375407
<div id="error-message">{errorMessage}</div>
376408
</div>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from django.db import models
2+
from django.contrib.auth.models import User
3+
4+
class RegistrationProfile(models.Model):
5+
user = models.OneToOneField(User, on_delete=models.CASCADE)
6+
activation_key = models.CharField(max_length=40)
7+
8+
def save(self, *args, **kwargs):
9+
# Generate a unique activation key when saving the model
10+
if not self.activation_key:
11+
self.activation_key = self.generate_activation_key()
12+
super(RegistrationProfile, self).save(*args, **kwargs)
13+
14+
def generate_activation_key(self):
15+
# Implement a function to generate a unique activation key (you may use a library like uuid)
16+
# This is a simple example, you may want to customize this based on your requirements
17+
import uuid
18+
return str(uuid.uuid4())

0 commit comments

Comments
 (0)