Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Logging in Users / Sessions / Cookies - Allways logs me out


Go to End


907 Views

Avatar
FlorianGER

Community Member, 1 Post

22 November 2013 at 2:14am

Edited: 22/11/2013 2:22am

Hey Guys!

I got a Problem with an own LogIn Module.

Explanation:

I have a Controller "MemberHandler_Controller".

Routing:

Director:
  rules:
    'base': 'MemberHandler_Controller'

Then i have a AJAX-Form which will LogIn a Member.

    // Login Form
    $("#loginForm").submit(function(event) {
        var email = $("#inputEmail").val();
        var pw = $("#inputPassword").val();
        var remember = $("#rememberLoginInput:checked").length ? "True" : "False";
        $.ajax({
            url: PreUrl+"base/login",
            data: {email: email, pw: pw, remember: remember},
            dataType: "json",
            type: "POST"
        }).done(function(result) {
            if (result.success) {
                window.location = PreUrl;
            } else {
                $("#loginMessageArea").html(ErrorPreHTML + result.message + ErrorAfterHTML);
            }
        });
        event.preventDefault();
    });


To avoid some stupid Errors i have shrinked the Login Method to that:

public function Login(SS_HTTPRequest $request) {
$email = "test@test.com";
$user = OBUser::get()->find("Email", $email);
      $user->logIn($remember);

        echo json_encode(array("success" => true));
    }

Now i Press the Login Button at http://localhost/ProjectName/

It will send an Request to: http://localhost/ProjectName/index.php/base/logout

Now i get redirected by JavaScript to: http://localhost/ProjectName/index.php

I can browse the Page now, on every underpage i am logged in like on:
http://localhost/ProjectName/index.php/about-us/
or
http://localhost/ProjectName/index.php/contact-us/

BUT if i go to a site without the "index.php" like http://localhost/ProjectName/ i am Logged Out...
if i go back to http://localhost/ProjectName/index.php i am still logged in.

What is the Problem?

Very much Thanks in Advance