Esempio n. 1
0
def process_register_form(request, auth_method='session'):
    form = NewUserForm(
        request.POST) if auth_method == 'session' else NewUserFormAPI(
            request.POST)
    token_dict = None
    if form.is_valid():
        try:
            with transaction.atomic():
                new_user = form.save()
                user = authenticate(email=form.cleaned_data['email'],
                                    password=form.cleaned_data['password1'])
                p = UserProfile(id=user.id)
                p.assign_slug()
                p.join_invited_groups()
                if PARTNER_GROUP_EMAIL_PATTERN_LOOKUP_FILE:
                    p.add_partner_group_by_email()
                if hasattr(request, "interfaceLang"):
                    p.settings["interface_language"] = request.interfaceLang

                p.save()
        except Exception:
            return {"error": "something went wrong"}
        if auth_method == 'session':
            auth_login(request, user)
        elif auth_method == 'jwt':
            token_dict = TokenObtainPairSerializer().validate({
                "username":
                form.cleaned_data['email'],
                "password":
                form.cleaned_data['password1']
            })
    return {
        k: v[0] if len(v) > 0 else unicode(v)
        for k, v in form.errors.items()
    }, token_dict, form
Esempio n. 2
0
def register(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect("/login")

    next = request.REQUEST.get('next', '')

    if request.method == 'POST':
        form = NewUserForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            user = authenticate(email=form.cleaned_data['email'],
                                password=form.cleaned_data['password1'])
            auth_login(request, user)
            p = UserProfile(id=user.id)
            p.assign_slug()
            p.join_invited_groups()
            p.settings["interface_language"] = request.interfaceLang
            p.save()
            if "noredirect" in request.POST:
                return HttpResponse("ok")
            elif "new?assignment=" in request.POST.get("next",""):
                next = request.POST.get("next", "")
                return HttpResponseRedirect(next)
            else:
                next = request.POST.get("next", "/") + "?welcome=to-sefaria"
                return HttpResponseRedirect(next)
    else:
        if request.REQUEST.get('educator', ''):
            form = NewUserForm(initial={'subscribe_educator': True})
        else:
            form = NewUserForm()

    return render_to_response("registration/register.html",
                                {'form' : form, 'next': next},
                                RequestContext(request))
Esempio n. 3
0
def register(request):
    if request.user.is_authenticated:
        return redirect("login")

    next = request.GET.get('next', '')

    if request.method == 'POST':
        form = NewUserForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            user = authenticate(email=form.cleaned_data['email'],
                                password=form.cleaned_data['password1'])
            auth_login(request, user)
            p = UserProfile(id=user.id)
            p.assign_slug()
            p.join_invited_groups()
            p.settings["interface_language"] = request.interfaceLang
            p.save()
            if "noredirect" in request.POST:
                return HttpResponse("ok")
            elif "new?assignment=" in request.POST.get("next",""):
                next = request.POST.get("next", "")
                return HttpResponseRedirect(next)
            else:
                next = request.POST.get("next", "/") + "?welcome=to-sefaria"
                return HttpResponseRedirect(next)
    else:
        if request.GET.get('educator', ''):
            form = NewUserForm(initial={'subscribe_educator': True})
        else:
            form = NewUserForm()

    return render(request, "registration/register.html", {'form': form, 'next': next})
Esempio n. 4
0
def register(request):
    if request.user.is_authenticated:
        return redirect("login")

    next = request.GET.get('next', '')

    if request.method == 'POST':
        form = NewUserForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            user = authenticate(email=form.cleaned_data['email'],
                                password=form.cleaned_data['password1'])
            auth_login(request, user)
            p = UserProfile(id=user.id)
            p.assign_slug()
            p.join_invited_groups()
            if PARTNER_GROUP_EMAIL_PATTERN_LOOKUP_FILE:
                p.add_partner_group_by_email()
            p.settings["interface_language"] = request.interfaceLang
            p.save()
            if "noredirect" in request.POST:
                return HttpResponse("ok")
            elif "new?assignment=" in request.POST.get("next", ""):
                next = request.POST.get("next", "")
                return HttpResponseRedirect(next)
            else:
                next = request.POST.get("next", "/")
                if "?" in next:
                    next += "&welcome=to-sefaria"
                else:
                    next += "?welcome=to-sefaria"
                return HttpResponseRedirect(next)
    else:
        if request.GET.get('educator', ''):
            form = NewUserForm(initial={'subscribe_educator': True})
        else:
            form = NewUserForm()

    return render(request, "registration/register.html", {
        'form': form,
        'next': next
    })
Esempio n. 5
0
def process_register_form(request, auth_method='session'):
    form = SefariaNewUserForm(request.POST) if auth_method == 'session' else SefariaNewUserFormAPI(request.POST)
    token_dict = None
    if form.is_valid():
        with transaction.atomic():
            new_user = form.save()
            user = authenticate(email=form.cleaned_data['email'],
                                password=form.cleaned_data['password1'])
            p = UserProfile(id=user.id)
            p.assign_slug()
            p.join_invited_groups()
            if hasattr(request, "interfaceLang"):
                p.settings["interface_language"] = request.interfaceLang

            p.save()
        if auth_method == 'session':
            auth_login(request, user)
        elif auth_method == 'jwt':
            token_dict = TokenObtainPairSerializer().validate({"username": form.cleaned_data['email'], "password": form.cleaned_data['password1']})
    return {
        k: v[0] if len(v) > 0 else str(v) for k, v in list(form.errors.items())
    }, token_dict, form