Exemplo n.º 1
0
def signin(request):
    """
    One time signin to create a bookmarklet using HTTP POST.

    The only required field is the email address

    Create a new user and return the URL to the user bookmarklet
    """
    # If the form has been submitted...
    form = SigninForm(request.POST)  # A form bound to the POST data
    if form.is_valid():  # All validation rules pass
        data = dict(form.cleaned_data)

        user = OAUser.objects.create(
            name=data['name'],
            email=data['email'],
            profession=data['profession'],
            slug=uuid.uuid4().hex,
            mailinglist=data['mailinglist'],
        )
        user.save()

        return HttpResponse(json.dumps({'url': user.get_bookmarklet_url()}),
                            content_type="application/json")
    return HttpResponseServerError(json.dumps({'errors': form._errors}),
                                   content_type="application/json")
Exemplo n.º 2
0
def signin(request):
    """
    One time signin to create a bookmarklet using HTTP POST.

    The only required field is the email address

    Create a new user and return the URL to the user bookmarklet
    """
    if request.method == 'POST':
        # If the form has been submitted...
        form = SigninForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # TODO: do stuff here
            manager = get_user_model()._default_manager
            data = dict(form.cleaned_data)
            data['username'] = data['email']

            try:
                user = User.objects.get(username=data['email'])
                user.mailinglist = data['mailinglist']
                user.name = data['name']
                user.profession = data['profession']
                user.usernmae = data['username']
                user.save()
            except User.DoesNotExist:
                # Default the username to be email address
                user = manager.create_user(**data)

            return HttpResponse(json.dumps({'url': user.get_bookmarklet_url()}), content_type="application/json")
    return HttpResponseServerError(json.dumps({'errors': form._errors}), content_type="application/json")
Exemplo n.º 3
0
def signin(request):
    """
    One time signin to create a bookmarklet using HTTP POST.

    The only required field is the email address

    Create a new user and return the URL to the user bookmarklet
    """
    # If the form has been submitted...
    form = SigninForm(request.POST)  # A form bound to the POST data
    if form.is_valid():  # All validation rules pass
        data = dict(form.cleaned_data)

        user = OAUser.objects.create(name=data['name'],
                                     email=data['email'],
                                     profession=data['profession'],
                                     slug=uuid.uuid4().hex,
                                     mailinglist=data['mailinglist'],
                                     )
        user.save()

        user.send_confirmation_email()

        return HttpResponse(json.dumps({'url': user.get_bookmarklet_url()}), content_type="application/json")
    return HttpResponseServerError(json.dumps({'errors': form._errors}), content_type="application/json")
Exemplo n.º 4
0
def homepage(req):
    # Need to lazy import the OAEvent model so that tests work with
    # mocks
    c = {}

    from oabutton.apps.bookmarklet.models import OAEvent

    evt_count = OAEvent.objects.count()
    data = []

    for evt in OAEvent.objects.all():
        data.append({
            'doi': evt.doi,
            'coords': dict(evt.coords),
            'accessed': evt.accessed.strftime("%b %d, %Y"),
            'user_name': evt.user_name,
            'user_profession': evt.user_profession,
            'description': evt.description,
            'story': evt.story,
            'url': evt.url,
        })

    c.update({
        'DEBUG': settings.DEBUG,
        'count': evt_count,
        'events': json.dumps(data),
        'hostname': settings.HOSTNAME,
        'signin_form': SigninForm(),
        'team_data': teamdata,
        'thanks_data': thanksdata
    })

    return render_to_response('web/start.jade',
                              c,
                              context_instance=RequestContext(req))