Exemplo n.º 1
0
def mobile_register(request):
    if request.method == 'POST':
        user_form = BlocklogicUserBaseForm(request.POST)
        user_form.is_mobile = True
        user_form.set_request(request)
        # user_profile_form = UserProfileForm(request.POST)

        if user_form.is_valid(): # and user_profile_form.is_valid():
            email = user_form.cleaned_data['email']

            if User.exists(email):

                if User.type(email) == "google":
                    return JsonError('error', _("You are already registered on one of Blocklogic sites with Google account. Please use the Google login button below."))
                elif User.type(email) == "normal":
                    return JsonError('error', _("You are already registered on one of Blocklogic sites. Try using that username."))

                return JsonError('user-exists', )
            # common function with web
            try_register(user_form) #), user_profile_form)

            return JsonResponse({'status': "created"})
        else:
            return JsonError(message='register failed')

    return JsonResponse({'error': "should not happen"})
Exemplo n.º 2
0
def login(request, data):
    """ log the user in;
        if successful, redirect to the index page
        if not successful, redirect back to the login page

        this is not a view!.
    """
    next = ''

    username = data.get('email')
    password = data.get('password')

    if request.GET.get('next', '') != '':
        next = request.GET.get('next')

    if request.POST.get('next', '') != '':
        next = request.POST.get('next')

    if User.exists(username) and User.type(username) == "google":
        return 'registered-with-google', next

    user = django_authenticate(username=username, password=password)

    if user is not None:
        # log in
        django_login(request, user)
        # activate this user's language
        set_language(request)
        message = "logged-in"
    else:
        # error page: wrong name/password
        message = "login-failed"

    # lets try google
    if message == 'login-failed':
        try:
            user = BlocklogicUser.objects.get(username=username, type=GOOGLE)
            message = 'google-login'
        except BlocklogicUser.DoesNotExist:
            pass

    # if still failing, lets see if user is not activated
    if message == 'login-failed':
        try:
            user = BlocklogicUser.objects.get(username=username, is_active=False)
            message = 'user-inactive'
        except BlocklogicUser.DoesNotExist:
            pass

    return message, next
Exemplo n.º 3
0
def sign_up(request):
    if request.method == 'POST':
        user_form = BlocklogicUserForm(request.POST)
        user_form.set_request(request)

        if user_form.is_valid():
            email = user_form.cleaned_data['email']

            if User.exists(email):
                if User.type(email) == "google":
                    return sign_up_message(request, 'user-exists-google')
                elif User.type(email) == "normal":
                    return sign_up_message(request, 'user-exists-normal')
                else:
                    return sign_up_message(request, 'user-exists')

            # common function with mobile
            try_register(user_form)

            # registration succeeded, return to login page
            return sign_up_message(request, 'registration-successful')
        else:
            print user_form.errors.as_data()
    else:
        user_form = BlocklogicUserForm()

    next = None
    if request.GET.get('next') and request.GET.get('next') != reverse('logout'):
        next = request.GET.get('next')

    context = {
        'next': next,
        'user_form': user_form,
        'client_id': settings.GOOGLE_API['client_id'],
        'title': _("Sign up"),
        'site_title': g.SITE_TITLE,
        'GOOGLE_API': settings.GOOGLE_API
    }

    return render(request, 'web/sign_up.html', context)
Exemplo n.º 4
0
            u'last_name': u'Jaklic TEST',
            u'password1': u'rok123',
            u'password2': u'rok123',
            u'country': u'SI',
            u'sex': u'male'
        }

        query_string = urllib.urlencode(my_dict)
        query_dict = QueryDict(query_string)

        user_form = BlocklogicUserBaseForm(query_dict)

        if user_form.is_valid():
            email = user_form.cleaned_data['email']

            if User.exists(email):
                print "User exists, something wrong, check it out..."
                raise Exception

            new_user = user_form.save()
            new_user.set_password(user_form.cleaned_data['password1'])

            key = ""
            while key == "":
                key = get_random_string(15, string.lowercase + string.digits)
                user = BlocklogicUser.objects.filter(password_reset_key=key)

                if user:
                    key = ""

            new_user.password_reset_key = key