Skip to content

Commit

Permalink
Fixing some things from prod
Browse files Browse the repository at this point in the history
  • Loading branch information
ariankordi committed Oct 13, 2017
1 parent 812e376 commit d614189
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 38 deletions.
7 changes: 6 additions & 1 deletion closedverse/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('closedverse_main.urls'))
]
]
if True:
import debug_toolbar
urlpatterns = [
url(r'^__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
6 changes: 2 additions & 4 deletions closedverse_main/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ class Meta:
"""

class UserAdmin(admin.ModelAdmin):
#search_fields = ('id', 'unique_id', 'username', 'nickname', 'addr', )
search_fields = ('id', 'unique_id', 'username', 'nickname', 'addr', 'origin_id')
search_fields = ('id', 'unique_id', 'username', 'nickname', 'addr', )
exclude = ('has_mh', )
# Not yet
#form = UserForm

class ProfileAdmin(admin.ModelAdmin):
search_fields = ('id', 'unique_id', )
#search_fields = ('id', 'unique_id', 'origin_id', )
search_fields = ('id', 'unique_id', 'origin_id', )
raw_id_fields = ('user', 'favorite', )

class ComplaintAdmin(admin.ModelAdmin):
Expand Down
49 changes: 35 additions & 14 deletions closedverse_main/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import BaseUserManager
from django.db.models import Q, QuerySet, Max, F
from django.db.models import Q, QuerySet, Max, F, Count
from django.utils import timezone
from django.forms.models import model_to_dict
from django.utils.dateformat import format
Expand All @@ -19,7 +19,7 @@
import re

feelings = ((0, 'normal'), (1, 'happy'), (2, 'wink'), (3, 'surprised'), (4, 'frustrated'), (5, 'confused'), (69, 'easter egg'), )
post_status = ((0, 'ok'), (1, 'delete by user'), (2, 'delete by authority'), (3, 'delete by mod'), (4, 'delete by admin'))
post_status = ((0, 'ok'), (1, 'delete by user'), (2, 'delete by authority'), (3, 'delete by mod'), (4, 'delete by admin'), (5, 'account pruge'))

class UserManager(BaseUserManager):
def create_user(self, username, password):
Expand Down Expand Up @@ -145,15 +145,15 @@ def mh(self):
if not self.profile().origin_info:
return None
try:
infodecode = json.loads(self.origin_info)
infodecode = json.loads(self.profile().origin_info)
except:
return None
return infodecode[0]
def get_class(self):
first = {
1: 'urapp',
2: 'moderator',
3: 'admin',
3: 'administrator',
5: 'openverse',
10: 'developer',
}.get(self.level, '')
Expand Down Expand Up @@ -188,7 +188,7 @@ def online_status(self, force=False):
else:
return True
def do_avatar(self, feeling=0):
if self.has_mh:
if self.has_mh and self.avatar:
feeling = {
0: 'normal',
1: 'happy',
Expand Down Expand Up @@ -385,16 +385,16 @@ def email_in_use(addr, request=None):
if not addr:
return False
if request:
return User.objects.filter(email=addr).exclude(id=request.user.id).exists()
return User.objects.filter(email__iexact=addr).exclude(id=request.user.id).exists()
else:
return User.objects.filter(email=addr).exists()
return User.objects.filter(email__iexact=addr).exists()
def nnid_in_use(id, request=None):
if not id:
return False
if request:
return User.objects.filter(origin_id=id).exclude(id=request.user.id).exists()
return Profile.objects.filter(origin_id__iexact=id).exclude(user__id=request.user.id).exists()
else:
return User.objects.filter(origin_id=id).exists()
return Profile.objects.filter(origin_id=id).exists()
def get_from_passwd(passwd):
try:
user = User.objects.get(password=base64.urlsafe_b64decode(passwd))
Expand Down Expand Up @@ -697,7 +697,7 @@ def change(self, request):
self.body = request.POST['body']
self.spoils = request.POST.get('is_spoiler', False)
self.feeling = request.POST.get('feeling_id', 0)
if not timezone.now() < self.created + timezone.timedelta(minutes=5):
if not timezone.now() < self.created + timezone.timedelta(minutes=2):
self.has_edit = True
return self.save()
def is_favorite(self, user):
Expand Down Expand Up @@ -736,6 +736,16 @@ def setup(self, request):
self.has_yeah = self.has_yeah(request)
self.can_yeah = self.can_yeah(request)
self.is_mine = self.is_mine(request.user)



def max_yeahs():
try:
max_yeahs_post = Post.objects.annotate(num_yeahs=Count('yeah')).aggregate(max_yeahs=Max('num_yeahs'))['max_yeahs']
except:
return None
the_post = Post.objects.annotate(num_yeahs=Count('yeah')).filter(num_yeahs=max_yeahs_post).order_by('-created')
return the_post.first()

class Comment(models.Model):
unique_id = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
Expand Down Expand Up @@ -819,7 +829,7 @@ def change(self, request):
self.body = request.POST['body']
self.spoils = request.POST.get('is_spoiler', False)
self.feeling = request.POST.get('feeling_id', 0)
if not timezone.now() < self.created + timezone.timedelta(minutes=5):
if not timezone.now() < self.created + timezone.timedelta(minutes=2):
self.has_edit = True
return self.save()
def rm(self, request):
Expand Down Expand Up @@ -885,10 +895,10 @@ def origin_id_public(self, user=None):
elif self.id_visibility == 1:
if not Friendship.find_friendship(self.user, user):
return 1
return self.user.origin_id
elif not self.user.origin_id:
return self.origin_id
elif not self.origin_id:
return None
return self.user.origin_id
return self.origin_id
def got_fullurl(self):
if self.weblink:
try:
Expand Down Expand Up @@ -1198,7 +1208,18 @@ class RedFlag(models.Model):

def __str__(self):
return "Report on a " + self.get_type_display() + " for " + self.get_reason_display() + ": " + str(self.reasoning)

# Login attempts: for incorrect passwords
class LoginAttempt(models.Model):
id = models.AutoField(primary_key=True)
created = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(User)
success = models.BooleanField(default=False)
addr = models.CharField(max_length=64, null=True, blank=True)

def __str__(self):
return 'A login attempt to ' + self.user + ' from ' + self.addr + ', ' + str(self.success)

# Fun
class ThermostatTouch(models.Model):
id = models.AutoField(primary_key=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
{% if post.recent_comment %}
<div class="recent-reply-content">
{% if post.comment_count > 1 %}
<div class="recent-reply-read-more-container" data-href="{% url "main:post-view" post.id %}" tabindex="0">
<div class="recent-reply-read-more-container" tabindex="0">
View all comments ({{ post.comment_count }})
</div>
{% endif %}
Expand Down
14 changes: 14 additions & 0 deletions closedverse_main/templates/closedverse_main/help/rules.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ <h2>Repeals</h2>
<p>Unless you're too bad, you can get more chances. If we still don't like your behavior, you'll be returned to the state you were.</p>
<h2>Begging for an unban</h2>
<p>If you only do it in one session, you'll be forgiven. If you do not stop begging an admin for an unban on a separate messaging site, you will be ignored unless you write a beautifully structured repeal asking why you should have an unban.</p>
<br>
<hr>
<h2>Names/branding</h2>
<p>I would not advise making anything fanmade for this or about this unless that's stated.</p>
<h3>What not to call this</h3>
<ul>
<li>ClosedVerse</li>
<li>CV</li>
<li>Openverse</li>
<li>Miiverse/Miiverse 2.0</li>
</ul>
<h3>What to call this</h3>
<p>Closedverse</p><br>
<p>If you do make any fanmade content for or about this, don't expect it to be alive, and be ready for it to be taken down by me only because I don't want that many stuff like that for this, and if I do then it'll be official and not user content.</p>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion closedverse_main/templates/closedverse_main/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-title" content="Closedverse">
<meta name="description" content="Openverse is a social network: designed by PF2M, programmed by Arian Kordi. With Miiverse DNA, style and familiar assets such as Miiverse's interface and Miis, you're sure to have fun here!">
<link rel="shortcut icon" type="image/png" href="{% static "favicon.ico" %}">
<link rel="shortcut icon" type="image/png" href="{% static "img/favicon.png" %}">
<link rel="stylesheet" type="text/css" href="{% static "closedverse.css" %}">
<link id="darkness" {% if request.session.lights %}disabled {% endif %}rel="stylesheet" type="text/css" href="{% static "blueness.css" %}">
<script src="{% static "jslibs.js" %}"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h2 class="label">{{ title }}</h2>
<li class="setting-nnid">
<p class="settings-label">Nintendo Network ID</p>
<div class="icon-container">
<img class="icon nnid-icon mii" src="{% miionly user.avatar user.has_mh %}">
<img class="icon nnid-icon mii" src="{% miionly user.mh %}">
</div>
<input type="text" name="origin_id" minlength="6" maxlength="16" placeholder="Nintendo Network ID{% if not profile.origin_id %} (None){% endif %}" value="{% if profile.origin_id %}{{ profile.origin_id }}{% endif %}" data-action="{% url "main:origin-id-get" %}">
<input type="hidden" name="mh" value="{{ user.mh }}">
Expand All @@ -89,7 +89,7 @@ <h2 class="label">{{ title }}</h2>
</li>
<li class="setting-avatar">
<div class="icon-container">
<img class="icon nnid-icon mii{% if not user.has_mh %} none{% endif %}" src="{% miionly user.avatar user.has_mh %}">
<img class="icon nnid-icon mii{% if not user.has_mh %} none{% endif %}" src="{% miionly user.mh %}">
<img class="icon nnid-icon gravatar{% if user.has_mh %} none{% endif %}" src="{{ user.gravatar }}">
</div>
<p class="settings-label">Do you want the avatar shown beside your content to use the Mii from your Nintendo Network ID or a Gravatar?</p>
Expand Down
6 changes: 3 additions & 3 deletions closedverse_main/templatetags/closedverse_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
def avatar(user, feeling=0):
return user.do_avatar(feeling)
@register.simple_tag
def miionly(avatar, has_mh):
if not avatar or not has_mh:
def miionly(mh):
if not mh:
return settings.STATIC_URL + '/img/anonymous-mii.png'
else:
return 'https://mii-secure.cdn.nintendo.net/{0}_normal_face.png'.format(avatar)
return 'https://mii-secure.cdn.nintendo.net/{0}_normal_face.png'.format(mh)
@register.simple_tag
def time(stamp, full=False):
return HumanTime(stamp.timestamp(), full) or "Less than a minute ago"
Expand Down
10 changes: 5 additions & 5 deletions closedverse_main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@
url(r'messages/'+ username +'$', views.messages_view, name='messages-view'),
url(r'messages/'+ username +'/read$', views.messages_read, name='messages-read'),

# Meta/configuration
# Help/configuration
url(r'lights$', views.set_lighting, name='set-lighting'),
url(r'complaints$', views.help_complaint, name='complaints'),
url(r'server$', views.server_stat, name='server-stat'),
url(r'meta/rules/?$', views.help_rules, name='help-rules'),
url(r'meta/faq/?$', views.help_faq, name='help-faq'),
url(r'meta/legal/?$', views.help_legal, name='help-legal'),
url(r'meta/contact/?', views.help_contact, name='help-contact'),
url(r'help/rules/?$', views.help_rules, name='help-rules'),
url(r'help/faq/?$', views.help_faq, name='help-faq'),
url(r'help/legal/?$', views.help_legal, name='help-legal'),
url(r'help/contact/?', views.help_contact, name='help-contact'),

# Manage
url(r'man/users', views.admin_users, name='admin-users'),
Expand Down
4 changes: 2 additions & 2 deletions closedverse_main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def signup_page(request):
if request.POST['origin_id'].lower() in loads(open(settings.nnid_forbiddens, 'r').read()):
return HttpResponseForbidden("You are very funny. Unfortunately, your funniness blah blah blah fuck off.")
if User.nnid_in_use(request.POST['origin_id']):
return HttpResponseBadRequest("That Nintendo Network ID address is already in use, that would cause confusion.")
return HttpResponseBadRequest("That Nintendo Network ID is already in use, that would cause confusion.")
mii = get_mii(request.POST['origin_id'])
if not mii:
return HttpResponseBadRequest("The NNID provided doesn't exist.")
Expand Down Expand Up @@ -268,7 +268,7 @@ def user_view(request, username):
if User.email_in_use(request.POST.get('email'), request):
return json_response("That email address is already in use, that can't happen.")
if User.nnid_in_use(request.POST.get('origin_id'), request):
return json_response("That Nintendo Network ID address is already in use, that would cause confusion.")
return json_response("That Nintendo Network ID is already in use, that would cause confusion.")
if settings.nnid_forbiddens:
if request.POST['origin_id'].lower() in loads(open(settings.nnid_forbiddens, 'r').read()):
return json_response("You are very funny. Unfortunately, your funniness blah blah blah fuck off.")
Expand Down
3 changes: 1 addition & 2 deletions static/closedverse.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ body {
margin: 0;
padding: 0;
color: #323232;
background: #eeeeee url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwBAMAAADMe/ShAAAAHlBMVEX29vb09PTy8vL19fXz8/Px8fHw8PDv7+/u7u739/dHdNvrAAACSElEQVR4AezYNX7DMBiGcafcKTRlC0hdy7T1Z7iAcS5YOkEl38DeQlNOW24YX63fsxr+Ztm2RmvjMiu2bWbOXPmjtW2A7S8YKlfMCK4lKPzeMoJvYhROHYIJno9gggkmmGCCCSaYYIIJJphgggkmGP/PZQZf4XDHCK5JFFYtE7hXkwWYap0awEMPh8NHA7jPNQprv2EAH5zh8MsTDo9vY/xGxuCeLXFYsVMY7nNZwCm/AcM3scZhnTooPBwfafBYP4JwiZvBfgWDh7Xxkc71DmXjY916hOAbLrMxK7ZuTOfKdxC4ZMf6z1Ui2iEh/2Sdssru8L4dy+zXFVGbuVtntyPxK+cqZRc7wr1Ll0v95/qser1DVZv/yVr5bv10Bczq+ML4Rl/als/ww4WfJptbwuACMbgwhaUVfkvgt6LU1icpdkAAAADAEEz/1EKshHOBgMAnwZ7gNgG9DEwybTKpyZiLRCT6ItqUCJuIYqKoosaJlEsMJBki+ZOElwRfkpqSuElcS9Qnd4LcGN3enRUACMRQDFSDJRzg3wIKuNnNzygYA83rGbx9g1cwGAwGg8FgMBgMBoPBYDAYDAaDwWAwGAwGg8FgMBgMBoPB/bFgfx7ZH4TWJ7DB0W9w5hwcdgen7MHxfp8r9IFGkKQEEU6WHWWhVZaWZTFdlg9mwWSdiAZRbJABB+FzkHoHcXuQ82cDBtlkQzVSkc1yZEMk2fRKNjZTzetkg0LlhJK1KjAYDAaDwWAwGAwGg8FgcAD3L/H6J4DLS/j67eEOl9GYoKbAV2YAAAAASUVORK5CYII=');
}
h1,
h2,
Expand Down Expand Up @@ -207,7 +206,7 @@ body {
margin: auto 0;
text-align: left;
background-color: #f4f4f4;
background-image: url('/s/img/bg-white-dot.png');
background: #eeeeee url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAIAAAC2BqGFAAADF0lEQVR4nO2dwW7bMBAFuRLz/5+bgyWyhwUE13ELtN43EIE3pyQHZj1YUoRMPcX393fT8Hg8zvOcc4rGryUi9n3/+voSjb+Jxm2tbdsWEbrxa4mIbVPa0A1tnrFoCIuGsGgIi4awaAiLhrBoCIuGsGgIi4awaAiLhrBoCIuGsGgIi4awaAiLhrBoCKHoOecqX4E3fbUS0RGxluUkaxZ9c6/q6DnnGEM0uIgxhq456kVnO+fRmYWaOqvNshVNXS96znkcx0JnlC5S9HEcisorRWcjnOd5nmfhsDBX/bV93UtGyZrGGFnl20XjqvsO58Su8l7qzF+zqfd9z0NiJQ1eIzovI1cv/KwsK87zbTcRnTVHxMtF+8V1RJQU3B+Px4eH+66i2zvFWeW2bYVFl/B89Wu/V54/jzHGGCXNMcbo53l+uA/70zRsraXZfd9rp2EJ1ySLiLcTMS1nG30oes7ZdZuw/Ay99+zl+yhOsp7s1og4jqP9Ycn++ff/QHuvI3u53amRX8jCrjp1qETnitF7v8+i/BeeZ57oX6judaToG64Yb8nth/Ryrerom2zj/gnp0xXCpWOVdk6yqZdcOhQjq1lv6TAvWDSERUNYNIRFQ1g0hEVDWDSERUNYNIRFQ1g0hEVDWDSERUNYNIRFQ1g0hEVDWDSERUNYNIRFQ1g0hEVDWDSERUNYNIRFQ1g0hEVDWDSERUNYNIRFQ1g0hEVDWDSERUNYNIRFQ1g0hEVDSESvFS34jK5yYWSmLudTgTpPVSVamvMpQpqnKlw6dDmf5QB5qsKlQ5fzWQ6Qp6rddYhyPgvB8lT755krfM5nCWSe6pyzXwo+GQXO+SyBzFMdY/SSd7uTOZ8lwHmq+77XpO2SOZ8l8HmqNaLhnE8dujzVyl0HlvMpRZSnKnmZgjrnU4Q0T1XyMgV1zqcCdZ6qMDJTl/MpQrojUt3rWKudE2meqrDp1nKtrnax2b0uFg1h0RAWDWHREBYNYdEQFg1h0RAWDWHREBYNYdEQFg1h0RAWDWHREBYNYdEQFg0hFL3W0xXS5ypaa78A+zg9ngAQ62UAAAAASUVORK5CYII=');
background-attachment: fixed;
}
#sub-body {
Expand Down
7 changes: 4 additions & 3 deletions static/closedverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2118,8 +2118,10 @@ var Olv = Olv || {};
n: {},
msg: {}
}, function(b, c) {
// If the response isn't blank..
if(b) {
// If the response is blank, set both of the counts as 0.
if(!b) {
b = [unescape('\x00'), unescape('\x00')];
}
// Notification
var d = a("#global-menu-news")
, e = d.find(".badge");
Expand All @@ -2143,7 +2145,6 @@ var Olv = Olv || {};
j += b[1].charCodeAt()
h.text(j),
h.toggle(j > 0)
}
}),
a(document).on("pjax:complete", function(a) {
c.resetInterval()
Expand Down

0 comments on commit d614189

Please sign in to comment.