Exemplo n.º 1
0
def register(request, template_name='registration/register.html'):
    profile_url = settings.USER_PROFILE_URL % 'username'
    if request.method == 'GET':
        form = RegistrationForm()
    else:  # POST
        form = RegistrationForm(data=request.POST)
        if form.is_valid():
            hn_username = form.cleaned_data['hn_username']
            # user_data is a dict containing the users HN account creation
            # date, karma at query time, and HN profile
            user_data = retrieve_hn_user_data(hn_username)
            # form validation checks that hn_username matches what's provided
            # and that the "key" (a url) is in the profile
            temp_password = ''.join(random.sample(string.letters, 16))
            new_user = User.objects.create_user(username=hn_username,
                                                email='',
                                                password=temp_password)
            user = authenticate(username=new_user.username,
                                password=temp_password)

            if user is not None:
                login(request, user)
                messages.success(request,
                                 'That worked. Please provide a password.')
                return HttpResponseRedirect(reverse('set_password'))
    return render_to_response(template_name,
                              locals(),
                              context_instance=RequestContext(request))
Exemplo n.º 2
0
def register(request, template_name='registration/register.html'):
    profile_url = settings.USER_PROFILE_URL % 'username'
    if request.method == 'GET':
        form = RegistrationForm()
    else: # POST
        form = RegistrationForm(data=request.POST)
        if form.is_valid():
            hn_username = form.cleaned_data['hn_username']
            # user_data is a dict containing the users HN account creation
            # date, karma at query time, and HN profile
            user_data = retrieve_hn_user_data(hn_username)
            # form validation checks that hn_username matches what's provided
            # and that the "key" (a url) is in the profile
            temp_password = ''.join(random.sample(string.letters, 16))
            new_user = User.objects.create_user(username=hn_username,
                                                email='',
                                                password=temp_password)
            user = authenticate(username=new_user.username,
                                password=temp_password)
            
            if user is not None:
                login(request, user)
                messages.success(request, 'That worked. Please provide a password.')
                return HttpResponseRedirect(reverse('set_password'))
    return render_to_response(template_name, locals(),
                              context_instance=RequestContext(request))
Exemplo n.º 3
0
 def clean_hn_username(self):
     hn_username = self.cleaned_data['hn_username']
     hnoh_profile =  settings.USER_PROFILE_URL % hn_username
     try:
         user_data = retrieve_hn_user_data(hn_username)
     except:
         errormsg = "%s does not appear to be a registered HN username" % hn_username
         raise forms.ValidationError(errormsg)
     if not hnoh_profile in user_data["about"]:
         raise forms.ValidationError('The url does not appear to be in your hn profile. Please paste %s into your hn profile. Note the trailing slash.' % hnoh_profile)
     if User.objects.filter(username=hn_username).count() > 0:
         errormsg = 'User "%s" already has an account' % hn_username
         raise forms.ValidationError(errormsg)
     return hn_username
Exemplo n.º 4
0
 def clean_hn_username(self):
     hn_username = self.cleaned_data['hn_username']
     hnoh_profile = settings.USER_PROFILE_URL % hn_username
     try:
         user_data = retrieve_hn_user_data(hn_username)
     except:
         errormsg = "%s does not appear to be a registered HN username" % hn_username
         raise forms.ValidationError(errormsg)
     if not hnoh_profile in user_data["about"]:
         raise forms.ValidationError(
             'The url does not appear to be in your hn profile. Please paste %s into your hn profile. Note the trailing slash.'
             % hnoh_profile)
     if User.objects.filter(username=hn_username).count() > 0:
         errormsg = 'User "%s" already has an account' % hn_username
         raise forms.ValidationError(errormsg)
     return hn_username