Example #1
0
def register(request, trial):

    page_type = 'register'
    if trial == 'trial':
        trial_account = True
    else:
        trial_account = False

    if request.method == 'POST':
        user_form = UserRegisterForm(request.POST, label_suffix='')
        group_form = GroupRegisterForm(request.POST, label_suffix='')
        if user_form.is_valid() and group_form.is_valid():
            # save each form
            password = user_form.cleaned_data['password1']
            new_user = user_form.save()
            group = group_form.save()
            # associate the user with the group
            u = new_user
            group.users.add(u)
            # set the group as the user's current_group
            settings = UserSettings(user=u, current_group=group)
            settings.save()
            # generate a slug from the group name
            slug = slugify(group.name)[:20]
            group.slug = slug
            group.save()
            # set the account status to trial if required
            if trial_account == True:
                group.account_type = 'Trial'
                group.save()
            # save initial snapshots of new user and group details
            snapshot_user_details(u, password='******')
            snapshot_group_details(group)
            # log the new user in
            user = authenticate(username=new_user.username, password=password)
            login(request, user)
            # set the new user up as a participant
            participant = Participant(group=group,
                                      email=user.email,
                                      first_name=user.first_name,
                                      last_name=user.last_name)
            participant.save()
            # send the new user a welcome email
            send_welcome_email(group=group, user=user)

            return HttpResponseRedirect(reverse('welcome'))
    else:
        user_form = UserRegisterForm(label_suffix='')
        group_form = GroupRegisterForm(label_suffix='')

    return render(
        request, 'register.html', {
            'group_form': group_form,
            'page_type': page_type,
            'trial_account': trial_account,
            'user_form': user_form,
        })
Example #2
0
def register(request, trial):

    page_type = 'register'
    if trial == 'trial':
        trial_account = True
    else:
        trial_account = False
            
    if request.method == 'POST':
        user_form = UserRegisterForm(request.POST, label_suffix='')
        group_form = GroupRegisterForm(request.POST, label_suffix='')
        if user_form.is_valid() and group_form.is_valid():
            # save each form
            password = user_form.cleaned_data['password1']
            new_user = user_form.save()
            group = group_form.save()
            # associate the user with the group
            u = new_user
            group.users.add(u)
            # set the group as the user's current_group
            settings = UserSettings(user=u, current_group=group)
            settings.save()
            # generate a slug from the group name
            slug = slugify(group.name)[:20]
            group.slug = slug
            group.save()
            # set the account status to trial if required
            if trial_account == True:
                group.account_type = 'Trial'
                group.save()
            # save initial snapshots of new user and group details
            snapshot_user_details(u, password='******')
            snapshot_group_details(group)
            # log the new user in
            user = authenticate(username=new_user.username,
                                password=password)
            login(request, user)
            # set the new user up as a participant
            participant = Participant(group=group, email=user.email,
                                      first_name=user.first_name,
                                      last_name=user.last_name)
            participant.save()
            # send the new user a welcome email
            send_welcome_email(group=group, user=user)
                        
            return HttpResponseRedirect(reverse('welcome'))
    else:
        user_form = UserRegisterForm(label_suffix='')
        group_form = GroupRegisterForm(label_suffix='')
        
    return render(request, 'register.html', {
        'group_form': group_form,
        'page_type': page_type,
        'trial_account': trial_account,
        'user_form': user_form,
    })
    def handle(self, *args, **options):
        """
        Initialises the user and group update logs.
        For use once only, on 11APR2014.
        """
        users = User.objects.all()
        for user in users:
            snapshot_user_details(user, password='******')

        groups = Group.objects.all()
        for group in groups:
            snapshot_group_details(group)
Example #4
0
    def handle(self, *args, **options):
        """
        Initialises the user and group update logs.
        For use once only, on 11APR2014.
        """
        users = User.objects.all()
        for user in users:
            snapshot_user_details(user, password='******')

        groups = Group.objects.all()
        for group in groups:
            snapshot_group_details(group)
Example #5
0
def password_change(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('index'))

    if request.method == "POST":
        form = PasswordChangeForm(request.user, request.POST, label_suffix='')
        if form.is_valid():
            form.save()
            snapshot_user_details(request.user, password='******')
            return HttpResponseRedirect(reverse('password-changed'))
    else:
        form = PasswordChangeForm(request.user, label_suffix='')

    menu = {'parent': 'account'}
    return render(request, 'password_change.html', {
                  'menu': menu,
                  'form': form,
                  })
Example #6
0
def user_edit(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('index'))

    if request.method == "POST":
        form = UserDetailsForm(request.POST, instance=request.user,
                                label_suffix='')
        if form.is_valid():
            form.save()
            snapshot_user_details(request.user, password='******')
            return HttpResponseRedirect(reverse('account'))
    else:
        form = UserDetailsForm(instance=request.user, label_suffix='')

    menu = {'parent': 'account'}
    return render(request, 'user_edit.html', {
                  'menu': menu,
                  'form': form,
                  })