Exemplo n.º 1
0
def signup(request, template_name='signup.html', *args, **kwargs):
    me = 'people'
    error = pop_error(request)
    data = {
            'me': me,
            'error': '',
            'form': SignupForm()
    }
    if request.method == 'POST':
        form = SignupForm(request.POST, request.FILES)
        print 'testing'
        print request.FILES
        print form.errors
        if form.is_valid():
            print 'testing'
            username = asciify(form.cleaned_data['username'])
            password = form.cleaned_data['password2']
            email = form.cleaned_data['email'].strip() or ''
            firstName = asciify(form.cleaned_data['first'])
            lastName = asciify(form.cleaned_data['last'])
            store_picture(request.FILES['picture'])


            # check that username not taken
            userslug = slugify(username)
            Profile = get_profile_model(raise_on_error=False)
            if Profile.objects.filter(username=userslug).count():
                data['error'] = u'Username "{}" is taken'.format(userslug)
                # error!
                #return HttpResponseRedirect('user:signup')
                '''
                safe_username = slugify('%s-%s' % (username, str(tznow())))
                changed_warningmsg = errormsg + ", changed it to '%s'."
                messages.warning(request, changed_warningmsg % (username, safe_username))
                username = safe_username
                '''
            # make user
            else:
                try:
                    user = make_user(firstName, lastName,username, password, email=email, request=request)
                except NanoUserExistsError:
                    next_profile = Profile.objects.get(user=user).get_absolute_url()
                    return HttpResponseRedirect(next_profile)
                else:
                    # fake authentication, avoid a db-lookup/thread-trouble/
                    # race conditions
                    user.backend = 'django.contrib.auth.backends.ModelBackend'
                    _LOG.debug('Attempting login of: %s' % user)
                    login(request, user)
                    nexthop = getattr(settings, 'NANO_USER_SIGNUP_NEXT', reverse('user:nano_user_signup_done'))
                    '''
                    try:
                        nexthop_profile = Profile.objects.get(user=user).get_absolute_url()
                        return HttpResponseRedirect(nexthop_profile)
                    except Profile.DoesNotExist:
                        pass
                    '''
                    return HttpResponseRedirect(nexthop)
                _LOG.debug('Should never end up here')
    return render(request, template_name, data)
Exemplo n.º 2
0
def signup(request, template_name='signup.html', *args, **kwargs):
    me = 'people'
    error = pop_error(request)
    data = {'me': me, 'error': error, 'form': SignupForm()}
    if request.method == 'POST':
        form = SignupForm(data=request.POST)
        if form.is_valid():
            username = asciify(form.cleaned_data['username'])
            password = form.cleaned_data['password2']
            email = form.cleaned_data['email'].strip() or ''

            errormsg = 'Username "%s" is taken'

            # check that username not taken
            userslug = slugify(username)
            Profile = get_profile_model(raise_on_error=False)
            if Profile.objects.filter(slug=userslug).count():
                # error!
                safe_username = slugify('%s-%s' % (username, str(tznow())))
                changed_warningmsg = errormsg + ", changed it to '%s'."
                messages.warning(
                    request, changed_warningmsg % (username, safe_username))
                username = safe_username

            # make user
            try:
                user = make_user(username,
                                 password,
                                 email=email,
                                 request=request)
            except NanoUserExistsError:
                next_profile = Profile.objects.get(
                    user=user).get_absolute_url()
                return HttpResponseRedirect(next_profile)
            else:
                # fake authentication, avoid a db-lookup/thread-trouble/
                # race conditions
                user.backend = 'django.contrib.auth.backends.ModelBackend'
                _LOG.debug('Attempting login of: %s' % user)
                login(request, user)
                nexthop = getattr(settings, 'NANO_USER_SIGNUP_NEXT',
                                  reverse('nano_user_signup_done'))
                try:
                    nexthop_profile = Profile.objects.get(
                        user=user).get_absolute_url()
                    return HttpResponseRedirect(nexthop_profile)
                except Profile.DoesNotExist:
                    pass
                return HttpResponseRedirect(nexthop)
            _LOG.debug('Should never end up here')
    return render(request, template_name, data)
Exemplo n.º 3
0
def signup(request, template_name='signup.html', *args, **kwargs):
    me = 'people'
    error = pop_error(request)
    data = {
            'me': me, 
            'error': error, 
            'form': SignupForm()
    }
    if request.method == 'POST':
        form = SignupForm(data=request.POST)
        if form.is_valid():
            username = asciify(form.cleaned_data['username'])
            password = form.cleaned_data['password2']
            email = form.cleaned_data['email'].strip() or ''

            errormsg = u'Username "%s" is taken'

            # check that username not taken
            userslug = slugify(username)
            if Profile.objects.filter(slug=userslug).count():
                # error!
                safe_username = slugify('%s-%s' % (username, str(datetime.now())))
                changed_warningmsg = errormsg + ", changed it to '%s'."
                messages.warning(request, changed_warningmsg % (username, safe_username))
                username = safe_username

            # make user
            try:
                user = make_user(username, password, email=email, request=request)
            except NanoUserExistsError:
                next_profile = user.get_profile().get_absolute_url()
                return HttpResponseRedirect(next_profile)
            else:
                # fake authentication, avoid a db-lookup/thread-trouble/
                # race conditions
                user.backend = 'django.contrib.auth.backends.ModelBackend'
                _LOG.debug('Attempting login of: %s' % user)
                login(request, user)
                nexthop = getattr(settings, 'NANO_USER_SIGNUP_NEXT', reverse('nano_user_signup_done'))
                try:
                    nexthop_profile = user.get_profile().get_absolute_url()
                    return HttpResponseRedirect(nexthop_profile)
                except Profile.DoesNotExist:
                    pass
                return HttpResponseRedirect(nexthop)
            _LOG.debug('Should never end up here')
    return render(request, template_name, data)
Exemplo n.º 4
0
def password_change(request, *args, **kwargs):
    error = pop_error(request)
    template_name = 'password_change_form.html'
    if request.method == "POST":
        form = PasswordChangeForm(request.POST)
        if form.is_valid():
            password = form.cleaned_data[u'password2']
            user = request.user
            user.set_password(password)
            user.save()
            request.session['error'] = None
            return HttpResponseRedirect('/password/change/done/')
    else:
        form = PasswordChangeForm()
    data = { 'form': form,
            'error': error,}
    return render(request, template_name, data)
Exemplo n.º 5
0
def password_change(request, *args, **kwargs):
    error = pop_error(request)
    template_name = 'password_change_form.html'
    if request.method == "POST":
        form = PasswordChangeForm(request.POST)
        if form.is_valid():
            password = form.cleaned_data['password2']
            user = request.user
            user.set_password(password)
            user.save()
            request.session['error'] = None
            return HttpResponseRedirect('/password/change/done/')
    else:
        form = PasswordChangeForm()
    data = {
        'form': form,
        'error': error,
    }
    return render(request, template_name, data)
Exemplo n.º 6
0
def password_reset(request, project_name='Nano', *args, **kwargs):
    User = get_user_model()
    error = pop_error(request)
    template = 'password_reset_form.html'
    e_template = 'password_reset.txt'
    help_message = None
    e_subject = '%s password assistance' % project_name
    e_message = """Your new password is: 

%%s

It is long deliberately, so change it to 
something you'll be able to remember.


%s' little password-bot
""" % project_name
    e_from = getattr(settings, 'NANO_USER_EMAIL_SENDER', '')
    form = PasswordResetForm()
    if e_from and request.method == 'POST':
        form = PasswordResetForm(request.POST)
        if form.is_valid():
            user = get_object_or_404(User,
                                     username=form.cleaned_data['username'])
            if user.email:
                tmp_pwd = random_password()
                user.set_password(tmp_pwd)
                result = send_mail(subject=e_subject,
                                   from_email=e_from,
                                   message=e_message % tmp_pwd,
                                   recipient_list=(user.email, ))
                user.save()
                request.session['error'] = None
                return HttpResponseRedirect('/password/reset/sent/')
            else:
                error = """There's no email-address registered for '%s', 
                        the password can't be reset.""" % user.username
                request.session['error'] = error

    data = {'form': form, 'help_message': help_message, 'error': error}
    return render(request, template, data)
Exemplo n.º 7
0
def password_reset(request, project_name='Nano', *args, **kwargs):
    User = get_user_model()
    error = pop_error(request)
    template = 'password_reset_form.html'
    e_template = 'password_reset.txt'
    help_message = None
    e_subject = '%s password assistance' % project_name
    e_message = """Your new password is: 

%%s

It is long deliberately, so change it to 
something you'll be able to remember.


%s' little password-bot
""" % project_name
    e_from = getattr(settings, 'NANO_USER_EMAIL_SENDER', '')
    form = PasswordResetForm()
    if e_from and request.method == 'POST':
        form = PasswordResetForm(request.POST)
        if form.is_valid():
            user = get_object_or_404(User, username=form.cleaned_data['username'])
            if user.email:
                tmp_pwd = random_password()
                user.set_password(tmp_pwd)
                result = send_mail(subject=e_subject, from_email=e_from, message=e_message % tmp_pwd, recipient_list=(user.email,))
                user.save()
                request.session['error'] = None
                return HttpResponseRedirect('/password/reset/sent/')
            else:
                error = """There's no email-address registered for '%s', 
                        the password can't be reset.""" % user.username
                request.session['error'] = error
                
    data = {'form': form,
            'help_message': help_message,
            'error':error}
    return render(request, template, data)
Exemplo n.º 8
0
def signup(request, template_name='signup.html', *args, **kwargs):
    me = 'people'
    error = pop_error(request)
    data = {
            'me': me, 
            'error': error, 
            'form': SignupForm()
    }
    if request.method == 'POST':
        form = SignupForm(data=request.POST)
        if form.is_valid():
            username = asciify(form.cleaned_data['username'])
            password = form.cleaned_data['password2']
            email = form.cleaned_data['email'].strip() or ''

            # check that username not taken
            userslug = slugify(username)
            if Profile.objects.filter(slug=userslug).count():
                # error!
                safe_username = slugify('%s-%s' % (username, str(datetime.now())))
                request.session['error'] = u"Username '%s' already taken, changed it to '%s'." % (username, safe_username)
                username = safe_username

            # make user
            user = make_user(username, password, email=email, request=request)
            user = auth.authenticate(username=username, password=password)
            auth.login(request, user)
            request.session['error'] = None
            next = getattr(settings, 'NANO_USER_SIGNUP_NEXT', reverse('nano_user_signup_done'))
            try:
                next_profile = user.get_profile().get_absolute_url()
                return HttpResponseRedirect(next_profile)
            except Profile.DoesNotExist:
                pass
            return HttpResponseRedirect(next)
    return render_page(request, template_name, data)