Пример #1
0
def create_invited_user(request, key):
    context = {}
    context['key'] = key
    invitation = users_manager.get_invitation(key)

    if request.user.is_authenticated():
        return redirect('/user/dashboard')

    if request.method == 'POST':
        form = InvitedUserCreateForm(request.POST)
        if form.is_valid() and invitation != None:
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            phone = form.cleaned_data['phone']
            try:
                users_manager.create_user(first_name, last_name, username, password, invitation.email, phone)
                bands_manager.add_band_member(invitation.band.id, username)
                # authenticate and login
                user = authenticate(username=username, password=password)
                login_auth(request, user)
                return redirect('/user/dashboard')
            except Exception as exc:
                # 400
                form.errors['__all__'] = form.error_class(["Error: %s" % exc.message])
    elif invitation != None:
        form = InvitedUserCreateForm({'email': invitation.email})
    else:
        redirect('/404')

    # GET / POST with invalid input
    context['form'] = form
    return render_to_response('user/create.html', context, context_instance=RequestContext(request))
Пример #2
0
def add_band_member(request, band_id):
    context = {}
    username = request.POST['username']

    try:
        band = bands_manager.get_band(band_id)
        if not band.is_member(request.user):
            raise Exception("You have no permission to add members to this band cause you are not a member of it.")

        bands_manager.add_band_member(band_id, username)
        response_data = {'result': True}
    except Exception as exc:
        response_data = {'result': False}
    return HttpResponse(simplejson.dumps(response_data), mimetype='application/json')