コード例 #1
0
def register(request):
    if request.user.is_authenticated():
        messages.error(request, _(u'You cannot be logged in when registering.'))
        return HttpResponseRedirect('/')
    else:
        if request.method == 'POST':
            form = RegisterForm(request.POST)
            if form.is_valid():
                cleaned = form.cleaned_data

                # Create user
                user = User(
                    username=cleaned['desired_username'],
                    first_name=cleaned['first_name'],
                    last_name=cleaned['last_name'],
                    email=cleaned['email'],
                )
                user.set_password(cleaned['password'])
                user.is_active = False
                user.save()

                # Create userprofile
                up = UserProfile(
                    user=user,
                    nick=cleaned['desired_username'],
                    date_of_birth=cleaned['date_of_birth'],
                    zip_code=cleaned['zip_code'],
                    address=cleaned['address'],
                    phone=cleaned['phone'],
                )
                up.save()

                # Create the registration token
                token = uuid.uuid4().hex
                rt = RegisterToken(user=user, token=token)
                rt.save()

                link = request.build_absolute_uri(reverse('auth_verify', args=[token]))
                context = {
                    'link': link,
                }
                txt_message = render_to_string('auth/email/verify_account.txt', context, request).strip()
                html_message = render_to_string('auth/email/verify_account.html', context, request).strip()
                send_mail(
                    subject=_(u'Verify your account'),
                    from_email=settings.STUDLAN_FROM_MAIL,
                    recipient_list=[user.email],
                    message=txt_message,
                    html_message=html_message,
                )

                messages.success(request, _(u'Registration successful. Check your email for verification instructions.'))

                return HttpResponseRedirect('/')
            else:
                form = RegisterForm(request.POST, auto_id=True, error_class=InlineSpanErrorList)
        else:
            form = RegisterForm()

        return render(request, 'auth/register.html', {'form': form})
コード例 #2
0
def direct_register(request, lan_id):
    lan = get_object_or_404(LAN, id=lan_id)

    if lan.is_ended():
        messages.error(request,
                       _(u'The LAN is ended, arrivals can\'t be changed.'))
        return redirect('/')

    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            cleaned = form.cleaned_data

            # Create user
            user = User(
                username=cleaned['desired_username'],
                first_name=cleaned['first_name'],
                last_name=cleaned['last_name'],
                email=cleaned['email'],
            )
            user.set_password(cleaned['password'])
            user.is_active = True
            user.save()

            # Create userprofile
            up = UserProfile(
                user=user,
                nick=cleaned['desired_username'],
                date_of_birth=cleaned['date_of_birth'],
                zip_code=cleaned['zip_code'],
                address=cleaned['address'],
                phone=cleaned['phone'],
            )
            up.save()

            attendee = Attendee(lan=lan, user=user)
            attendee.save()

            messages.success(request, _(u'Registration successful.'))

            return redirect('/auth/direct_register')
        else:
            form = RegisterForm(request.POST,
                                auto_id=True,
                                error_class=InlineSpanErrorList)
    else:
        form = RegisterForm()

    breadcrumbs = (
        (lan, lan.get_absolute_url()),
        (_(u'Manual Registration'), ''),
    )
    context = {
        'breadcrumbs': breadcrumbs,
        'lan': lan,
        'form': form,
    }

    return render(request, 'auth/direct_register.html', context)
コード例 #3
0
ファイル: views.py プロジェクト: sklirg/studlan
def register(request):
    if request.user.is_authenticated():
        messages.error(request, _(u'You cannot be logged in when registering.'))
        return HttpResponseRedirect('/')
    else:
        if request.method == 'POST':
            form = RegisterForm(request.POST)
            if form.is_valid():
                cleaned = form.cleaned_data

                # Create user
                user = User(
                    username=cleaned['desired_username'],
                    first_name=cleaned['first_name'],
                    last_name=cleaned['last_name'],
                    email=cleaned['email'],
                )
                user.set_password(cleaned['password'])
                user.is_active = False
                user.save()

                # Create userprofile
                up = UserProfile(
                    user=user,
                    nick=cleaned['desired_username'],
                    date_of_birth=cleaned['date_of_birth'],
                    zip_code=cleaned['zip_code'],
                    address=cleaned['address'],
                    phone=cleaned['phone'],
                )
                up.save()

                # Create the registration token
                token = uuid.uuid4().hex
                rt = RegisterToken(user=user, token=token)
                rt.save()

                email_message = create_verify_message(request.META['HTTP_HOST'], token)

                send_mail(_(u'Verify your account'), email_message, settings.STUDLAN_FROM_MAIL, [user.email,], fail_silently=False)

                messages.success(request, _(u'Registration successful. Check your email for verification instructions.'))

                return HttpResponseRedirect('/')
            else:
                form = RegisterForm(request.POST, auto_id=True, error_class=InlineSpanErrorList)
        else:
            form = RegisterForm()

        return render(request, 'auth/register.html', {'form': form, })
コード例 #4
0
ファイル: views.py プロジェクト: sklirg/studlan
def direct_register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            cleaned = form.cleaned_data
            lan = LAN.objects.filter(end_date__gte=datetime.now())[0]

            if not lan:
                messages.error(request, u'No upcoming LAN was found.')
                return HttpResponseRedirect('/auth/direct_register')

            # Create user
            user = User(
               username=cleaned['desired_username'],
               first_name=cleaned['first_name'],
               last_name=cleaned['last_name'],
               email=cleaned['email'],
            )
            user.set_password(cleaned['password'])
            user.is_active = True
            user.save()

            # Create userprofile
            up = UserProfile(
                user=user,
                nick=cleaned['desired_username'],
                date_of_birth=cleaned['date_of_birth'],
                zip_code=cleaned['zip_code'],
                address=cleaned['address'],
                phone=cleaned['phone'],
            )
            up.save()

            attendee = Attendee(lan=lan, user=user)
            attendee.save()

            messages.success(request, _(u'Registration successful.'))

            return HttpResponseRedirect('/auth/direct_register')
        else:
            form = RegisterForm(request.POST, auto_id=True, error_class=InlineSpanErrorList)
    else:
        form = RegisterForm()
        lan = LAN.objects.filter(end_date__gte=datetime.now())[0]

    return render(request, 'auth/direct_register.html', {'form': form, 'lan': lan})
コード例 #5
0
def direct_register(request):
    lan = LAN.objects.filter(end_date__gte=datetime.now()).first()
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            cleaned = form.cleaned_data

            if lan is None:
                messages.error(request, _(u'No upcoming LAN was found.'))
                return HttpResponseRedirect('/auth/direct_register')

            # Create user
            user = User(
                username=cleaned['desired_username'],
                first_name=cleaned['first_name'],
                last_name=cleaned['last_name'],
                email=cleaned['email'],
            )
            user.set_password(cleaned['password'])
            user.is_active = True
            user.save()

            # Create userprofile
            up = UserProfile(
                user=user,
                nick=cleaned['desired_username'],
                date_of_birth=cleaned['date_of_birth'],
                zip_code=cleaned['zip_code'],
                address=cleaned['address'],
                phone=cleaned['phone'],
            )
            up.save()

            attendee = Attendee(lan=lan, user=user)
            attendee.save()

            messages.success(request, _(u'Registration successful.'))

            return HttpResponseRedirect('/auth/direct_register')
        else:
            form = RegisterForm(request.POST, auto_id=True, error_class=InlineSpanErrorList)
    else:
        form = RegisterForm()

    return render(request, 'auth/direct_register.html', {'form': form, 'lan': lan})
コード例 #6
0
ファイル: views.py プロジェクト: SUNET/ni
def whoami(request):
    if request.method == 'GET':
        user_profile = getattr(request.user, 'profile', None)

        if not user_profile:
            user_profile = UserProfile(user=request.user,
                                       email=request.user.email)
            user_profile.save()

        user = {
            'id': user_profile.pk,
            'userid': request.user.pk,
            'display_name': user_profile.display_name,
            'email': request.user.email,
            'landing_page': user_profile.landing_page,
            'landing_choices': user_profile.LANDING_CHOICES,
            'view_network': user_profile.view_network,
            'view_services': user_profile.view_services,
            'view_community': user_profile.view_community
        }
        return JsonResponse(user)
    return httpResponse(status_code=405)
コード例 #7
0
def create_profile(user, data=None):
    profile = UserProfile(user=user)
    profile.save()

    return profile
コード例 #8
0
    def mutate_and_get_payload(cls, root, info, **input):
        if not (info.context and info.context.user.is_authenticated and \
            (sriutils.authorize_superadmin(info.context.user) or \
                sriutils.user_is_admin(info.context.user)) ):
            raise GraphQLAuthException()

        user_id = input.get("user_id")
        userprofile = None
        success = False
        errors = None

        if not DjangoUser.objects.filter(id=user_id).exists():
            errors = [
                ErrorType(
                    field="_",
                    messages=\
                        ["An error occurred while processing your request"])
            ]

            return EditUserProfile(success=success,
                                   errors=errors,
                                   userprofile=userprofile)

        the_user = DjangoUser.objects.get(id=user_id)

        # if user profile doesn't exists, we should create one
        up_exists = DjangoUserProfile.objects.all().exists() and \
                        DjangoUserProfile.objects.filter(user=the_user).exists()

        if not up_exists:
            userprofile = DjangoUserProfile(user=the_user)
        else:
            userprofile = DjangoUserProfile.objects.get(user=the_user)

        # get optional values
        display_name = input.get("display_name")
        email = input.get("email", None)
        is_staff = input.get("is_staff", False)
        is_active = input.get("is_active", False)
        landing_page = input.get("landing_page", LandingPage.COMMUNITY)
        view_network = input.get("view_network", False)
        view_services = input.get("view_services", False)
        view_community = input.get("view_community", False)

        # set the values
        if display_name:
            userprofile.display_name = display_name

        if email:
            userprofile.email = email
            the_user.email = email

        the_user.is_staff = is_staff
        the_user.is_active = is_active
        the_user.save()

        userprofile.landing_page = landing_page
        userprofile.view_network = view_network
        userprofile.view_services = view_services
        userprofile.view_community = view_community

        userprofile.save()
        success = True

        ret = EditUserProfile(success=success,
                              errors=errors,
                              userprofile=userprofile)

        return ret