Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
red_brick_board
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ciella Francisco
red_brick_board
Commits
24dcbd38
Commit
24dcbd38
authored
Mar 09, 2024
by
gab
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created accounts app for logins
parent
56cde85d
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
144 additions
and
0 deletions
+144
-0
__init__.py
redbrickboard/accounts/__init__.py
+0
-0
apps.py
redbrickboard/accounts/apps.py
+6
-0
backends.py
redbrickboard/accounts/backends.py
+15
-0
forms.py
redbrickboard/accounts/forms.py
+29
-0
models.py
redbrickboard/accounts/models.py
+15
-0
login.html
redbrickboard/accounts/templates/accounts/login.html
+10
-0
register.html
redbrickboard/accounts/templates/accounts/register.html
+10
-0
tests.py
redbrickboard/accounts/tests.py
+3
-0
urls.py
redbrickboard/accounts/urls.py
+11
-0
views.py
redbrickboard/accounts/views.py
+45
-0
No files found.
redbrickboard/accounts/__init__.py
0 → 100644
View file @
24dcbd38
redbrickboard/accounts/apps.py
0 → 100644
View file @
24dcbd38
from
django.apps
import
AppConfig
class
AccountsConfig
(
AppConfig
):
default_auto_field
=
'django.db.models.BigAutoField'
name
=
'accounts'
redbrickboard/accounts/backends.py
0 → 100644
View file @
24dcbd38
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth.backends
import
ModelBackend
class
EmailBackend
(
ModelBackend
):
def
authenticate
(
self
,
request
,
email
,
password
,
**
kwargs
):
UserModel
=
get_user_model
()
try
:
user
=
UserModel
.
objects
.
get
(
email
=
email
)
except
UserModel
.
DoesNotExist
:
return
None
else
:
if
user
.
check_password
(
password
):
return
user
return
None
\ No newline at end of file
redbrickboard/accounts/forms.py
0 → 100644
View file @
24dcbd38
from
django.contrib.auth.forms
import
UserCreationForm
,
AuthenticationForm
from
.models
import
CustomUser
from
django
import
forms
from
django.forms.widgets
import
PasswordInput
,
EmailInput
# Authenticate a User // Login
class
CustomUserAuthenticationForm
(
AuthenticationForm
):
email
=
forms
.
EmailField
(
widget
=
forms
.
EmailInput
(
attrs
=
{
'autofocus'
:
True
}))
password
=
forms
.
CharField
(
widget
=
PasswordInput
())
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
CustomUserAuthenticationForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
'email'
]
.
required
=
True
self
.
fields
.
pop
(
'username'
)
self
.
order_fields
([
'email'
,
'password'
])
# Registering a User Form
class
CustomUserCreationForm
(
UserCreationForm
):
class
Meta
:
model
=
CustomUser
fields
=
[
"email"
,
"first_name"
,
"last_name"
,
"password1"
,
"password2"
]
# class CustomUserChangeForm(UserChangeForm):
# class Meta:
# model = CustomUser
# fields = ("username", "email")
\ No newline at end of file
redbrickboard/accounts/models.py
0 → 100644
View file @
24dcbd38
from
django.db
import
models
from
django.contrib.auth.models
import
AbstractUser
# Create your models here.
class
CustomUser
(
AbstractUser
):
username
=
None
email
=
models
.
EmailField
(
unique
=
True
,
db_index
=
True
)
first_name
=
models
.
CharField
(
blank
=
False
,
max_length
=
150
)
last_name
=
models
.
CharField
(
blank
=
False
,
max_length
=
150
)
USERNAME_FIELD
=
'email'
REQUIRED_FIELDS
=
[]
def
__str__
(
self
):
return
self
.
first_name
\ No newline at end of file
redbrickboard/accounts/templates/accounts/login.html
0 → 100644
View file @
24dcbd38
{% extends "base.html" %}
{% block content %}
<form
method=
"POST"
autocomplete=
"off"
>
{% csrf_token %}
{{ loginform.as_p }}
<input
type=
"submit"
value=
"Log In"
/>
</form>
{% endblock %}
\ No newline at end of file
redbrickboard/accounts/templates/accounts/register.html
0 → 100644
View file @
24dcbd38
{% extends "base.html" %}
{% block content %}
<form
method=
"POST"
autocomplete=
"off"
>
{% csrf_token %}
{{ registerform.as_p }}
<input
type=
"submit"
value=
"Register"
/>
</form>
{% endblock %}
\ No newline at end of file
redbrickboard/accounts/tests.py
0 → 100644
View file @
24dcbd38
from
django.test
import
TestCase
# Create your tests here.
redbrickboard/accounts/urls.py
0 → 100644
View file @
24dcbd38
from
django.urls
import
path
from
.
import
views
app_name
=
"accounts"
urlpatterns
=
[
path
(
'login'
,
views
.
login_page
,
name
=
"login"
),
path
(
'register'
,
views
.
register
,
name
=
"register"
),
path
(
'logout'
,
views
.
user_logout
,
name
=
"logout"
)
]
\ No newline at end of file
redbrickboard/accounts/views.py
0 → 100644
View file @
24dcbd38
from
django.shortcuts
import
render
,
redirect
from
django.http
import
HttpResponse
from
.forms
import
CustomUserCreationForm
,
CustomUserAuthenticationForm
from
django.contrib.auth.models
import
auth
from
django.contrib.auth
import
authenticate
,
login
,
logout
def
register
(
request
):
# return HttpResponse("I am in Register")
form
=
CustomUserCreationForm
()
if
request
.
method
==
"POST"
:
form
=
CustomUserCreationForm
(
request
.
POST
)
if
form
.
is_valid
():
form
.
save
()
return
redirect
(
"index"
)
context
=
{
'registerform'
:
form
,
}
return
render
(
request
,
'accounts/register.html'
,
context
=
context
)
def
login_page
(
request
):
form
=
CustomUserAuthenticationForm
()
if
request
.
method
==
"POST"
:
form
=
CustomUserAuthenticationForm
(
request
,
data
=
request
.
POST
)
if
form
.
is_valid
():
email
=
request
.
POST
.
get
(
'email'
)
password
=
request
.
POST
.
get
(
'password'
)
user
=
authenticate
(
request
,
email
=
email
,
password
=
password
)
if
user
is
not
None
:
auth
.
login
(
request
,
user
)
return
redirect
(
"index"
)
context
=
{
'loginform'
:
form
}
return
render
(
request
,
'accounts/login.html'
,
context
=
context
)
def
user_logout
(
request
):
auth
.
logout
(
request
)
return
redirect
(
"index"
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment