def register(request): """ returns success_message, error_message """ #if request.POST['username'] and request.POST['userpass'] and request.POST['userconfirmpass'] and request.POST['useremail']: try: newUsername = request.POST['username'] newUserpass = sha512(str(request.POST['userpass']).encode('utf-8')).hexdigest() newUseremail = request.POST['useremail'] #if request.POST['userpass'] == request['userconfirmpass']: # This should be checked by JavaScript first; this is a backup # Would normally sanitize input before saving model try: NewUser = User(name=newUsername, passwordHash=newUserpass, regDate=datetime.now(), goldMember=False, email=newUseremail) NewUser.save() print("Mwahaha") return HttpResponseRedirect(reverse('kslpages:index')) except: print("Blahblahblah") return render_to_response('register.html', {'error_message': "Could not register new user. That name is already taken."}, context_instance=RequestContext(request)) except (KeyError): print("Oh well") return render_to_response('register.html', context_instance=RequestContext(request))
def popdb(request): """ Bad population function, run multiple times to continue filling """ from kslpages.models import User from random import randint # randint(a, b) from datetime import datetime namelist = ['Bob', 'Sally', 'Mary', 'Billy', 'Tom', 'Harry', 'Ken', 'Bill', 'Ted', 'Heisenberg', 'Adama', 'Wil Wheaton', 'Picard'] fakesalt = 'paoutgpoanegfponadfgniapibgnfpianfg' result = [] for i in range(300): name = namelist[randint(0,len(namelist)-1)]+str(randint(0,300)) email = name+'@google.com' regDate = datetime.now() passwordHash = sha512((str(name)+str(fakesalt)).encode('utf-8')).hexdigest() blah = User(name=name, email=email, regDate=regDate, goldMember=True, passwordHash=passwordHash) result.append([name, email, regDate, passwordHash, 'END']) blah.save() return 'All Done! ' + str(result)
from kslpages.models import User from random import randint # randint(a, b) from datetime import datetime from hashlib import sha512 namelist = ['Bob', 'Sally', 'Mary', 'Billy', 'Tom', 'Harry', 'Ken', 'Bill', 'Ted', 'Heisenberg', 'Adama', 'Wil Wheaton', 'Picard'] fakesalt = 'xd&^+93_09v+zaa%%q=%y7g9^%9=b8rxxh3' for i in range(300): name = namelist[randint(0,len(namelist))] email = name+'@google.com' regDate = datetime.now() passwordHash = sha512(name+fakesalt.encode('utf-8').hexdigest()) blah = User(name=name, email=email, regDate=regDate, goldMember=True, passwordHash=passwordHash) print [name, email, regDate, passwordHash] blah.save()