mirror of https://gitlab.com/brutaldon/brutaldon
Ensure that account username is unique
This commit is contained in:
parent
cd4acab7c2
commit
283b94cd53
|
@ -14,13 +14,6 @@ from pdb import set_trace
|
||||||
class NotLoggedInException(Exception):
|
class NotLoggedInException(Exception):
|
||||||
pass
|
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):
|
def get_usercontext(request):
|
||||||
if is_logged_in(request):
|
if is_logged_in(request):
|
||||||
try:
|
try:
|
||||||
|
@ -148,8 +141,10 @@ def login(request):
|
||||||
if tmp_base.netloc == '':
|
if tmp_base.netloc == '':
|
||||||
api_base_url = parse.urlunparse(('https', tmp_base.path,
|
api_base_url = parse.urlunparse(('https', tmp_base.path,
|
||||||
'','','',''))
|
'','','',''))
|
||||||
|
request.session['instance_hostname'] = tmp_base.path
|
||||||
else:
|
else:
|
||||||
api_base_url = api_base_url.lower()
|
api_base_url = api_base_url.lower()
|
||||||
|
request.session['instance_hostname'] = tmp_base.netloc
|
||||||
|
|
||||||
request.session['instance'] = api_base_url
|
request.session['instance'] = api_base_url
|
||||||
try:
|
try:
|
||||||
|
@ -210,8 +205,8 @@ def oauth_callback(request):
|
||||||
client = Client.objects.get(api_base_id=request.session['instance']),
|
client = Client.objects.get(api_base_id=request.session['instance']),
|
||||||
preferences = preferences)
|
preferences = preferences)
|
||||||
request.session['user'] = user
|
request.session['user'] = user
|
||||||
request.session['username'] = user.username
|
request.session['username'] = user.username + '@' + request.session['instance_hostname']
|
||||||
account.username = user.username
|
account.username = user.username + '@' + request.session['instance_hostname']
|
||||||
account.save()
|
account.save()
|
||||||
return redirect(home)
|
return redirect(home)
|
||||||
|
|
||||||
|
@ -229,8 +224,10 @@ def old_login(request):
|
||||||
if tmp_base.netloc == '':
|
if tmp_base.netloc == '':
|
||||||
api_base_url = parse.urlunparse(('https', tmp_base.path,
|
api_base_url = parse.urlunparse(('https', tmp_base.path,
|
||||||
'','','',''))
|
'','','',''))
|
||||||
|
request.session['instance_hostname'] = tmp_base.path
|
||||||
else:
|
else:
|
||||||
api_base_url = api_base_url.lower()
|
api_base_url = api_base_url.lower()
|
||||||
|
request.session['instance_hostname'] = tmp_base.netloc
|
||||||
|
|
||||||
request.session['instance'] = api_base_url
|
request.session['instance'] = api_base_url
|
||||||
email = form.cleaned_data['email']
|
email = form.cleaned_data['email']
|
||||||
|
@ -270,8 +267,8 @@ def old_login(request):
|
||||||
account.access_token = access_token
|
account.access_token = access_token
|
||||||
user = mastodon.account_verify_credentials()
|
user = mastodon.account_verify_credentials()
|
||||||
request.session['user'] = user
|
request.session['user'] = user
|
||||||
request.session['username'] = user.username
|
request.session['username'] = user.username + '@' + request.session['instance_hostname']
|
||||||
account.username = user.username
|
account.username = request.session['username']
|
||||||
request.session['timezone'] = account.preferences.timezone;
|
request.session['timezone'] = account.preferences.timezone;
|
||||||
account.save()
|
account.save()
|
||||||
return redirect(home)
|
return redirect(home)
|
||||||
|
|
Loading…
Reference in New Issue