Beispiel #1
0
def goal_email(sender, **kwargs):
    '''
    Emails supervisor of goal on any changes
    '''
    p = models.Goal.objects.get(pk=sender.id)
    email = diff(sender, p, 'supervisor')
    if email:
        template_mail(
            'Goal Ownership Changed',
            'tracker/goal_owner_email',
            {
                'from': sender.supervisor,
                'to': p.supervisor,
                'name': sender.name
            },
            settings.COMPSOC_EXEC_EMAIL,
            [sender.supervisor.email, p.supervisor.email],
        )
    else:
        template_mail(
            'Goal Changed',
            'tracker/goal_change_email',
            {
                'attr': dict_map(lambda x: diff(sender, p, x),
                                 p.__dict__.keys()),
                'name': sender.name
            },
            settings.COMPSOC_EXEC_EMAIL,
            [sender.supervisor.email],
        )
Beispiel #2
0
def _email_guest_about_pending_request(guest):
    template_mail(
        'Guest account request',
        'memberinfo/guest_request_email',
        {},  #{'name': name},
        settings.COMPSOC_EXEC_EMAIL,
        [guest.email])
Beispiel #3
0
def reset_password(request):
    try:
        # Do the password reset
        user_name = request.POST["user_name"]
        user = User.objects.get(username__exact=user_name)
        password = User.objects.make_random_password()
        user.set_password(password)
        user.save()

        # Email the user
        template_mail(
            "Compsoc Password Reset",
            "memberinfo/reset_email",
            {"name": user_name, "password": password},
            settings.WEBMASTER_EMAIL,
            [user.email],
        )
        return render_to_response(
            "memberinfo/password_reset_success.html", {}, context_instance=RequestContext(request, {}, [path_processor])
        )
    # If someone tries to reset the password of a user who doesn't exist, then report it
    except User.DoesNotExist:
        template_mail(
            "Warning: Failed Password Reset Attempt",
            "memberinfo/techteam_reset_email",
            {"name": user_name, "ip": request.META["REMOTE_ADDR"]},
            settings.WEBMASTER_EMAIL,
            [settings.WEBMASTER_EMAIL],
        )
        return render_to_response(
            "memberinfo/password_reset_no_name.html",
            {"tech": settings.WEBMASTER_EMAIL},
            context_instance=RequestContext(request, {}, [path_processor]),
        )
Beispiel #4
0
def quota(request):
    form = forms.QuotaForm(request.POST)
    user = request.user
    if form.is_valid():
        amount = form.cleaned_data["quota"]
        try:
            acc_name = user.shellaccount.name
            models.Quota.objects.create(user=user, quantity=amount, status="RE", date=datetime.now())
            template_mail(
                "Quota request",
                "memberinfo/quota_techteam",
                {"realname": user.member.all_name(), "username": acc_name, "amount": amount},
                user.email,
                [settings.COMPSOC_TECHTEAM_EMAIL, settings.COMPSOC_TREASURER_EMAIL],
            )
            return HttpResponseRedirect("/member/")
        except models.ShellAccount.DoesNotExist:
            return render_to_response(
                "memberinfo/request_error.html",
                {"name": "Quota", "error": "You don't have a shell account"},
                context_instance=RequestContext(request, {}, [path_processor]),
            )
    else:
        return render_to_response(
            "memberinfo/request_error.html",
            {"name": "Quota", "error": "You must enter an integer as the amount"},
            context_instance=RequestContext(request, {}, [path_processor]),
        )
Beispiel #5
0
def _email_exec_about_guest_request(guest):
    template_mail(
        'Guest account request',
        'memberinfo/exec_guest_request_email',
        {},  #{'name': name},
        settings.COMPSOC_EXEC_EMAIL,
        [settings.COMPSOC_EXEC_EMAIL])
Beispiel #6
0
def do_service(request, form, klass, name, error):
    f = form(request.POST)
    if f.is_valid():
        n = f.cleaned_data["name"]
        u = request.user

        try:
            acc = klass.objects.get(user=u)
            return render_to_response(
                "memberinfo/request_error.html",
                {"name": name, "error": error(acc)},
                context_instance=RequestContext(request, {}, [path_processor]),
            )
        except klass.DoesNotExist:
            obj = klass(user=u, name=n, status="RE")
            obj.save()

            template_mail(
                "New service request",
                "memberinfo/service_techteam.html",
                {"realname": ("%s %s" % (u.first_name, u.last_name)), "username": n, "what": name},
                settings.COMPSOC_TECHTEAM_EMAIL,
                [settings.COMPSOC_TECHTEAM_EMAIL],
            )
        return HttpResponseRedirect("/member/")
    else:
        return render_to_response(
            "memberinfo/form_errors.html",
            {"name": name, "all_errors": f.errors.items()},
            context_instance=RequestContext(request, {}, [path_processor]),
        )
Beispiel #7
0
def reset_password(request):
    try:
        # Do the password reset
        user_name = request.POST['user_name']
        user = User.objects.get(username__exact=user_name)
        password = User.objects.make_random_password()
        user.set_password(password)
        user.save()

        # Email the user
        template_mail('Compsoc Password Reset', 'memberinfo/reset_email', {
            'name': user_name,
            'password': password
        }, settings.WEBMASTER_EMAIL, [user.email])
        return render_to_response('memberinfo/password_reset_success.html', {},
                                  context_instance=RequestContext(
                                      request, {}, [path_processor]))
    # If someone tries to reset the password of a user who doesn't exist, then report it
    except User.DoesNotExist:
        template_mail('Warning: Failed Password Reset Attempt',
                      'memberinfo/techteam_reset_email', {
                          'name': user_name,
                          'ip': request.META['REMOTE_ADDR']
                      }, settings.WEBMASTER_EMAIL, [settings.WEBMASTER_EMAIL])
        return render_to_response('memberinfo/password_reset_no_name.html', {
            'tech': settings.WEBMASTER_EMAIL,
        },
                                  context_instance=RequestContext(
                                      request, {}, [path_processor]))
Beispiel #8
0
def quota(request):
    form = forms.QuotaForm(request.POST)
    user = request.user
    if form.is_valid():
        amount = form.cleaned_data['quota']
        try:
            acc_name = user.shellaccount.name
            models.Quota.objects.create(user=user,
                                        quantity=amount,
                                        status='RE',
                                        date=datetime.now())
            template_mail(
                'Quota request', 'memberinfo/quota_techteam', {
                    'realname': user.member.all_name(),
                    'username': acc_name,
                    'amount': amount
                }, user.email, [
                    settings.COMPSOC_TECHTEAM_EMAIL,
                    settings.COMPSOC_TREASURER_EMAIL
                ])
            return HttpResponseRedirect('/member/')
        except models.ShellAccount.DoesNotExist:
            return render_to_response(
                'memberinfo/request_error.html', {
                    'name': 'Quota',
                    'error': 'You don\'t have a shell account',
                },
                context_instance=RequestContext(request, {}, [path_processor]))
    else:
        return render_to_response(
            'memberinfo/request_error.html', {
                'name': 'Quota',
                'error': "You must enter an integer as the amount",
            },
            context_instance=RequestContext(request, {}, [path_processor]))
Beispiel #9
0
def do_service(request, form, klass, name, error):
    f = form(request.POST)
    if f.is_valid():
        n = f.cleaned_data['name']
        u = request.user

        try:
            acc = klass.objects.get(user=u)
            return render_to_response('memberinfo/request_error.html', {
                'name': name,
                'error': error(acc),
            },
                                      context_instance=RequestContext(
                                          request, {}, [path_processor]))
        except klass.DoesNotExist:
            obj = klass(user=u, name=n, status='RE')
            obj.save()

            template_mail(
                'New service request', 'memberinfo/service_techteam.html', {
                    'realname': ("%s %s" % (u.first_name, u.last_name)),
                    'username': n,
                    'what': name
                }, settings.COMPSOC_TECHTEAM_EMAIL,
                [settings.COMPSOC_TECHTEAM_EMAIL])
        return HttpResponseRedirect('/member/')
    else:
        return render_to_response('memberinfo/form_errors.html', {
            'name': name,
            'all_errors': f.errors.items(),
        },
                                  context_instance=RequestContext(
                                      request, {}, [path_processor]))
Beispiel #10
0
def _email_guest_about_pending_request(guest):
    template_mail(
        "Guest account request",
        "memberinfo/guest_request_email",
        {},  # {'name': name},
        settings.COMPSOC_EXEC_EMAIL,
        [guest.email],
    )
Beispiel #11
0
def _email_exec_about_guest_request(guest):
    template_mail(
        "Guest account request",
        "memberinfo/exec_guest_request_email",
        {},  # {'name': name},
        settings.COMPSOC_EXEC_EMAIL,
        [settings.COMPSOC_EXEC_EMAIL],
    )
Beispiel #12
0
def accept_guest(request, user_id):
    u = User.objects.get(id=user_id)
    u.is_active = True
    pwd = User.objects.make_random_password()
    u.set_password(pwd)
    u.save()
    template_mail('Guest account Acceptance',
                  'admin/memberinfo/guest_accept_email', {
                      'name': u.username,
                      'password': pwd
                  }, settings.COMPSOC_EXEC_EMAIL, [u.email])
    return HttpResponseRedirect('/admin/memberinfo/guests/')
Beispiel #13
0
def accept_guest(request,user_id):
    u = User.objects.get(id=user_id)
    u.is_active = True
    pwd = User.objects.make_random_password()
    u.set_password(pwd)
    u.save()
    template_mail(
        'Guest account Acceptance',
        'admin/memberinfo/guest_accept_email',
        {'name':u.username,'password':pwd},
        settings.COMPSOC_EXEC_EMAIL,
        [u.email])
    return HttpResponseRedirect('/admin/memberinfo/guests/')
Beispiel #14
0
 def handle(self, *args, **options):
     '''
     '''
     u = User.objects.get(username=args[0])
     password = User.objects.make_random_password()
     u.set_password(password)
     u.save()
     template_mail(
         'New Website Password',
         'memberinfo/new_user_email',
         {'first': u.first_name, 'last':u.last_name, 'username':u.username, 'password':password},
         settings.COMPSOC_TECHTEAM_EMAIL,
         [u.email])
Beispiel #15
0
 def handle(self, *args, **options):
     '''
     '''
     u = User.objects.get(username=args[0])
     password = User.objects.make_random_password()
     u.set_password(password)
     u.save()
     template_mail(
         'New Website Password', 'memberinfo/new_user_email', {
             'first': u.first_name,
             'last': u.last_name,
             'username': u.username,
             'password': password
         }, settings.COMPSOC_TECHTEAM_EMAIL, [u.email])
Beispiel #16
0
def reject_guest(request, user_id):
    u = User.objects.get(id=user_id)
    name = u.username
    email = u.email

    u.member.delete()
    u.nicknamedetails.delete()
    u.delete()

    template_mail('Guest account Rejection',
                  'admin/memberinfo/guest_reject_email', {'name': name},
                  settings.COMPSOC_EXEC_EMAIL, [email])

    return HttpResponseRedirect('/admin/memberinfo/guests/')
Beispiel #17
0
def reject_guest(request,user_id):
    u = User.objects.get(id=user_id)
    name = u.username
    email = u.email

    u.member.delete()
    u.nicknamedetails.delete()
    u.delete()

    template_mail(
        'Guest account Rejection',
        'admin/memberinfo/guest_reject_email',
        {'name':name},
        settings.COMPSOC_EXEC_EMAIL,
        [email])

    return HttpResponseRedirect('/admin/memberinfo/guests/')
Beispiel #18
0
 def handle(self, *args, **options):
     '''
     '''
     for u in User.objects.all():
         password = User.objects.make_random_password()
         u.set_password(password)
         u.save()
         try:
             template_mail(
                 'New Website Password', 'memberinfo/migration_email', {
                     'first': u.first_name,
                     'last': u.last_name,
                     'username': u.username,
                     'password': password
                 }, settings.COMPSOC_TECHTEAM_EMAIL, [u.email])
         except Exception, e:
             print u.username
             print e
Beispiel #19
0
def ticket_email(sender, **kwargs):
    '''
    Emails appropriate people on ticket changes
    '''
    p = models.Ticket.objects.get(pk=sender.id)
    email_to = set()
    for ticket in [sender,p]:
        if ticket.assignee:
            email_to.add(ticket.assignee.email)
        email_to.add(ticket.submitter.email)
        email_to.add(ticket.goal.supervisor.email)
    template_mail(
        'Ticket Changed',
        'tracker/ticket_change_email',
        {'attr': dict_map(lambda x: diff(sender,p,x),p.__dict__.keys())},
        settings.COMPSOC_EXEC_EMAIL,
        [x for x in email_to],
    )
Beispiel #20
0
def ticket_email(sender, **kwargs):
    '''
    Emails appropriate people on ticket changes
    '''
    p = models.Ticket.objects.get(pk=sender.id)
    email_to = set()
    for ticket in [sender, p]:
        if ticket.assignee:
            email_to.add(ticket.assignee.email)
        email_to.add(ticket.submitter.email)
        email_to.add(ticket.goal.supervisor.email)
    template_mail(
        'Ticket Changed',
        'tracker/ticket_change_email',
        {'attr': dict_map(lambda x: diff(sender, p, x), p.__dict__.keys())},
        settings.COMPSOC_EXEC_EMAIL,
        [x for x in email_to],
    )
 def handle(self, *args, **options):
     '''
     '''
     for u in User.objects.all():
         password = User.objects.make_random_password()
         u.set_password(password)
         u.save()
         try:
             template_mail(
                 'New Website Password',
                 'memberinfo/migration_email',
                 {'first': u.first_name, 'last':u.last_name, 'username':u.username, 'password':password},
                 settings.COMPSOC_TECHTEAM_EMAIL,
                 [u.email]
             )
         except Exception, e:
             print u.username
             print e
Beispiel #22
0
def goal_email(sender, **kwargs):
    '''
    Emails supervisor of goal on any changes
    '''
    p = models.Goal.objects.get(pk=sender.id)
    email = diff(sender, p, 'supervisor')
    if email:
        template_mail(
            'Goal Ownership Changed',
            'tracker/goal_owner_email',
            {'from':sender.supervisor,'to':p.supervisor,'name':sender.name},
            settings.COMPSOC_EXEC_EMAIL,
            [sender.supervisor.email,p.supervisor.email],
        )
    else:
        template_mail(
            'Goal Changed',
            'tracker/goal_change_email',
            {'attr': dict_map(lambda x:diff(sender,p,x),p.__dict__.keys()),'name':sender.name},
            settings.COMPSOC_EXEC_EMAIL,
            [sender.supervisor.email],
        )
Beispiel #23
0
def reset_account(request, account):
    try:
        u = request.user
        name = (u.databaseaccount if account == 'db' else u.shellaccount).name
        type = 'Database' if account == 'db' else 'Shell'
        template_mail('Password reset request',
                      'memberinfo/account_techteam_email', {
                          'name': u.get_full_name(),
                          'type': type,
                          'accname': name
                      }, u.email, [settings.OMPSOC_TECHTEAM_EMAIL])
        return render_to_response('memberinfo/account_reset.html', {},
                                  context_instance=RequestContext(
                                      request, {}, [path_processor]))
    except models.DatabaseAccount.DoesNotExist:
        error = "You don't have a database, so it can't be password reset"
    except models.ShellAccount.DoesNotExist:
        error = "You don't have a shell account, so it can't be password reset"
    return render_to_response('memberinfo/request_error.html', {
        'name': 'Shell',
        'error': error,
    },
                              context_instance=RequestContext(
                                  request, {}, [path_processor]))
Beispiel #24
0
def reset_account(request, account):
    try:
        u = request.user
        name = (u.databaseaccount if account == "db" else u.shellaccount).name
        type = "Database" if account == "db" else "Shell"
        template_mail(
            "Password reset request",
            "memberinfo/account_techteam_email",
            {"name": u.get_full_name(), "type": type, "accname": name},
            u.email,
            [settings.OMPSOC_TECHTEAM_EMAIL],
        )
        return render_to_response(
            "memberinfo/account_reset.html", {}, context_instance=RequestContext(request, {}, [path_processor])
        )
    except models.DatabaseAccount.DoesNotExist:
        error = "You don't have a database, so it can't be password reset"
    except models.ShellAccount.DoesNotExist:
        error = "You don't have a shell account, so it can't be password reset"
    return render_to_response(
        "memberinfo/request_error.html",
        {"name": "Shell", "error": error},
        context_instance=RequestContext(request, {}, [path_processor]),
    )
Beispiel #25
0
    def handle_noargs(self, **options):
        '''
        Runs main update for Compsoc membership details.  The update satisfies the
        following conditions:
        1. Internal Consistency of compsoc models
            user.is_active iff there is a join entry for the current year
        2. Equivalence between compsoc and union models
            user.is_active iff the user is a current member of compsoc or a guest
        3. User information
            compsoc members who have just had an account created, should be emailed
        '''
        from uwcs_website.shortcuts import current_year

        #1. get data from the union
        union_lookup = get_data()

        #2. soundness: if your account is not a guest account and is active then you must be a union member
        # a) sync active members info
        # b) deactivate non union members
        #for user in User.objects.exclude(member__guest=True):
        y = current_year()
        for user in User.objects.filter(is_active=True, member__guest=False):
            if union_lookup.has_key(user.username):
                (first, last, email) = union_lookup[user.username]

                # sync information
                user.first_name = first
                user.last_name = last
                if email is not None:
                    user.email = email
                else:
                    user.email = ""
                    user.is_active = False
                user.save()

                # note that they have joined this year
                MemberJoin.objects.get_or_create(user=user, year=y)

                del union_lookup[user.username]
            # if they're not listed in the union's api, could be a special case
            elif not user.is_staff:
                # next two lines should be removed when historical exec data is added
                ex, created = Group.objects.get_or_create(
                    name=settings.EX_EXEC_GROUP_NAME)

                # if not on the exec at some point or a society
                if not (user.groups.filter(name=settings.EX_EXEC_GROUP_NAME)
                        or Society.objects.filter(user_ptr=user)):
                    try:
                        week = warwick_week_for(datetime.now())
                    except Term.DoesNotExist:
                        week = settings.GRACE_PERIOD + 1  #assume outside of grace period

                    # if inside the grace period
                    if week <= settings.GRACE_PERIOD:
                        # but not a member from last year
                        if not user.memberjoin_set.filter(year=current_year() -
                                                          1):
                            user.is_active = False
                            user.save()
                    else:
                        user.is_active = False
                        user.save()

        #3. completeness: if you are a union member, then you must have a compsoc account
        #                 it is active iff you have a union email address
        #4. TODO: information: emails people who have just had their accounts added
        #5. consistency: ensure there exist current join years for members
        # a) create new accounts for those without
        # b) reactivate accounts for those already with inactive accounts
        for (id, (first, last, email)) in union_lookup.iteritems():

            active = True

            try:
                # find disabled accounts
                user = User.objects.get(username=id)
                print "reactivating %s" % id
                if email is None:
                    email = ""
                    active = False
                    print "cannot reactivate %s: no email address" % id
            except User.DoesNotExist:
                print "creating %s" % id
                if email is None:
                    email = ""
                    active = False
                    print "cannot activate %s: no email address" % id
                password = User.objects.make_random_password()
                user = User.objects.create_user(id, email, password)
                user.first_name = first
                user.last_name = last
                user.memberjoin_set.create(year=y)
                if not settings.DEBUG:
                    if user.email != "":
                        template_mail(
                            'Welcome to Compsoc', 'memberinfo/new_user_email',
                            {
                                'first': user.first_name,
                                'last': user.last_name,
                                'username': user.username,
                                'password': password,
                                'events': Event.objects.in_future()[:5]
                            }, settings.WEBMASTER_EMAIL, [user.email])

            #sync info
            user.first_name = first
            user.last_name = last
            user.is_active = active

            user.save()
            MemberJoin.objects.get_or_create(user=user, year=y)
Beispiel #26
0
    def handle_noargs(self, **options):
        '''
        Runs main update for Compsoc membership details.  The update satisfies the
        following conditions:
        1. Internal Consistency of compsoc models
            user.is_active iff there is a join entry for the current year
        2. Equivalence between compsoc and union models
            user.is_active iff the user is a current member of compsoc or a guest
        3. User information
            compsoc members who have just had an account created, should be emailed
        '''
        from uwcs_website.shortcuts import current_year

        #1. get data from the union
        union_lookup = get_data()

        #2. soundness: if your account is not a guest account and is active then you must be a union member
        # a) sync active members info
        # b) deactivate non union members
        #for user in User.objects.exclude(member__guest=True):
        y = current_year()
        for user in User.objects.filter(is_active=True, member__guest=False):
            if union_lookup.has_key(user.username):
                (first,last,email) = union_lookup[user.username]

                # sync information
                user.first_name = first
                user.last_name = last
                if email is not None:
                    user.email = email
                else:
                    user.email = ""
                    user.is_active = False
                user.save()

                # note that they have joined this year
                MemberJoin.objects.get_or_create(user=user,year=y)

                del union_lookup[user.username]
            # if they're not listed in the union's api, could be a special case
            elif not user.is_staff:
                # next two lines should be removed when historical exec data is added
                ex, created = Group.objects.get_or_create(name=settings.EX_EXEC_GROUP_NAME)

                # if not on the exec at some point or a society
                if not (user.groups.filter(name=settings.EX_EXEC_GROUP_NAME) or Society.objects.filter(user_ptr=user)):
                    try:
                        week = warwick_week_for(datetime.now())
                    except Term.DoesNotExist:
                        week = settings.GRACE_PERIOD + 1 #assume outside of grace period

                    # if inside the grace period 
                    if week <= settings.GRACE_PERIOD:
                        # but not a member from last year
                        if not user.memberjoin_set.filter(year=current_year()-1):
                            user.is_active = False
                            user.save()
                    else:
                        user.is_active = False
                        user.save()

        #3. completeness: if you are a union member, then you must have a compsoc account
        #                 it is active iff you have a union email address
        #4. TODO: information: emails people who have just had their accounts added
        #5. consistency: ensure there exist current join years for members
        # a) create new accounts for those without
        # b) reactivate accounts for those already with inactive accounts
        for (id,(first,last,email)) in union_lookup.iteritems():

            active = True

            try:
                # find disabled accounts
                user = User.objects.get(username=id)
                print "reactivating %s" % id
                if email is None:
                    email = ""
                    active = False
                    print "cannot reactivate %s: no email address" % id
            except User.DoesNotExist:
                print "creating %s" % id
                if email is None:
                    email = ""
                    active = False
                    print "cannot activate %s: no email address" % id
                password = User.objects.make_random_password()
                user = User.objects.create_user(id,email,password)
                user.first_name = first
                user.last_name = last
                user.memberjoin_set.create(year=y)
                if not settings.DEBUG:
                    if user.email != "":
                        template_mail(
                            'Welcome to Compsoc',
                            'memberinfo/new_user_email',
                            {'first': user.first_name, 'last':user.last_name, 'username':user.username, 'password':password, 'events':Event.objects.in_future()[:5]},
                            settings.WEBMASTER_EMAIL,
                            [user.email])

            #sync info
            user.first_name = first
            user.last_name = last 
            user.is_active = active

            user.save()
            MemberJoin.objects.get_or_create(user=user,year=y)