Esempio n. 1
0
def pp_generate_key(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)

    POST = kwargs.get('POST', None)

    if POST is not None and POST.get("form_id") == "pp_key_generator":
        form = KeyGenerator(POST)
        if form.is_valid():
            u_key = form.cleaned_data['user']
            try:
                user = User.objects.get(username=u_key)
                if user.is_active:
                    namespace[
                        'errors'] = 'User already active! Login to start browsing.'
                else:
                    salt = sha.new(str(random.random())).hexdigest()[:5]
                    activation_key = sha.new(salt + user.username).hexdigest()
                    key_expires = datetime.datetime.today(
                    ) + datetime.timedelta(2)

                    #delete expired email verification
                    old_ver = EmailVerification.objects.get(user=user)
                    old_ver.delete()

                    new_profile = EmailVerification(
                        user=user,
                        activation_key=activation_key,
                        key_expires=key_expires)
                    new_profile.save()

                    email_subject = 'OpenAssembly account confirmation'
                    email_body = "Hello, %s, and thanks for signing up for an Open Assembly account!\n\nTo activate your account, click this link within 48 hours:\n\n%sconfirm/%s/" % (
                        user.username, DOMAIN_NAME, new_profile.activation_key)
                    send_mail(email_subject, email_body, '*****@*****.**',
                              [user.email])
                    namespace[
                        'errors'] = 'New Confirmation Email Sent! Check Your Mail Soon.'

            except:
                namespace['errors'] = 'Username not found.'
        else:
            form = KeyGenerator(POST)
            namespace['errors'] = form.errors

    else:
        form = KeyGenerator()

    namespace['form'] = form
    output = nodelist.render(context)
    context.pop()

    return output
Esempio n. 2
0
def pp_generate_key(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)

    POST = kwargs.get('POST', None)

    if POST is not None and POST.get("form_id") == "pp_key_generator":
        form = KeyGenerator(POST)
        if form.is_valid():
            u_key = form.cleaned_data['user']
            try:
                user = User.objects.get(username=u_key)
                if user.is_active:
                    namespace['errors'] = 'User already active! Login to start browsing.'
                else:
                    salt = sha.new(str(random.random())).hexdigest()[:5]
                    activation_key = sha.new(salt + user.username).hexdigest()
                    key_expires = datetime.datetime.today() + datetime.timedelta(2)

                    #delete expired email verification
                    old_ver = EmailVerification.objects.get(user=user)
                    old_ver.delete()
                                                                                                                      
                    new_profile = EmailVerification(user=user,
                                              activation_key=activation_key,
                                              key_expires=key_expires)
                    new_profile.save()
                                                                                                           
                    email_subject = 'OpenAssembly account confirmation'
                    email_body = "Hello, %s, and thanks for signing up for an Open Assembly account!\n\nTo activate your account, click this link within 48 hours:\n\n%sconfirm/%s/" % (
                        user.username, DOMAIN_NAME,
                        new_profile.activation_key)
                    send_mail(email_subject,
                              email_body,
                              '*****@*****.**',
                              [user.email])
                    namespace['errors'] = 'New Confirmation Email Sent! Check Your Mail Soon.'

            except:
                namespace['errors'] = 'Username not found.'
        else:
           form = KeyGenerator(POST)
           namespace['errors'] = form.errors

    else:
        form = KeyGenerator()

    namespace['form'] = form
    output = nodelist.render(context)
    context.pop()    

    return output
Esempio n. 3
0
def pp_user_registration_form(context, nodelist, *args, **kwargs):
    '''form_id = forms.CharField(widget=forms.HiddenInput(), initial="pp_user_registration_form")
    This block tag can create or process forms either to create or to modify issues.
    Usage is as follows:

    {% pp_user_login_form request=request return_path=request.MATH.PATH_INFO return_query=request.META.QUERY_STRING %}
       Do stuff with {{ pp_login.form }}.
    {% endpp_user_login_form%}
    '''
    context.push()
    namespace = get_namespace(context)

    request = kwargs.get('request')
    dimension=kwargs.get('dimension', None)
    return_path= kwargs.get('return_path')
    return_query= kwargs.get('return_query')
    returnurl = kwargs.get('returnurl') #this is for register.html:
    user = kwargs.get('user', None)

    if request is not None: 
        POST = request.POST
    else:
        raise ValueError("Tag pp_user_login_form must contain the argument 'request=request'")

    if POST and POST.get("form_id") == "pp_user_registration_form":
        if user.is_authenticated():
            form = RegisterForm(POST)
            namespace['errors'] = "You are already logged in. Log out and try again."
        else:
            try:
                form = RegisterForm(POST)
                if form.is_valid():
                    new_user = form.save()
                    if new_user.password1 == new_user.password2:
                        #check to see if there are other users with this name
                        try:
                            ui = User.objects.get(username__iexact=new_user.name)
                            namespace['errors'] = "Sorry that username is taken already, please pick another."
                        except:
                            user = User.objects.create_user(new_user.name, new_user.email, new_user.password1)
                            user.is_active = False
                            user.save()
                            #set user location
                            user = authenticate(username=new_user.name, password=new_user.password1)

                            if user is not None:
                                #if this is a referred user
                                if dimension is not None:
                                    #try:
                                    ref = Referral.objects.get(key=dimension, accepted=False)
                                    ref.referred_user = user
                                    ref.accepted_dt = datetime.datetime.now()
                                    ref.accepted = True
                                    ref.save()
                                    user.is_active = True
                                    user.save()
                                    login(request, user)

                                    if ref.topic is not None:
                                        mg, is_new = MyGroup.objects.get_or_create(user=user, topic=ref.topic)
                                        ref.topic.group_members += 1
                                        ref.topic.save()
                                    namespace['success'] = 'Account created and group joined!'
                                    #except:
                                    #    namespace['errors'] = "Illegal Referral Key"
                                else:
                                    salt = sha.new(str(random.random())).hexdigest()[:5]
                                    activation_key = sha.new(salt + user.username).hexdigest()
                                    key_expires = datetime.datetime.today() + datetime.timedelta(2)

                                    new_profile = EmailVerification(user=user,
                                                              activation_key=activation_key,
                                                              key_expires=key_expires)
                                    new_profile.save()

                                    email_subject = 'OpenAssembly account confirmation'
                                    email_body = "Hello, %s, and thanks for signing up for an Open Assembly account!\n\nTo activate your account, click this link within 48 hours:\n\n%sconfirm/%s/" % (
                                        user.username, DOMAIN_NAME,
                                        new_profile.activation_key)
                                    send_mail(email_subject,
                                              email_body,
                                              '*****@*****.**',
                                              [user.email])
                                    namespace['success'] = 'Check your email for confirmation!'
                    else:
                        namespace['errors'] = "Passwords are not the same. Try again."
            except HttpRedirectException, e:
                raise e
Esempio n. 4
0
def pp_user_registration_form(context, nodelist, *args, **kwargs):
    '''form_id = forms.CharField(widget=forms.HiddenInput(), initial="pp_user_registration_form")
    This block tag can create or process forms either to create or to modify issues.
    Usage is as follows:

    {% pp_user_login_form request=request return_path=request.MATH.PATH_INFO return_query=request.META.QUERY_STRING %}
       Do stuff with {{ pp_login.form }}.
    {% endpp_user_login_form%}
    '''
    context.push()
    namespace = get_namespace(context)

    request = kwargs.get('request')
    dimension = kwargs.get('dimension', None)
    return_path = kwargs.get('return_path')
    return_query = kwargs.get('return_query')
    returnurl = kwargs.get('returnurl')  #this is for register.html:
    user = kwargs.get('user', None)

    if request is not None:
        POST = request.POST
    else:
        raise ValueError(
            "Tag pp_user_login_form must contain the argument 'request=request'"
        )

    if POST and POST.get("form_id") == "pp_user_registration_form":
        if user.is_authenticated():
            form = RegisterForm(POST)
            namespace[
                'errors'] = "You are already logged in. Log out and try again."
        else:
            try:
                form = RegisterForm(POST)
                if form.is_valid():
                    new_user = form.save()
                    if new_user.password1 == new_user.password2:
                        #check to see if there are other users with this name
                        try:
                            ui = User.objects.get(
                                username__iexact=new_user.name)
                            namespace[
                                'errors'] = "Sorry that username is taken already, please pick another."
                        except:
                            user = User.objects.create_user(
                                new_user.name, new_user.email,
                                new_user.password1)
                            user.is_active = False
                            user.save()
                            #set user location
                            user = authenticate(username=new_user.name,
                                                password=new_user.password1)

                            if user is not None:
                                #if this is a referred user
                                if dimension is not None:
                                    #try:
                                    ref = Referral.objects.get(key=dimension,
                                                               accepted=False)
                                    ref.referred_user = user
                                    ref.accepted_dt = datetime.datetime.now()
                                    ref.accepted = True
                                    ref.save()
                                    user.is_active = True
                                    user.save()
                                    login(request, user)

                                    if ref.topic is not None:
                                        mg, is_new = MyGroup.objects.get_or_create(
                                            user=user, topic=ref.topic)
                                        ref.topic.group_members += 1
                                        ref.topic.save()
                                    namespace[
                                        'errors'] = 'Account created and group joined!'
                                    #except:
                                    #    namespace['errors'] = "Illegal Referral Key"
                                else:
                                    salt = sha.new(str(
                                        random.random())).hexdigest()[:5]
                                    activation_key = sha.new(
                                        salt + user.username).hexdigest()
                                    key_expires = datetime.datetime.today(
                                    ) + datetime.timedelta(2)

                                    new_profile = EmailVerification(
                                        user=user,
                                        activation_key=activation_key,
                                        key_expires=key_expires)
                                    new_profile.save()

                                    email_subject = 'OpenAssembly account confirmation'
                                    email_body = "Hello, %s, and thanks for signing up for an Open Assembly account!\n\nTo activate your account, click this link within 48 hours:\n\n%sconfirm/%s/" % (
                                        user.username, DOMAIN_NAME,
                                        new_profile.activation_key)
                                    send_mail(email_subject, email_body,
                                              '*****@*****.**', [user.email])
                                    namespace[
                                        'errors'] = 'Check your email for confirmation!'
                    else:
                        namespace[
                            'errors'] = "Passwords are not the same. Try again."
            except HttpRedirectException, e:
                raise e