Ejemplo n.º 1
0
def registration(request):
    RegistrationForm = get_form_class(up_settings.REGISTRATION_FORM)

    if request.method == 'POST':
        form = RegistrationForm(data=request.POST, files=request.FILES)

        if form.is_valid():
            new_user = form.save()
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']

            # Automatically log this user in
            if up_settings.AUTO_LOGIN:

                if up_settings.EMAIL_ONLY:
                    username = form.cleaned_data['email']

                user = authenticate(username=username, password=password)
                if user is not None:
                    if user.is_active:
                        login(request, user)

            return redirect(up_settings.REGISTRATION_REDIRECT)

    else:
        form = RegistrationForm()

    return render(request, 'userprofiles/registration.html', {
        'form': form
    })
Ejemplo n.º 2
0
    def test_get_form_class(self):
        self.assertEqual(utils.get_form_class('userprofiles.forms.RegistrationForm'),
            forms.RegistrationForm)

        self.assertRaises(ImproperlyConfigured,
            utils.get_form_class, 'userprofiles.invalid_forms.RegistrationForm')

        self.assertRaises(ImproperlyConfigured,
            utils.get_form_class, 'userprofiles.forms.InvalidRegistrationForm')
Ejemplo n.º 3
0
    def test_get_form_class(self):
        self.assertEqual(
            utils.get_form_class('userprofiles.forms.RegistrationForm'),
            forms.RegistrationForm)

        self.assertRaises(ImproperlyConfigured, utils.get_form_class,
                          'userprofiles.invalid_forms.RegistrationForm')

        self.assertRaises(ImproperlyConfigured, utils.get_form_class,
                          'userprofiles.forms.InvalidRegistrationForm')
Ejemplo n.º 4
0
class RegistrationView(FormView):
    form_class = get_form_class('userprofiles.forms.RegistrationForm')
    template_name = 'userprofiles/registration.html'

    def form_valid(self, form):
        form.save()
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        # return redirect(up_settings.REGISTRATION_REDIRECT)
        url = reverse('users:userprofiles_registration_complete')
        return HttpResponseRedirect(url)
Ejemplo n.º 5
0
def registration(request):
    RegistrationForm = get_form_class(up_settings.REGISTRATION_FORM)

    if request.method == 'POST':
        form = RegistrationForm(data=request.POST, files=request.FILES)
        if form.is_valid():
            new_user = form.save()
            return redirect('userprofiles_registration_complete')
    else:
        form = RegistrationForm()

    return render(request, 'userprofiles/registration.html', {
        'form': form
    })
Ejemplo n.º 6
0
def registration(request):
    RegistrationForm = get_form_class(up_settings.REGISTRATION_FORM)

    if request.method == 'POST':
        form = RegistrationForm(data=request.POST, files=request.FILES)

        if form.is_valid():
            new_user = form.save()

            username = form.cleaned_data['username']
            password = form.cleaned_data['password']

            request.session['login'] = "******"

            # Automatically log this user in
            if up_settings.AUTO_LOGIN:

                if up_settings.EMAIL_ONLY:
                    username = form.cleaned_data['email']

                user = authenticate(username=username, password=password)
                if user is not None:
                    if user.is_active:
                        login(request, user)
                        calculate_profile_completion(request)

            return redirect(up_settings.REGISTRATION_REDIRECT)

    else:
        form = RegistrationForm(auto_id=False)

    import random
    x = random.randint(1, 7)
    try:
        next = request.GET['next']
    except:
        next = ''

    if not request.user.is_authenticated():
        #return render(request, 'userprofiles/registration.html', {'form': form, 'pic_num': x, 'next': next})
        return render(request, 'userprofiles/registration2.html', {
            'form': form,
            'pic_num': x,
            'next': next
        })
    else:
        from shoghlanah.views import master
        return master(request=request)
Ejemplo n.º 7
0
def registration(request):
    RegistrationForm = get_form_class(up_settings.REGISTRATION_FORM)

    if request.method == 'POST':
        form = RegistrationForm(data=request.POST, files=request.FILES)

        if form.is_valid():
            new_user = form.save()

            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            
            request.session['login'] = "******"

            # Automatically log this user in
            if up_settings.AUTO_LOGIN:

                if up_settings.EMAIL_ONLY:
                    username = form.cleaned_data['email']

                user = authenticate(username=username, password=password)
                if user is not None:
                    if user.is_active:
                        login(request, user)
                        calculate_profile_completion(request)

            return redirect(up_settings.REGISTRATION_REDIRECT)

    else:
        form = RegistrationForm(auto_id=False)

    import random
    x = random.randint(1, 7)
    try:
        next = request.GET['next']
    except:
        next = ''

    if not request.user.is_authenticated():
        #return render(request, 'userprofiles/registration.html', {'form': form, 'pic_num': x, 'next': next})
        return render(request, 'userprofiles/registration2.html', {'form': form, 'pic_num': x, 'next': next})
    else:
        from shoghlanah.views import master
        return master(request=request)
Ejemplo n.º 8
0
class RegistrationView(FormView):
    form_class = get_form_class(up_settings.REGISTRATION_FORM)
    template_name = 'userprofiles/registration.html'

    def form_valid(self, form):
        form.save()
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']

        # Automatically log this user in
        if up_settings.AUTO_LOGIN:
            if up_settings.EMAIL_ONLY:
                username = form.cleaned_data['email']

            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(self.request, user)

        return redirect(up_settings.REGISTRATION_REDIRECT)
Ejemplo n.º 9
0
def profile_change(request):
    ProfileForm = get_form_class(up_settings.PROFILE_FORM)

    if request.method == 'POST':
        form = ProfileForm(request.POST, request.FILES,
            instance=request.user.get_profile())
        if form.is_valid():
            profile = form.save()
            messages.success(request, _(u'Profile changed'))
            return redirect(up_settings.PROFILE_CHANGE_DONE_URL)
    else:
        if up_settings.REGISTRATION_FULLNAME:
            form = ProfileForm(instance=request.user.get_profile(), initial={
                'first_name': request.user.first_name,
                'last_name': request.user.last_name,
                'email': request.user.email
            })
        else:
            form = ProfileForm(instance=request.user.get_profile())

    return render(request, 'userprofiles/profile_change.html', {'form': form})
Ejemplo n.º 10
0
def profile_change(request):
    ProfileForm = get_form_class(up_settings.PROFILE_FORM)

    if request.method == 'POST':
        form = ProfileForm(request.POST, request.FILES,
            instance=request.user.get_profile())
        if form.is_valid():
            profile = form.save()
            messages.success(request, _(u'Profile changed'))
            return redirect(up_settings.PROFILE_CHANGE_DONE_URL)
    else:
        if up_settings.REGISTRATION_FULLNAME:
            form = ProfileForm(instance=request.user.get_profile(), initial={
                'first_name': request.user.first_name,
                'last_name': request.user.last_name,
                'email': request.user.email
            })
        else:
            form = ProfileForm(instance=request.user.get_profile())

    return render(request, 'userprofiles/profile_change.html', {'form': form})
Ejemplo n.º 11
0
class ProfileChangeView(LoginRequiredMixin, FormView):
    form_class = get_form_class(up_settings.PROFILE_FORM)
    template_name = 'userprofiles/profile_change.html'

    def get_form_kwargs(self):
        kwargs = super(ProfileChangeView, self).get_form_kwargs()
        kwargs['instance'] = get_profile_model().objects.get(
            user=self.request.user)

        if up_settings.REGISTRATION_FULLNAME:
            kwargs['initial'].update({
                'first_name': self.request.user.first_name,
                'last_name': self.request.user.last_name,
                'email': self.request.user.email
            })
        return kwargs

    def form_valid(self, form):
        form.save()
        messages.success(self.request, _(u'Profile changed'))
        return redirect(up_settings.PROFILE_CHANGE_DONE_URL)
Ejemplo n.º 12
0
def log_in(request):
    """
    This method checks for the input username(email) and password.
    If they are empty the user id redirected to the login page, else checks whether
    the user is authenticated. If the user is not found in the database, it renders the login
    page with an error_message that the email or password are invalid. Further, it checks if the user's
    account is activated, it not he is redirected back to login and notified.
    If the user is activated, it checks for the field remember_me, if it is not checked, then the
    expiry date of the session is set to when the browser is closed.
    Then the user is logged in using the login in django backends and it checks on the session
    value if it is his first time or not to open the getstrated instead of the normal profile.
    """
    base_login = True
    print "trying to login"
    if 'username' in request.POST and 'password' in request.POST:
        print "found user and pass in post"
        username = request.POST['username'].lower()
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is None:
            error_message = translation.gettext("The Email/Password is incorrect.")
            print error_message
            #return render(request, 'userprofiles/registration.html', {'error_message': error_message})
            return render(request, 'userprofiles/registration2.html', {'error_message': error_message})
        else:
            if user.is_active:
                if not request.POST.get('remember_me', False):
                    request.session.set_expiry(0)

                login(request, user)

                request.session['DEPLOYED_ADDRESS'] = settings.DEPLOYED_ADDRESS

                logged_user = UserProfile.objects.filter(username=request.user.username)
                if len(logged_user) > 0:
                    logged_user = logged_user[0]
                else:
                    print "no account found!!"
                    error_message = translation.gettext("You do not yet have an Account on Shoghlanah, please Request Invitation below.")
                    return render(request, 'userprofiles/registration2.html', {'error_message': error_message})
                    #return render(request, 'userprofiles/registration.html', {'error_message': error_message})
                if (request.POST['next']):  # Request contains next url
                    return redirect(request.POST['next'], RequestContext(request))

                return redirect('/', RequestContext(request))

            else:
                print "not yet activated"
                error_message = translation.gettext("This Email Hasn't Been Activated Yet. Please Check The Activation Mail Sent To You.")
                #error_message = translation.gettext("This Email Hasn't Been Activated Yet.")
                return render(request, 'userprofiles/registration2.html', {'error_message': error_message})
                #return render(request, 'userprofiles/registration.html', {'error_message': error_message})

    else:
        RegistrationForm = get_form_class(up_settings.REGISTRATION_FORM)

        if request.method == 'POST':
            form = RegistrationForm(data=request.POST, files=request.FILES)

            if form.is_valid():
                new_user = form.save()
                username = form.cleaned_data['username']
                password = form.cleaned_data['password']

                request.session['login'] = "******"

                # Automatically log this user in
                if up_settings.AUTO_LOGIN:

                    if up_settings.EMAIL_ONLY:
                        username = form.cleaned_data['email']

                    user = authenticate(username=username, password=password)
                    if user is not None:
                        if user.is_active:
                            login(request, user)
                            # calculate_profile_completion(request)

                return redirect(up_settings.REGISTRATION_REDIRECT)

        else:
            form = RegistrationForm()
            try:
                next = request.GET['next']  # to save the next url if exists
            except:
         #       return render(request, 'userprofiles/registration.html', {'form': form, 'base_login': base_login})
                return render(request, 'userprofiles/registration2.html', {'form': form, 'base_login': base_login})

        return render(request, 'userprofiles/registration2.html', {'form': form, 'base_login': base_login, 'next': next})
Ejemplo n.º 13
0
def log_in(request):
    """
    This method checks for the input username(email) and password.
    If they are empty the user id redirected to the login page, else checks whether
    the user is authenticated. If the user is not found in the database, it renders the login
    page with an error_message that the email or password are invalid. Further, it checks if the user's
    account is activated, it not he is redirected back to login and notified.
    If the user is activated, it checks for the field remember_me, if it is not checked, then the
    expiry date of the session is set to when the browser is closed.
    Then the user is logged in using the login in django backends and it checks on the session
    value if it is his first time or not to open the getstrated instead of the normal profile.
    """
    base_login = True
    print "trying to login"
    if 'username' in request.POST and 'password' in request.POST:
        print "found user and pass in post"
        username = request.POST['username'].lower()
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is None:
            error_message = translation.gettext(
                "The Email/Password is incorrect.")
            print error_message
            #return render(request, 'userprofiles/registration.html', {'error_message': error_message})
            return render(request, 'userprofiles/registration2.html',
                          {'error_message': error_message})
        else:
            if user.is_active:
                if not request.POST.get('remember_me', False):
                    request.session.set_expiry(0)

                login(request, user)

                request.session['DEPLOYED_ADDRESS'] = settings.DEPLOYED_ADDRESS

                logged_user = UserProfile.objects.filter(
                    username=request.user.username)
                if len(logged_user) > 0:
                    logged_user = logged_user[0]
                else:
                    print "no account found!!"
                    error_message = translation.gettext(
                        "You do not yet have an Account on Shoghlanah, please Request Invitation below."
                    )
                    return render(request, 'userprofiles/registration2.html',
                                  {'error_message': error_message})
                    #return render(request, 'userprofiles/registration.html', {'error_message': error_message})
                if (request.POST['next']):  # Request contains next url
                    return redirect(request.POST['next'],
                                    RequestContext(request))

                return redirect('/', RequestContext(request))

            else:
                print "not yet activated"
                error_message = translation.gettext(
                    "This Email Hasn't Been Activated Yet. Please Check The Activation Mail Sent To You."
                )
                #error_message = translation.gettext("This Email Hasn't Been Activated Yet.")
                return render(request, 'userprofiles/registration2.html',
                              {'error_message': error_message})
                #return render(request, 'userprofiles/registration.html', {'error_message': error_message})

    else:
        RegistrationForm = get_form_class(up_settings.REGISTRATION_FORM)

        if request.method == 'POST':
            form = RegistrationForm(data=request.POST, files=request.FILES)

            if form.is_valid():
                new_user = form.save()
                username = form.cleaned_data['username']
                password = form.cleaned_data['password']

                request.session['login'] = "******"

                # Automatically log this user in
                if up_settings.AUTO_LOGIN:

                    if up_settings.EMAIL_ONLY:
                        username = form.cleaned_data['email']

                    user = authenticate(username=username, password=password)
                    if user is not None:
                        if user.is_active:
                            login(request, user)
                            # calculate_profile_completion(request)

                return redirect(up_settings.REGISTRATION_REDIRECT)

        else:
            form = RegistrationForm()
            try:
                next = request.GET['next']  # to save the next url if exists
            except:
                #       return render(request, 'userprofiles/registration.html', {'form': form, 'base_login': base_login})
                return render(request, 'userprofiles/registration2.html', {
                    'form': form,
                    'base_login': base_login
                })

        return render(request, 'userprofiles/registration2.html', {
            'form': form,
            'base_login': base_login,
            'next': next
        })