Ejemplo n.º 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})
Ejemplo n.º 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
                      })
Ejemplo n.º 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})
Ejemplo n.º 4
0
def signup(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            to_email = form.cleaned_data.get('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',
                    'Thank you for joining CDCRC Internal Network. We have sent an activation link to your email. Once verified, you can access plethora of resources on the webpage. Hope to see you onboard soon!'
                )
            except Exception as e:
                # Deleting the user
                if user.id != None:
                    print("Deleting user: ", user.id)
                    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})
Ejemplo n.º 5
0
def activate(request, uidb64, token):
    try:
        t = urlsafe_base64_decode(uidb64)
        uid = force_text(t)
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist) as e:
        user = None
        return render_message(
            request,
            'Error in activating the account',
            'Trace: ' + str(e),
        )
    if user is not None and account_activation_token.check_token(user, token):
        user.is_active = True
        user.save()
        login(request, user)
        return render_message(
            request, 'Account Activated',
            'Congratulations, your account was successfully activated!')
    else:
        return render_message(request, 'Invalid Activation Link',
                              'The activation link is invalid!')
Ejemplo n.º 6
0
def import_contacts_from_csv(request):
    if request.method == 'POST':
        form = ImportContactsForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                contact_handler = ContactsCSVHandler(
                    request.FILES['contacts_file'], request.encoding)
                contact_handler.import_from_file()
                return HttpResponseRedirect(
                    reverse('internal:unapproved_contacts_list'))
            except:
                return render_message(
                    request, 'Error',
                    'There was an error...pls check the format of your file')
        else:
            return render_message(
                request, 'Error',
                'There was an error...pls check the format of your file')

    else:
        form = ImportContactsForm()
    return render(request,
                  'internal/import_contacts_from_csv.html',
                  context={'form': form})
Ejemplo n.º 7
0
def check_account_status(request):
    message = str(request.user.get_user_name()) + " " + str(request.user.is_team_member()) + " " + str(request.user.student_profile_completed())
    return render_message(request, 'User Status', message)