Beispiel #1
0
 def post(self, request, *args, **kwargs):
     form = CreateUserForm(request.POST)
     if form.is_valid():
         if SessionManager.user_exists(email=request.POST['email']):
             messages.error(
                 request, 'A user with this email address already exists.')
             self.context.update({
                 'form': form,
             })
             return HttpResponse(self.template.render(
                 self.context, request))
         else:
             user = SessionManager.create_user(
                 email=request.POST['email'],
                 username=request.POST['username'],
                 password=request.POST['password'])
             messages.success(
                 request,
                 'Registration complete! Please log in to continue.')
             return redirect(reverse('session_manager_login'))
     else:
         self.context.update({
             'form': form,
         })
         return HttpResponse(self.template.render(self.context, request))
Beispiel #2
0
 def post(self, request, *args, **kwargs):
     form = CreateUserForm(request.POST)
     if form.is_valid():
         user = SessionManager.create_user(
             email=request.POST['email'],
             password=request.POST['password'],
             first_name=request.POST['first_name'],
             last_name=request.POST['last_name'])
         messages.success(
             request, 'Registration complete! Please log in to continue.')
         return redirect(reverse('session_manager_login'))
     else:
         self.context.update({
             'form': form,
         })
         return HttpResponse(self.template.render(self.context, request))
Beispiel #3
0
    def post(self, request, *args, **kwargs):
        if 'search_term' in request.POST:
            form = SearchUsersForm(request.POST)
            stage = 1
        elif 'confirmed_invitation' in request.POST:
            stage = 2
        else:
            stage = 3

        if stage == 1:
            django_users = SessionManager.full_search(
                request.POST['search_term'])
            self.context.update({
                'search_result_users': django_users,
                'form': InviteUserForm()
            })
            self.template = loader.get_template(
                'teambeat/user-search-confirm-results.html')
            return HttpResponse(self.template.render(self.context, request))
        elif stage == 2:
            django_user = SessionManager.get_user_by_username(
                request.POST['email'])
            existing_org_user = OrganizationUser.objects.filter(
                organization=self.organization, user=django_user).first()
            if existing_org_user and existing_org_user.active == True:
                messages.error(request,
                               'This user is already in your organization')
                return HttpResponse(self.template.render(
                    self.context, request))
            else:
                org_invitation_exists = OrganizationInvitation.objects.filter(
                    organization=self.organization, user=django_user).first()
                if org_invitation_exists:
                    messages.success(
                        request,
                        '{} already has an invitation to the organization.'.
                        format(org_invitation_exists.display_name))
                else:
                    org_invitation = OrganizationInvitation(
                        organization=self.organization, user=django_user)
                    org_invitation.save()
                    self.organization.send_org_invitation_email(
                        _to=django_user, _from=self.user)
                    messages.success(
                        request, 'Invited {} to organization'.format(
                            org_invitation.display_name))
            if request.session.get('current_team_id'):
                return redirect(
                    reverse('team_admin_dashboard',
                            kwargs={
                                'team_uuid':
                                request.session.get('current_team_id')
                            }))
            return redirect(reverse('organization_admin_dashboard'))
        elif stage == 3:
            django_user = SessionManager.create_user(
                email=request.POST['email'])
            org_invitation = OrganizationInvitation(
                organization=self.organization, user=django_user)
            org_invitation.save()
            self.organization.send_app_invitation_email(_to=django_user,
                                                        _from=self.user)
            messages.success(
                request, 'Invited {} to TeamBeat for your organization'.format(
                    django_user.email))
            if request.session.get('current_team_id'):
                return redirect(
                    reverse('team_admin_dashboard',
                            kwargs={
                                'team_uuid':
                                request.session.get('current_team_id')
                            }))
            return redirect(reverse('organization_admin_dashboard'))

        self.context['form'] = form
        return HttpResponse(self.template.render(self.context, request))