Exemple #1
0
def register_view(request, template_name='registration.html'):
    """
    Form that send registration email to user
    """
    context = {}
    if request.method == "POST":
        form = RegisterForm(request.POST)
        if form.is_valid():
            registration = form.save()
            context['registration'] = registration
            context['email_to'] = registration.email
            text_content = render_string(request,
                                         'email/registration.txt',
                                         context)
            send_mail('Your Registration is done',
                      text_content,
                      DEFAULT_EMAIL_FROM,
                      [registration.email, ])
            return HttpResponseRedirect(reverse('registration_sent'))
        else:
            # form is invalid
            context['register_form'] = form
    else:
        # no post, user just arrived
        context['register_form'] = RegisterForm()
    return render_response(request, template_name, context)
Exemple #2
0
def register(request):
    self_register = SettingProperties \
        .get_bool(constants.OPPIA_ALLOW_SELF_REGISTRATION,
                  settings.OPPIA_ALLOW_SELF_REGISTRATION)
    if not self_register:
        raise Http404

    if request.method == 'POST':  # if form submitted...
        form = RegisterForm(request.POST)
        if form.is_valid():  # All validation rules pass
            # Create new user
            username = form.cleaned_data.get("username")
            password = form.cleaned_data.get("password")
            register_form_process(form)

            u = authenticate(username=username, password=password)
            if u is not None and u.is_active:
                login(request, u)
                return HttpResponseRedirect('thanks/')
    else:
        form = RegisterForm(initial={
            'next': filter_redirect(request.GET),
        })

    return render(request, STR_COMMON_FORM, {
        'form': form,
        'title': _(u'Register')
    })
Exemple #3
0
def register(request):
    self_register = SettingProperties.get_int(constants.OPPIA_ALLOW_SELF_REGISTRATION, settings.OPPIA_ALLOW_SELF_REGISTRATION)
    if not self_register:
        raise Http404

    if request.method == 'POST':  # if form submitted...
        form = RegisterForm(request.POST)
        if form.is_valid():  # All validation rules pass
            # Create new user
            username = form.cleaned_data.get("username")
            email = form.cleaned_data.get("email")
            password = form.cleaned_data.get("password")
            first_name = form.cleaned_data.get("first_name")
            last_name = form.cleaned_data.get("last_name")
            user = User.objects.create_user(username, email, password)
            user.first_name = first_name
            user.last_name = last_name
            user.save()
            user_profile = UserProfile()
            user_profile.user = user
            user_profile.job_title = form.cleaned_data.get("job_title")
            user_profile.organisation = form.cleaned_data.get("organisation")
            user_profile.save()
            u = authenticate(username=username, password=password)
            if u is not None and u.is_active:
                login(request, u)
                return HttpResponseRedirect('thanks/')
            return HttpResponseRedirect('thanks/')  # Redirect after POST
    else:
        form = RegisterForm(initial={'next': filter_redirect(request.GET), })

    return render(request, 'oppia/form.html',
                              {'form': form,
                               'title': _(u'Register'), })
Exemple #4
0
def register_view(request):
    """
    Formular which send registration email to user
    """
    context = {}
    if request.method == "POST":
        form = RegisterForm(request.POST)
        if form.is_valid():
            registration = form.save()
            context["registration"] = registration
            context["email_to"] = registration.email
            text_content = render_string(request, "email/registration.txt", context)
            send_mail("Registration to kaaloo", text_content, settings.DEFAULT_EMAIL_FROM, [registration.email])
            return HttpResponseRedirect(reverse("registration_sent"))
        else:
            # form is invalid
            context["register_form"] = form
    else:
        # no post, user just arrived
        context["register_form"] = RegisterForm()
    context["login_form"] = LoginForm()
    return render_response(request, "profile/login.html", context)
Exemple #5
0
    def obj_create(self, bundle, **kwargs):
        self_register = SettingProperties.get_int(constants.OPPIA_ALLOW_SELF_REGISTRATION, settings.OPPIA_ALLOW_SELF_REGISTRATION)
        if not self_register:
            raise BadRequest(_(u'Registration is disabled on this server.'))
        required = ['username', 'password', 'passwordagain', 'email', 'firstname', 'lastname']

        check_required_params(bundle, required)

        data = {'username': bundle.data['username'],
                'password': bundle.data['password'],
                'password_again': bundle.data['passwordagain'],
                'email': bundle.data['email'] if 'email' in bundle.data else '',
                'first_name': bundle.data['firstname'],
                'last_name': bundle.data['lastname'], }
        rf = RegisterForm(data)
        if not rf.is_valid():
            str = ""
            for key, value in rf.errors.items():
                for error in value:
                    str += error + "\n"
            raise BadRequest(str)
        else:
            username = bundle.data['username']
            password = bundle.data['password']
            email = bundle.data['email']
            first_name = bundle.data['firstname']
            last_name = bundle.data['lastname']
        try:
            bundle.obj = User.objects.create_user(username, email, password)
            bundle.obj.first_name = first_name
            bundle.obj.last_name = last_name
            bundle.obj.save()

            user_profile = UserProfile()
            user_profile.user = bundle.obj
            if 'jobtitle' in bundle.data:
                user_profile.job_title = bundle.data['jobtitle']
            if 'organisation' in bundle.data:
                user_profile.organisation = bundle.data['organisation']
            if 'phoneno' in bundle.data:
                user_profile.phone_number = bundle.data['phoneno']
            user_profile.save()

            u = authenticate(username=username, password=password)
            if u is not None and u.is_active:
                login(bundle.request, u)
                # Add to tracker
                tracker = Tracker()
                tracker.user = u
                tracker.type = 'register'
                tracker.ip = bundle.request.META.get('REMOTE_ADDR', api.DEFAULT_IP_ADDRESS)
                tracker.agent = bundle.request.META.get('HTTP_USER_AGENT', 'unknown')
                tracker.save()
            key = ApiKey.objects.get(user=u)
            bundle.data['api_key'] = key.key
        except IntegrityError:
            raise BadRequest(_(u'Username "%s" already in use, please select another' % username))
        del bundle.data['passwordagain']
        del bundle.data['password']
        del bundle.data['firstname']
        del bundle.data['lastname']
        return bundle
Exemple #6
0
    def obj_create(self, bundle, **kwargs):
        self_register = SettingProperties \
            .get_bool(constants.OPPIA_ALLOW_SELF_REGISTRATION,
                      settings.OPPIA_ALLOW_SELF_REGISTRATION)
        if not self_register:
            raise BadRequest(_(u'Registration is disabled on this server.'))
        required = [
            'username', 'password', 'passwordagain', 'first_name', 'last_name'
        ]
        check_required_params(bundle, required)

        data = {
            'username': bundle.data['username'],
            'password': bundle.data['password'],
            'password_again': bundle.data['passwordagain'],
            'email': bundle.data['email'] if 'email' in bundle.data else '',
            'first_name': bundle.data['first_name'],
            'last_name': bundle.data['last_name'],
        }

        custom_fields = CustomField.objects.all()
        for custom_field in custom_fields:
            try:
                data[custom_field.id] = bundle.data[custom_field.id]
            except KeyError:
                pass

        rf = RegisterForm(data)
        if not rf.is_valid():
            str = ""
            for key, value in rf.errors.items():
                for error in value:
                    str += error + "\n"
            raise BadRequest(str)
        else:
            username = bundle.data['username']
            password = bundle.data['password']
            email = bundle.data['email'] if 'email' in bundle.data else '',
            first_name = bundle.data['first_name']
            last_name = bundle.data['last_name']

        try:
            bundle.obj = User.objects.create_user(username=username,
                                                  password=password)
            bundle.obj.first_name = first_name
            bundle.obj.email = email
            bundle.obj.last_name = last_name
            bundle.obj.save()
        except IntegrityError:
            raise BadRequest(
                _(u'Username "%s" already in use, please select another' %
                  username))

        self.process_register_base_profile(bundle)

        self.process_register_custom_fields(bundle)

        u = authenticate(username=username, password=password)
        if u is not None and u.is_active:
            login(bundle.request, u)
            # Add to tracker
            tracker = Tracker()
            tracker.user = u
            tracker.type = 'register'
            tracker.ip = bundle.request.META.get('REMOTE_ADDR',
                                                 DEFAULT_IP_ADDRESS)
            tracker.agent = bundle.request.META.get('HTTP_USER_AGENT',
                                                    'unknown')
            tracker.save()
        key = ApiKey.objects.get(user=u)
        bundle.data['api_key'] = key.key

        del bundle.data['passwordagain']
        del bundle.data['password']
        del bundle.data['first_name']
        del bundle.data['last_name']
        return bundle
    def obj_create(self, bundle, **kwargs):
        self_register = SettingProperties.get_int(constants.OPPIA_ALLOW_SELF_REGISTRATION, settings.OPPIA_ALLOW_SELF_REGISTRATION)
        if not self_register:
            raise BadRequest(_(u'Registration is disabled on this server.'))
        required = ['username', 'password', 'passwordagain', 'email', 'firstname', 'lastname']

        check_required_params(bundle, required)

        data = {'username': bundle.data['username'],
                'password': bundle.data['password'],
                'password_again': bundle.data['passwordagain'],
                'email': bundle.data['email'],
                'first_name': bundle.data['firstname'],
                'last_name': bundle.data['lastname'], }
        rf = RegisterForm(data)
        if not rf.is_valid():
            str = ""
            for key, value in rf.errors.items():
                for error in value:
                    str += error + "\n"
            raise BadRequest(str)
        else:
            username = bundle.data['username']
            password = bundle.data['password']
            email = bundle.data['email']
            first_name = bundle.data['firstname']
            last_name = bundle.data['lastname']
        try:
            bundle.obj = User.objects.create_user(username, email, password)
            bundle.obj.first_name = first_name
            bundle.obj.last_name = last_name
            bundle.obj.save()

            user_profile = UserProfile()
            user_profile.user = bundle.obj
            if 'jobtitle' in bundle.data:
                user_profile.job_title = bundle.data['jobtitle']
            if 'organisation' in bundle.data:
                user_profile.organisation = bundle.data['organisation']
            if 'phoneno' in bundle.data:
                user_profile.phone_number = bundle.data['phoneno']
            user_profile.save()

            u = authenticate(username=username, password=password)
            if u is not None and u.is_active:
                login(bundle.request, u)
                # Add to tracker
                tracker = Tracker()
                tracker.user = u
                tracker.type = 'register'
                tracker.ip = bundle.request.META.get('REMOTE_ADDR', api.DEFAULT_IP_ADDRESS)
                tracker.agent = bundle.request.META.get('HTTP_USER_AGENT', 'unknown')
                tracker.save()
            key = ApiKey.objects.get(user=u)
            bundle.data['api_key'] = key.key
        except IntegrityError:
            raise BadRequest(_(u'Username "%s" already in use, please select another' % username))
        del bundle.data['passwordagain']
        del bundle.data['password']
        del bundle.data['firstname']
        del bundle.data['lastname']
        return bundle