Skip to content

Commit

Permalink
loginok
Browse files Browse the repository at this point in the history
  • Loading branch information
dwsds committed Nov 2, 2023
1 parent cc5f839 commit 84108f9
Show file tree
Hide file tree
Showing 21 changed files with 23 additions and 7 deletions.
Binary file modified app1/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file modified app1/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified app1/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file modified app1/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file modified app1/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file modified app1/__pycache__/forms.cpython-311.pyc
Binary file not shown.
Binary file modified app1/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file modified app1/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified app1/__pycache__/views.cpython-311.pyc
Binary file not shown.
Binary file modified app1/migrations/__pycache__/0001_initial.cpython-311.pyc
Binary file not shown.
Binary file modified app1/migrations/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
3 changes: 1 addition & 2 deletions app1/templates/app1/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ <h1>Sign Up</h1>
<label for="password">Password:</label>
<input type="password" name="password" id="password" required><br><br>

<label for="password_confirm">Confirm Password:</label>
<input type="password" name="password_confirm" id="password_confirm" required><br><br>


<button type="submit">Sign Up</button>
</form>
Expand Down
2 changes: 2 additions & 0 deletions app1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
path('illness-form/', views.illness_form, name='illness_form'),
path('login/', views.login_view, name='login'),
path('signup/', views.signup, name='signup'),
path('home/', views.homepage, name='home'),

]
25 changes: 20 additions & 5 deletions app1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ def illness_form(request):
'physical_form': physical_form,
})

from django.contrib.auth.forms import AuthenticationForm




def login_view(request):
if request.method == 'POST':
Expand All @@ -213,24 +215,37 @@ def login_view(request):

if user is not None:
login(request, user)
# Redirect to a success page or home page
return redirect('home')
return redirect('app1:home') # Always redirect to the 'home' page on successful login
else:
# Handle authentication failure
form.add_error(None, "Please enter a valid username and password.")
else:
form = CustomLoginForm()

return render(request, 'app1/login.html', {'form': form})


def signup(request):
if request.method == 'POST':
form = CustomUserCreationForm(request.POST)
if form.is_valid():
print("Form is valid") # Print a message to indicate form validity

user = form.save()
print("User created:", user) # Print the user object

login(request, user)
return redirect('login') # Redirect to the homepage after signup
print("User logged in")

return redirect('app1:login') # Redirect to the login page after signup
else:
print("Form is invalid. Errors:", form.errors) # Print form validation errors

else:
form = CustomUserCreationForm()

return render(request, 'app1/signup.html', {'form': form})
return render(request, 'app1/signup.html', {'form': form})


def homepage(request):
return render(request, 'app1/home.html')
Binary file modified project1/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file modified project1/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified project1/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file modified project1/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file modified project1/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified project1/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified project1/__pycache__/wsgi.cpython-311.pyc
Binary file not shown.

0 comments on commit 84108f9

Please sign in to comment.