Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
go
Project
Project
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
21
Issues
21
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SRCT
go
Commits
70fcd31c
Commit
70fcd31c
authored
Dec 11, 2018
by
David Haynes
🙆
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'go-three' into gothree-frontend
parents
a6bc3252
e2691fd0
Pipeline
#3457
passed with stage
in 1 minute and 12 seconds
Changes
7
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
1146 additions
and
1306 deletions
+1146
-1306
Pipfile
Pipfile
+1
-0
Pipfile.lock
Pipfile.lock
+97
-62
go/go_ahead/src/AuthButton.jsx
go/go_ahead/src/AuthButton.jsx
+49
-0
go/go_ahead/templates/index.html
go/go_ahead/templates/index.html
+16
-27
go/go_back/urls.py
go/go_back/urls.py
+7
-8
go/go_back/views.py
go/go_back/views.py
+22
-9
yarn.lock
yarn.lock
+954
-1200
No files found.
Pipfile
View file @
70fcd31c
...
...
@@ -7,6 +7,7 @@ name = "pypi"
pylint
=
"*"
pylint-django
=
"*"
coverage
=
"*"
black
=
"*"
[packages]
django
=
"<2.1,>=2.0"
...
...
Pipfile.lock
View file @
70fcd31c
This diff is collapsed.
Click to expand it.
go/go_ahead/src/AuthButton.jsx
0 → 100644
View file @
70fcd31c
import
React
from
"
react
"
;
import
{
Button
}
from
"
reactstrap
"
;
class
AuthButton
extends
React
.
Component
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
error
:
null
,
is_auth
:
false
};
}
componentDidMount
()
{
fetch
(
"
/auth/status
"
)
.
then
(
res
=>
res
.
json
())
.
then
(
result
=>
{
this
.
setState
({
is_auth
:
result
.
is_authenticated
});
},
error
=>
{
this
.
setState
({
error
});
}
);
}
render
()
{
const
{
is_auth
,
error
}
=
this
.
state
;
if
(
error
)
{
return
<
div
>
Error:
{
error
.
message
}
</
div
>;
}
else
{
return
(
<
div
>
{
is_auth
?
(
<
Button
color=
"info"
href=
"/auth/logout"
>
Logout
</
Button
>
)
:
(
<
Button
color=
"info"
href=
"/auth/login"
>
Login
</
Button
>
)
}
</
div
>
);
}
}
}
export
default
AuthButton
;
go/go_ahead/templates/index.html
View file @
70fcd31c
{% load static %}
<html>
<head>
<meta
charset=
"utf-8"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta
name=
"theme-color"
content=
"#006633"
/>
<meta
name=
"description"
content=
"University-branded URL shortening"
/>
<title>
Welcome
•
SRCT Go
</title>
</head>
<head>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, shrink-to-fit=no"
>
<meta
name=
"theme-color"
content=
"#006633"
/>
<meta
name=
"description"
content=
"University-branded URL shortening"
/>
<title>
Welcome
•
SRCT Go
</title>
</head>
<body>
<!-- React injects itself here -->
<div
id=
"root"
></div>
</body>
<body>
<!-- React injects itself here -->
<div
id=
"root"
></div>
</body>
<script>
window
.
django
=
{
logout
:
"
{% url
"
cas_logout
"
%}
"
,
user
:
{
username
:
"
{{ request.user.username }}
"
,
full_name
:
"
{{ request.user.get_full_name }}
"
,
last_login
:
"
{{ request.user.last_login }}
"
,
is_authenticated
:
"
{{ request.user.is_authenticated }}
"
}
};
</script>
<script
src=
"static/main.js"
></script>
</html>
\ No newline at end of file
<script
src=
"static/main.js"
></script>
</html>
go/go_back/urls.py
View file @
70fcd31c
...
...
@@ -4,17 +4,15 @@ settings/urls.py
The URLs of the project and their associated view that requests are routed to.
"""
# Django Imports
from
django.urls
import
path
,
re_path
,
include
from
django.urls
import
path
,
include
from
django.contrib
import
admin
from
django.views.decorators.cache
import
cache_page
from
django.views.generic
import
TemplateView
# App Imports
from
.
import
views
from
cas
import
views
as
cas_views
# Third Party
from
rest_framework
import
routers
from
cas
import
views
as
cas_views
# App Imports
from
.
import
views
router
=
routers
.
DefaultRouter
()
router
.
register
(
r"golinks"
,
views
.
URLViewSet
,
base_name
=
"golinks"
)
...
...
@@ -32,7 +30,8 @@ urlpatterns = [
# /admin - Administrator interface.
path
(
"admin/"
,
admin
.
site
.
urls
,
name
=
"go_admin"
),
path
(
"auth/"
,
include
(
"rest_framework.urls"
)),
path
(
"auth/token/"
,
views
.
CustomAuthToken
.
as_view
())
path
(
"auth/token/"
,
views
.
CustomAuthToken
.
as_view
()),
path
(
"auth/status/"
,
views
.
GetSessionInfo
.
as_view
())
# # /view/<short> - View URL data. Cached for 15 minutes
# re_path(r'^view/(?P<short>([\U00010000-\U0010ffff][\U0000200D]?)+)$',
# cache_page(60 * 15)(go.views.view), name='view'),
...
...
go/go_back/views.py
View file @
70fcd31c
...
...
@@ -4,15 +4,16 @@ go/views.py
The functions that handle a request to a given URL. Get some data, manipulate
it, and return a rendered template.
"""
from
rest_framework
import
viewsets
from
rest_framework
import
permissions
from
rest_framework
import
viewsets
,
permissions
from
rest_framework.authentication
import
TokenAuthentication
,
SessionAuthentication
from
.serializers
import
URLSerializer
from
.models
import
URL
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
rest_framework.authtoken.models
import
Token
from
rest_framework.permissions
import
IsAuthenticated
from
rest_framework.authtoken.views
import
ObtainAuthToken
from
.serializers
import
URLSerializer
from
.models
import
URL
class
URLPermission
(
permissions
.
BasePermission
):
...
...
@@ -46,11 +47,6 @@ class URLViewSet(viewsets.ModelViewSet):
serializer
.
save
(
owner
=
self
.
request
.
user
.
registereduser
)
from
rest_framework.authtoken.views
import
ObtainAuthToken
from
rest_framework.authtoken.models
import
Token
from
rest_framework.response
import
Response
class
CustomAuthToken
(
ObtainAuthToken
):
authentication_classes
=
(
SessionAuthentication
,)
permission_classes
=
(
IsAuthenticated
,)
...
...
@@ -59,3 +55,20 @@ class CustomAuthToken(ObtainAuthToken):
token
,
created
=
Token
.
objects
.
get_or_create
(
user
=
request
.
user
)
return
Response
({
"token"
:
token
.
key
})
class
GetSessionInfo
(
APIView
):
"""Handy endpoint to return current user session status & information to the frontend."""
authentication_classes
=
(
SessionAuthentication
,)
permission_classes
=
(
IsAuthenticated
,)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
token
,
created
=
Token
.
objects
.
get_or_create
(
user
=
request
.
user
)
session_info
=
{
"username"
:
request
.
user
.
username
,
# "full_name": f"{request.user.get_full_name}",
"last_login"
:
request
.
user
.
last_login
,
"is_authenticated"
:
request
.
user
.
is_authenticated
,
"token"
:
token
.
key
,
}
return
Response
(
session_info
)
yarn.lock
View file @
70fcd31c
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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