def create(request,team_id=None): if request.method == 'POST': # If the form has been submitted... form = CreateUserForm(request.POST) # A form bound to the POST data if form.is_valid(): newuser = User() newuser.username = form.cleaned_data['username'] newuser.first_name = form.cleaned_data['firstName'] newuser.last_name = form.cleaned_data['lastName'] newuser.email = form.cleaned_data['email'] newuser.set_password(form.cleaned_data['password']) newuser.save() newuser.groups.add(form.cleaned_data['group']) newuser.save() newprofile = UserProfile() newprofile.email = form.cleaned_data['email'] newprofile.club = form.cleaned_data['club'] newprofile.team = form.cleaned_data['team'] newprofile.phone = form.cleaned_data['phone'] newprofile.user = newuser newprofile.save() return HttpResponseRedirect('/accounts/detail/%d' % newuser.id) else: form = CreateUserForm() # An unbound form if team_id: team = Team.objects.get(id=team_id) form = CreateUserForm(club_id=team.club.id,team_id=team.id) return render_to_response('core/user_form.html', { 'form': form, 'user': request.user })
user = User() invitation = Invitation.objects.get(key = key) user.username = form.cleaned_data['username'] name = invitation.name.split(' ') user.first_name = name[0] user.last_name = name[1] user.email = invitation.email user.set_password(form.cleaned_data['password']) user.is_active = False user.save() user.groups.add(invitation.group) user.save() userProfile = UserProfile() userProfile.user = user userProfile.team = invitation.team userProfile.club = invitation.club userProfile.email = invitation.email userProfile.save() # mark invitation as used invitation.used = True invitation.save() # generate confirmation email hash = hashlib.sha256() # TODO: un-hardcode salt hash.update("confirmation_%s_%s" % (userProfile.id, "hockeypuck")) userProfile.confirmation = hash.hexdigest() userProfile.confirmed = False userProfile.save()