Beispiel #1
0
def create_resource(request):
    if request.method == 'POST':
        form = ResourceForm(request.POST, request.FILES)
        files = request.FILES.getlist('images')
        if form.is_valid():
            with transaction.atomic():
                res = form.save(commit=True)
                res.author = request.user
                res.save()
                for file in files:
                    file = ResourceImage(image=file)
                    file.resource = res
                    file.save()
            mailer = Mailer()
            mailer.send_email(
                CDCRC_MEDIA_EMAIL,
                'Approval Request for New Resource {}'.format(res.title),
                '{} has added a resource titled {}. Please take a look.'.
                format(res.author.username, res.title))
            return render_message(
                request, 'Approval Pending',
                'Thanks for sharing the resource...it will be posted on the website after being approved by our team!'
            )
        else:
            return render_message(
                request, 'Error',
                'There was an error in creating the resource')
    else:
        form = ResourceForm()
        return render(request,
                      'info/resource_create.html',
                      context={'form': form})
Beispiel #2
0
def contact_us_form(request):
    if request.method == 'POST':
        form = ContactUsForm(request.POST)
        if form.is_valid():
            contact_us_obj = form.save(commit=True)
            mailer = Mailer()
            mailer.send_email(
                PRIMARY_ALERT_EMAILS,
                '[ALERT] New Registration on Website:  {}'.format(
                    contact_us_obj.name),
                'Please reach out to {} from {} who has registered on the CDCRC Website.\n Contact Info - {}, {}.\nMessage- {}'
                .format(contact_us_obj.name, contact_us_obj.organization,
                        contact_us_obj.email, contact_us_obj.phone,
                        contact_us_obj.message),
            )
            return render_message(
                request, 'Thanks!',
                'Our team will reach out to you shortly. You can also call us at {} whenever you want!'
                .format(PRIMARY_PHONE))
        else:
            return render_message(request, 'Error',
                                  'There was an error in filling the form..')
    else:
        title = 'Contact Us Form'
        form = ContactUsForm()
        return render(request,
                      'info/contact_us_form.html',
                      context={
                          'title': title,
                          'form': form
                      })
Beispiel #3
0
def signup(request):
    if request.method=='POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            to_email = form.cleaned_data.get('email')
            print(to_email)
            if not to_email.endswith('@iitrpr.ac.in'):
                return render_message(request, 'Access Denied', 'Sorry ... only IIT Ropar domain emails can be used to sign up!')
            mailer = Mailer()
            user = form.save(commit=False)
            user.is_active = False
            user.username = to_email
            try:
                user.save()
                current_site = get_current_site_from_env()
                message = render_to_string('accounts/activate_account_email.html', {
                    'user': user,
                    'domain': current_site,
                    'uid':urlsafe_base64_encode(force_bytes(user.pk)),
                    'token':account_activation_token.make_token(user),
                })
                
                response=mailer.send_email(to_email, 'CDCRC User Registration Activation', message )
                print("Mail Response: ", response)
                if(response=='fail'):
                    raise Exception('Mail Service is down! 😢')

                return render_message(request,
                    'Email Confirmation',
                    'To activate your account, please see your email!'
                )
            except IntegrityError as e: 
                if 'UNIQUE constraint failed' in str(e):
                    return render_message(request,
                        'User Exists',
                        'An account with this user already exists!'
                    )
                else:
                    raise Exception('DB Integrity Error Occurred')
            except Exception as e:
                # Deleting the user
                user.delete()
                return render_message(request,
                    'An error occurred while creating your account',
                    'Trace: '+ str(e)
                )
            

    else:
        form = SignupForm()
    return render(request, 'accounts/signup.html', {'form': form})