mirror of
https://github.com/creyD/asiimov.git
synced 2026-06-18 03:30:20 +02:00
Profile and Settings Work
- Added logout button + url - Added redirect urls - Fixed bug where the steam name wouldn't show in template - Added tradeurl to model - Added simple profile - Added ability to change own trade url
This commit is contained in:
@@ -27,7 +27,6 @@ ALLOWED_HOSTS = []
|
|||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'core',
|
'core',
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
@@ -71,7 +70,6 @@ WSGI_APPLICATION = 'asiimov.wsgi.application'
|
|||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
@@ -82,7 +80,6 @@ DATABASES = {
|
|||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||||
@@ -101,7 +98,6 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'en-us'
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'UTC'
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
@@ -119,3 +115,10 @@ STATICFILES_DIRS = [
|
|||||||
|
|
||||||
# Steam API variables
|
# Steam API variables
|
||||||
STEAM_API_KEY = os.environ['STEAM_API_KEY']
|
STEAM_API_KEY = os.environ['STEAM_API_KEY']
|
||||||
|
|
||||||
|
# Redirect for users to login
|
||||||
|
LOGIN_URL = 'signup'
|
||||||
|
# Redirect after login
|
||||||
|
LOGIN_REDIRECT_URL = 'me'
|
||||||
|
# Redirect after logout
|
||||||
|
LOGOUT_REDIRECT_URL = 'home'
|
||||||
|
|||||||
@@ -15,8 +15,10 @@ Including another URLconf
|
|||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
from django.contrib.auth.views import LogoutView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include('core.urls')),
|
path('', include('core.urls')),
|
||||||
path('admin/', admin.site.urls)
|
path('admin/', admin.site.urls),
|
||||||
|
path('logout/', LogoutView.as_view(template_name='logout.html'), name='logout')
|
||||||
]
|
]
|
||||||
|
|||||||
3
src/common/static_files/css/profile.css
Normal file
3
src/common/static_files/css/profile.css
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.content_block{
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
<link rel="stylesheet" href="{% static 'css/master.css' %}">
|
<link rel="stylesheet" href="{% static 'css/master.css' %}">
|
||||||
<!-- JQuery for easier HTML manipulation -->
|
<!-- JQuery for easier HTML manipulation -->
|
||||||
<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
|
<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
|
||||||
|
{% block header %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@@ -22,7 +23,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="right_nav" class="nav_box">
|
<div id="right_nav" class="nav_box">
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<a href="{% url 'offer_create' %}">Add Offer</a> | <a href="{% url 'me_settings' %}">settings</a> | Welcome, <a href="{% url 'me' %}">{{ user.gamer.display_name }}</a>
|
<a href="{% url 'offer_create' %}">Add Offer</a> | <a href="{% url 'me_settings' %}">Settings</a> | Welcome, <a href="{% url 'me' %}">{{ user.gamer.personaname }} <a href="{% url 'logout' %}">(Logout)</a></a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{% url 'signup' %}"><img src="{% static 'pic/steam_sign_in.png' %}" /></a>
|
<a href="{% url 'signup' %}"><img src="{% static 'pic/steam_sign_in.png' %}" /></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
9
src/core/forms.py
Normal file
9
src/core/forms.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Import forms for creating custom template forms
|
||||||
|
from django import forms
|
||||||
|
from .models import Gamer
|
||||||
|
|
||||||
|
|
||||||
|
class ChangeTradeUrl(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Gamer
|
||||||
|
fields = ('tradeurl',)
|
||||||
18
src/core/migrations/0002_gamer_tradeurl.py
Normal file
18
src/core/migrations/0002_gamer_tradeurl.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.0.2 on 2020-01-19 09:15
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='gamer',
|
||||||
|
name='tradeurl',
|
||||||
|
field=models.URLField(max_length=256, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
src/core/migrations/0003_gamer_offer_count.py
Normal file
18
src/core/migrations/0003_gamer_offer_count.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.0.2 on 2020-01-19 09:34
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0002_gamer_tradeurl'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='gamer',
|
||||||
|
name='offer_count',
|
||||||
|
field=models.IntegerField(default=0),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -91,11 +91,14 @@ class Gamer(models.Model):
|
|||||||
timecreated = models.IntegerField(null=True) # Only visible if user has profile visibility
|
timecreated = models.IntegerField(null=True) # Only visible if user has profile visibility
|
||||||
loccountrycode = models.CharField(max_length=2, null=True) # 2 char ISO country code
|
loccountrycode = models.CharField(max_length=2, null=True) # 2 char ISO country code
|
||||||
|
|
||||||
|
tradeurl = models.URLField(max_length=256, null=True)
|
||||||
|
|
||||||
# Asiimov specific information
|
# Asiimov specific information
|
||||||
inventory = models.ManyToManyField(ItemInstance) # Temporary storage of items for improving site performance
|
inventory = models.ManyToManyField(ItemInstance) # Temporary storage of items for improving site performance
|
||||||
API_KEY = models.CharField(max_length=32, null=True) # Optionally use the API KEY of the user
|
API_KEY = models.CharField(max_length=32, null=True) # Optionally use the API KEY of the user
|
||||||
badges = models.ManyToManyField(Badge)
|
badges = models.ManyToManyField(Badge)
|
||||||
system_user = models.OneToOneField(User, on_delete=models.CASCADE)
|
system_user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||||
|
offer_count = models.IntegerField(default=0)
|
||||||
|
|
||||||
|
|
||||||
class Offer(models.Model):
|
class Offer(models.Model):
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ FLOAT_SERVER = 'https://api.csgofloat.com/?url='
|
|||||||
def getUserInfo(steamID, API_KEY=settings.STEAM_API_KEY):
|
def getUserInfo(steamID, API_KEY=settings.STEAM_API_KEY):
|
||||||
QUERY = STEAM_SERVER + USER_METHOD + '/?key=' + str(API_KEY) + '&format=json&steamids=' + str(steamID)
|
QUERY = STEAM_SERVER + USER_METHOD + '/?key=' + str(API_KEY) + '&format=json&steamids=' + str(steamID)
|
||||||
player_object = json.load(urllib.request.urlopen(QUERY))
|
player_object = json.load(urllib.request.urlopen(QUERY))
|
||||||
return player_object
|
return player_object['response']['players'][0]
|
||||||
|
|
||||||
|
|
||||||
# Get the CS:GO inventory of a gamer
|
# Get the CS:GO inventory of a gamer
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
{{ url }}
|
|
||||||
43
src/core/templates/profile/profile.html
Normal file
43
src/core/templates/profile/profile.html
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
{% extends 'master.html' %}
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<!-- Adding custom style sheet for profile-->
|
||||||
|
<link rel="stylesheet" href="{% static 'css/profile.css' %}">
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="content_block">
|
||||||
|
<p><img src="{{ gamer.avatar }}" /></p>
|
||||||
|
<h2>{{ gamer.personaname }} {% if request.user.gamer == gamer %}(Your Profile){% endif %}</h2>
|
||||||
|
|
||||||
|
<h3>Links</h3>
|
||||||
|
<ul>
|
||||||
|
<a href="{{ gamer.profileurl }}" target="_blank"><li>Steam</li></a>
|
||||||
|
<a href="http://csgo.exchange/id/{{ gamer.steamid }}"><li>csgo.exchange</li></a>
|
||||||
|
{% if gamer.tradeurl %}<a href="{{ gamer.tradeurl }}" target="_blank"><li>Trade</li></a>{% endif %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>Info</h3>
|
||||||
|
<p>Steam ID: {{ gamer.steamid }}</p>
|
||||||
|
<p>Profile: {% if gamer.profilestate %}Public Profile{% else %}Private Profile{% endif %}</p>
|
||||||
|
<p>Comments: {% if gamer.commentpermission %}Allowed{% else %}Denied{% endif %}</p>
|
||||||
|
<p>Locale: {% if gamer.loccountrycode %}{{ gamer.loccountrycode }}{% else %}Not provided{% endif %}</p>
|
||||||
|
{% if gamer.API_KEY %}<p style="color: red">This is an API Key Sponsor!</p>{% endif %}
|
||||||
|
|
||||||
|
<h3>Badges</h3>
|
||||||
|
<p>
|
||||||
|
{% for badge in gamer.badges.all %}
|
||||||
|
<img src="{{ badge.icon }}" placeholder="{{ badge.name }}">
|
||||||
|
{% empty %}
|
||||||
|
No badges earned yet.
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>Statistics</h3>
|
||||||
|
<p>Offers created: {{ gamer.offer_count }}</p>
|
||||||
|
<p>Live Offers: {{ live_offers }}</p>
|
||||||
|
<p>Member since: {{ gamer.system_user.date_joined }}</p>
|
||||||
|
<p>Last Login: {{ gamer.system_user.last_login }}</p>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
21
src/core/templates/profile/settings.html
Normal file
21
src/core/templates/profile/settings.html
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{% extends 'master.html' %}
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<!-- Adding custom style sheet for profile-->
|
||||||
|
<link rel="stylesheet" href="{% static 'css/profile.css' %}">
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="content_block">
|
||||||
|
<h2>Settings</h2>
|
||||||
|
<a href="http://steamcommunity.com/id/me/tradeoffers/privacy#trade_offer_access_url" target="_blank">Find your trade URL!</a>
|
||||||
|
{% if gamer.API_KEY %}<a href="{% url 'profile_update' gamer.steamid %}">Synchronize profile from Steam</a>{% endif %}
|
||||||
|
|
||||||
|
<form role="from" method="post" action="{% url 'me_settings' %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<button type="submit">Set Trade URL</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -11,6 +11,7 @@ urlpatterns = [
|
|||||||
path('offers/create', views.offer_create, name='offer_create'),
|
path('offers/create', views.offer_create, name='offer_create'),
|
||||||
path('search/<str:filter>', views.search, name='search'),
|
path('search/<str:filter>', views.search, name='search'),
|
||||||
path('profile/<int:steamID>', views.profile, name='profile'),
|
path('profile/<int:steamID>', views.profile, name='profile'),
|
||||||
|
path('profile/<int:steamID>/update', views.profile_update, name='profile_update'),
|
||||||
path('profile/me', views.me, name='me'),
|
path('profile/me', views.me, name='me'),
|
||||||
path('profile/settings', views.me_settings, name='me_settings'),
|
path('profile/settings', views.me_settings, name='me_settings'),
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ from .steam_api import getUserInfo
|
|||||||
# Import for manually logging in user after creation
|
# Import for manually logging in user after creation
|
||||||
from django.contrib.auth import login
|
from django.contrib.auth import login
|
||||||
|
|
||||||
|
from .forms import ChangeTradeUrl
|
||||||
|
|
||||||
|
|
||||||
# HELPER
|
# HELPER
|
||||||
def validate_steam_login(params):
|
def validate_steam_login(params):
|
||||||
@@ -92,14 +94,14 @@ def signup_confirm(request):
|
|||||||
Gamer.objects.create(
|
Gamer.objects.create(
|
||||||
steamid=claimed_id,
|
steamid=claimed_id,
|
||||||
system_user=new_user,
|
system_user=new_user,
|
||||||
communityvisibilitystate=(True if info['response']['players'][0]['communityvisibilitystate'] == 3 else False),
|
communityvisibilitystate=(True if info['communityvisibilitystate'] == 3 else False),
|
||||||
profilestate=info['response']['players'][0]['profilestate'],
|
profilestate=info['profilestate'],
|
||||||
personaname=info['response']['players'][0]['personaname'],
|
personaname=info['personaname'],
|
||||||
profileurl=info['response']['players'][0]['profileurl'],
|
profileurl=info['profileurl'],
|
||||||
avatar=info['response']['players'][0]['avatar'],
|
avatar=info['avatar'],
|
||||||
commentpermission=info['response']['players'][0]['commentpermission'],
|
commentpermission=info['commentpermission'],
|
||||||
timecreated=info['response']['players'][0]['timecreated'] or None,
|
timecreated=info['timecreated'] or None,
|
||||||
loccountrycode=info['response']['players'][0]['loccountrycode'] or None
|
loccountrycode=info['loccountrycode'] or None
|
||||||
)
|
)
|
||||||
login(request, new_user)
|
login(request, new_user)
|
||||||
return redirect(me)
|
return redirect(me)
|
||||||
@@ -132,16 +134,41 @@ def offer_create(request):
|
|||||||
@login_required
|
@login_required
|
||||||
def profile(request, steamID):
|
def profile(request, steamID):
|
||||||
dude = get_object_or_404(Gamer, steamid=steamID)
|
dude = get_object_or_404(Gamer, steamid=steamID)
|
||||||
return render(request, 'core/profile.html', {'gamer': dude})
|
return render(request, 'profile/profile.html', {'gamer': dude, 'live_offers': Offer.objects.filter(offeror=dude).count()})
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def profile_update(request, steamID):
|
||||||
|
if (request.user.steamid == steamID and request.user.gamer.API_KEY) or request.user.is_staff:
|
||||||
|
the_gamer = get_object_or_404(Gamer, steamid=steamID)
|
||||||
|
info = getUserInfo(steamID, API_KEY=request.user.gamer.API_KEY or None)
|
||||||
|
the_gamer.communityvisibilitystate = (True if info['communityvisibilitystate'] == 3 else False)
|
||||||
|
the_gamer.profilestate = info['profilestate']
|
||||||
|
the_gamer.personaname = info['personaname']
|
||||||
|
the_gamer.profileurl = info['profileurl']
|
||||||
|
the_gamer.avatar = info['avatar']
|
||||||
|
the_gamer.commentpermission = info['commentpermission']
|
||||||
|
if 'timecreated' in info:
|
||||||
|
the_gamer.timecreated = info['timecreated']
|
||||||
|
if 'loccountrycode' in info:
|
||||||
|
the_gamer.loccountrycode = info['loccountrycode']
|
||||||
|
the_gamer.save()
|
||||||
|
return redirect(profile, steamID=steamID)
|
||||||
|
else:
|
||||||
|
return HttpResponseForbidden()
|
||||||
|
|
||||||
# PRIVATE AREA
|
# PRIVATE AREA
|
||||||
@login_required
|
@login_required
|
||||||
def me(request):
|
def me(request):
|
||||||
return render(request, 'core/profile.html', {'gamer': Gamer.objects.get(system_user=request.user)})
|
dude = get_object_or_404(Gamer, steamid=request.user.gamer.steamid)
|
||||||
|
return render(request, 'profile/profile.html', {'gamer': dude, 'live_offers': Offer.objects.filter(offeror=dude).count()})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def me_settings(request):
|
def me_settings(request):
|
||||||
dude = get_object_or_404(Gamer, system_user=request.user)
|
dude = get_object_or_404(Gamer, system_user=request.user)
|
||||||
return render(request, 'core/settings.html', {'gamer': dude})
|
trade_form = ChangeTradeUrl(request.POST or None, instance=dude)
|
||||||
|
if trade_form.is_valid() and request.method == 'POST':
|
||||||
|
dude.tradeurl = trade_form.cleaned_data['trade_url']
|
||||||
|
dude.save()
|
||||||
|
return render(request, 'profile/settings.html', {'gamer': dude, 'form': trade_form})
|
||||||
|
|||||||
Reference in New Issue
Block a user