Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
Ensure that account username is unique
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmcbrayer committed Aug 28, 2018
1 parent cd4acab commit 283b94c
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions brutaldon/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
class NotLoggedInException(Exception):
pass

class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]

def get_usercontext(request):
if is_logged_in(request):
try:
Expand Down Expand Up @@ -148,8 +141,10 @@ def login(request):
if tmp_base.netloc == '':
api_base_url = parse.urlunparse(('https', tmp_base.path,
'','','',''))
request.session['instance_hostname'] = tmp_base.path
else:
api_base_url = api_base_url.lower()
request.session['instance_hostname'] = tmp_base.netloc

request.session['instance'] = api_base_url
try:
Expand Down Expand Up @@ -210,8 +205,8 @@ def oauth_callback(request):
client = Client.objects.get(api_base_id=request.session['instance']),
preferences = preferences)
request.session['user'] = user
request.session['username'] = user.username
account.username = user.username
request.session['username'] = user.username + '@' + request.session['instance_hostname']
account.username = user.username + '@' + request.session['instance_hostname']
account.save()
return redirect(home)

Expand All @@ -229,8 +224,10 @@ def old_login(request):
if tmp_base.netloc == '':
api_base_url = parse.urlunparse(('https', tmp_base.path,
'','','',''))
request.session['instance_hostname'] = tmp_base.path
else:
api_base_url = api_base_url.lower()
request.session['instance_hostname'] = tmp_base.netloc

request.session['instance'] = api_base_url
email = form.cleaned_data['email']
Expand Down Expand Up @@ -270,8 +267,8 @@ def old_login(request):
account.access_token = access_token
user = mastodon.account_verify_credentials()
request.session['user'] = user
request.session['username'] = user.username
account.username = user.username
request.session['username'] = user.username + '@' + request.session['instance_hostname']
account.username = request.session['username']
request.session['timezone'] = account.preferences.timezone;
account.save()
return redirect(home)
Expand Down

0 comments on commit 283b94c

Please sign in to comment.