× Requests and support related to jBackend.

SSL and login

More
7 years 11 months ago - 7 years 11 months ago #5795 by brody182
Replied by brody182 on topic SSL and login
having some issues when logging in.. getting an alert box with [object Object] but not logging into joomla

json output:

{
"status": "ko",
"error_code": "USR_LIF",
"error_description": "Login failed"
}

form looks like this:
<form>
  <label for="text-basic" class="ui-hidden-accessible">User Name:</label>
                    <input type="text" name="username" placeholder="User Name" id="login-username" value="">
                    <label for="password" class="ui-hidden-accessible">Password:</label>
                    <input type="password" name="password" id="login-password" placeholder="Password" value="" autocomplete="off">
                    <div class="ui-field-contain">
                    <button type="submit" id="submit-6" class="ui-shadow ui-btn ui-corner-all ui-mini">Login</button>
                    </div>
</form>


<script>
        $("#submit-6").click(function(e) {
             e.preventDefault();

            var credentials = {
              username: $('#login-username').val(),
              password: $('#login-password').val()

            };
            jQuery.support.cors = true;

            $.ajax({
                type: "POST",
                url: "http://mywebsite.com/request-end-point/post/user/login",
               data: JSON.stringify(credentials),
               crossDomain: true,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data) {
                    // alert(data);

                    if (data.success === true) {
                      $.mobile.changePage($('#home'));
                       } else {
                         alert(data);
                       }

                },
                error: function(errMsg) {
                    alert(errMsg);
                }
            });


        });
</script>
Last edit: 7 years 11 months ago by brody182.

Please Log in or Create an account to join the conversation.

More
7 years 11 months ago #5796 by brody182
Replied by brody182 on topic SSL and login
more info, the json output i get form <end-point>/post/user/login?username=<username>&password=<password>

{
"status": "ok",
"userid": "44",
"username": "usrname",
"session_id": "f1515b2260a796b17e694e4aa023b9f6"
}

Please Log in or Create an account to join the conversation.

More
7 years 11 months ago #5797 by admin
Replied by admin on topic SSL and login
If you are posting a JSON payload, you need to enable it in the jBackend User plugin first.

Please Log in or Create an account to join the conversation.

More
7 years 11 months ago #5798 by brody182
Replied by brody182 on topic SSL and login
I enabled json login in the user plugin, still getting the alert box with [object Object]

I want to go to "#home" page after success login

do I need to store the session id in jQuery mobile?

I attached a screen shot with the login sessions.
Attachments:

Please Log in or Create an account to join the conversation.

More
7 years 11 months ago #5799 by admin
Replied by admin on topic SSL and login
In angular you need to set withCredentials to pass the cookie in the request (Joomla uses cookies for sessions). Probably this will fix for jQuery too:

api.jquery.com/jquery.ajax/

xhrFields
Type: PlainObject
An object of fieldName-fieldValue pairs to set on the native XHR object. For example, you can use it to set withCredentials to true for cross-domain requests if needed.

$.ajax({
url: a_cross_domain_url,
xhrFields: {
withCredentials: true
}
});

The following user(s) said Thank You: brody182

Please Log in or Create an account to join the conversation.

More
7 years 11 months ago #5803 by brody182
Replied by brody182 on topic SSL and login
one more question

how do I check if the client is logged in? ( {status: "ko", error_code: "USR_ALI", error_description: "Already logged in"} )

if client is logged in I wan to go to home page.

this needs to happen outside of $.ajax
Cookies.set('session_id', '18293840187');

 $.ajax({
url: a_cross_domain_url,
xhrFields: {
withCredentials: true
}

});


if ( Cookies.get('session_id' )  ) { //if cookie isset
         
            $.mobile.changePage($('#home'));
         }else{

              $.mobile.changePage($('#page-login'));
         }

Please Log in or Create an account to join the conversation.

Time to create page: 0.155 seconds