示例#1
0
 def send_invite_email():
     send_email(
         "You've been invited to collaborate on a Montage project",
         EXISTING_USER_INVITED.format(
             project_name=project.name,
             home_link='https://montage.meedan.com'),
         email
     )
示例#2
0
文件: views.py 项目: Laurian/montage
    def post(self, request, *args, **kwargs):
        """
            Handles form submissions to create a new user
        """
        form = InviteNewUserForm(request.POST)

        if form.is_valid():
            pu = PendingUser.objects.create(email=form.cleaned_data['email'],
                                            is_whitelisted=True)

            send_email(
                "You've been invited to join Montage",
                NEW_USER_INVITED_NO_PROJECT.format(
                    home_link='http://montage.storyful.com'), pu.email)
            return redirect('user_management')

        context = self.get_context_data(**kwargs)
        context['form'] = form

        return self.render_to_response(context)
示例#3
0
    def users_create(self, request):
        """
            Creates a new user

            Super users only
        """

        # TODO: review the user invite flow
        user, created = get_user_model().objects.get_or_create(
            email=request.email,
            defaults={
                'username': request.email,
                'is_active': False
            })

        subject = "Montage Invitation"
        message = """You've been invited to join Montage
 https://montage.storyful.com"""
        from greenday_core.utils import send_email
        send_email(subject, message, [request.email])

        return self.mapper.map(user)
示例#4
0
    def project_add_user(self, request):
        project_users = []
        for email in get_emails(request.email):
            """
            Adds a user to the project
            """
            project = self.get_project(
                request.project_id,
                check_fn=lambda p: p.is_owner_or_admin(self.current_user))

            def send_invite_email():
                send_email(
                    "You've been invited to collaborate on a Montage project",
                    EXISTING_USER_INVITED.format(
                        project_name=project.name,
                        home_link='https://montage.storyful.com'), email)

            User = get_user_model()

            project_user = None
            try:
                user = User.objects.get(email=email)

                project_user = (project.add_admin if request.as_admin else
                                project.add_assigned)(user)

                eventbus.publish_appevent(
                    kind=EventKind.USERINVITEDASPROJECTADMIN if
                    request.as_admin else EventKind.USERINVITEDASPROJECTUSER,
                    object_id=user.pk,
                    project_id=project.pk,
                    user=self.current_user)

                send_invite_email()

            except User.DoesNotExist:
                pending_user, created = User.objects.get_or_create(
                    email=email, username=email)

                project_user = (project.add_admin if request.as_admin else
                                project.add_assigned)(pending_user)

                eventbus.publish_appevent(
                    kind=EventKind.PENDINGUSERINVITEDASPROJECTADMIN
                    if request.as_admin else
                    EventKind.PENDINGUSERINVITEDASPROJECTUSER,
                    object_id=pending_user.pk,
                    project_id=project.pk,
                    meta=pending_user.email,
                    user=self.current_user)

                if created:
                    send_email(
                        "You've been invited to join Montage",
                        NEW_USER_INVITED.format(
                            project_name=project.name,
                            home_link='https://montage.storyful.com'),
                        pending_user.email)
                else:
                    send_invite_email()
            project_users.append(project_user)

        return ProjectUserListResponse(items=map(self.user_mapper.map,
                                                 project_users),
                                       is_list=True)