Authentication in jQuery Mobile and PhoneGap

I have a web application built using jQuery Mobile and PHP (Framework CodeIgniter). Now I am also trying to make a version of PhoneGap to make it available as a standalone application. However, the PHP web application. version uses Ion Auth, the CodeIgniter plugin for authentication. Therefore, when you go to a page that requires authentication, the application redirects you to the login method of the authentication controller. And after authentication, it redirects you back to the home page (in this case, on the jQuery Mobile page). This works great in a web application. Since the home page is in any case opened by the home controller.

But here's the bottom line: in the PhoneGap version, the home page should be the index.html file in PhoneGap. Obviously, you can load a different URL at startup by adding a value to PhoneGap.plist, but this is not acceptable for Apple to send to the app store. And if I do a redirect in authentication, I cannot return to the index.html file after authentication ...

So, how do you bypass authentication in the PhoneGap / jQuery mobile app?

UPDATE:

I tried this according to one of the answers, but the application is still trying to go to the account / login page (which does not exist) when I just want to login through the message and return the value from the method:

    $('#login_form').bind('submit', function () {
        event.preventDefault();
        //send a post request to your web-service
        $.post('http://localhost/app_xcode/account/login', $(this).serialize(), function (response) {
            //parse the response string into an object
            var response = response;
            //check if the authorization was successful or not
            if (response == true) {
                $.mobile.changePage('#toc', "slide");
            } else {
                alert('login failed');
                $.mobile.changePage('#toc', "slide");
            }
        });
    });

Here's the controller method:

function login()
    {
        //validate form input
        $this->form_validation->set_rules('identity', 'Identity', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');

        $base_url = $this->config->item('base_url');

        $mobile = $this->detect_mobile();
        if ($mobile === false && $base_url != 'http://localhost/app_xcode/') //Only restrict if not developing
            redirect('account/notAMobile');

        else if ($this->form_validation->run() == true) { //check to see if the user is logging in
            //check for "remember me"
            $remember = (bool)$this->input->post('remember');

            if ($this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $remember)) { //if the login is successful
                //redirect them back to the home page
                $this->session->set_flashdata('message', $this->ion_auth->messages());

                echo true;
                /*redirect($this->config->item('base_url'), 'refresh');*/
            }
            else
            { //if the login was un-successful
                //redirect them back to the login page
                $this->session->set_flashdata('message', $this->ion_auth->errors());
                /*redirect('account/login', 'refresh');*/ //use redirects instead of loading views for compatibility with MY_Controller libraries
            }
        }
        else
        { //the user is not logging in so display the login page
            //set the flash data error message if there is one
            $this->data['message'] = (validation_errors()) ? validation_errors()
                    : $this->session->flashdata('message');

            $this->data['identity'] = array('name' => 'identity',
                                            'id' => 'identity',
                                            'type' => 'text',
                                            'value' => $this->form_validation->set_value('identity'),
            );
            $this->data['password'] = array('name' => 'password',
                                            'id' => 'password',
                                            'type' => 'password',
            );

        }
    }

, , . , ? , jQuery Mobile , URL?

+5
3

- (Ion Auth) . jQuery. :

//add event handler to the `submit` event for your login form
$('#login_form').bind('submit', function () {

    //send a post request to your web-service
    $.post('http://my-domain.com/my-auth/auth.php', $(this).serialize(), function (response) {

        //parse the response string into an object
        response = $.parseJSON(response);

        //check if the authorization was successful or not
        if (response.status === 'success') {
            //do login here
        } else {
            //do error here
        }
    });
});

$(this).serialize() . , - JSON.

+4

, , , , Javascript. event , event.preventDefault(). , - , action method.

function(event) {, false . false .

$('#login_form').bind('submit', function () {

    //send a post request to your web-service
    $.post('http://localhost/app_xcode/account/login', $(this).serialize(), function (response) {
        //check if the authorization was successful or not
        if (response == true) {
            $.mobile.changePage('#toc', "slide");
        } else {
            alert('login failed');
            $.mobile.changePage('#toc', "slide");
        }
    }, 'JSON');

    return false;
});
+5

PhoneGap: ChildBrowser (iPhone, Android, ) locChanged?

I only have coded applications that use OAuth ( Twitter App ) and OpenID ( AppLaud App ) for PhoneGap / Android, but there is what they need for the child browser plugin. It seems that Ion Auth might be similar: after logging in with auth, return the user to the application without problems.

+2
source

All Articles