0

I am trying to implement a Codeigniter based app on Android via phonegap, all works well apart from logging in/out with tank auth.

When the login form is submitted it keeps showing a dialog saying 'Complete action using' with an option to select a browser, rather than staying in the app window.

If you select a browser it opens a browser window with the login page again, but if the app is re-started it is logged in.

How can I stop this jump to the browser so the app is seamless? I think it is when tank auth is writing/destroying the cookie info. This is running in an /android subfolder off the root as the client host does not support subdomains.

This is the tank auth login code. Note that 'home' is the default controller.

EDIT: I actually don't need to accept the 'Complete action using' dialog - if I just click back and restart the app it is logged in! Wish I knew what was making that dialog pop up, I'm actually pretty impressed that phonegap has managed to wrap around a full CI site with authentication at all...

function login()
    {
        if ($this->tank_auth->is_logged_in()) {                                 // logged in
            redirect('home');
        } elseif ($this->tank_auth->is_logged_in(FALSE)) {                      // logged in, not activated
            redirect('/auth/send_again/');
        } else {
            $data['login_by_username'] = ($this->config->item('login_by_username', 'tank_auth') AND
                    $this->config->item('use_username', 'tank_auth'));
            $data['login_by_email'] = $this->config->item('login_by_email', 'tank_auth');

            $this->form_validation->set_rules('login', 'Login', 'trim|required|xss_clean');
            $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
            $this->form_validation->set_rules('remember', 'Remember me', 'integer');

            // Get login for counting attempts to login
            if ($this->config->item('login_count_attempts', 'tank_auth') AND
                    ($login = $this->input->post('login'))) {
                $login = $this->security->xss_clean($login);
            } else {
                $login = '';
            }

            $data['use_recaptcha'] = $this->config->item('use_recaptcha', 'tank_auth');
            if ($this->tank_auth->is_max_login_attempts_exceeded($login)) {
                if ($data['use_recaptcha'])
                    $this->form_validation->set_rules('recaptcha_response_field', 'Confirmation Code', 'trim|xss_clean|required|callback__check_recaptcha');
                else
                    $this->form_validation->set_rules('captcha', 'Confirmation Code', 'trim|xss_clean|required|callback__check_captcha');
            }
            $data['errors'] = array();

            if ($this->form_validation->run()) {                                // validation ok
                if ($this->tank_auth->login(
                        $this->form_validation->set_value('login'),
                        $this->form_validation->set_value('password'),
                        $this->form_validation->set_value('remember'),
                        $data['login_by_username'],
                        $data['login_by_email'])) { // success

                        $this->load->library('user_agent');
                        redirect('home'); // Adds this onto /android/

                } else {
                    $errors = $this->tank_auth->get_error_message();
                    if (isset($errors['banned'])) {                             // banned user
                        $this->_show_message($this->lang->line('auth_message_banned').' '.$errors['banned']);

                    } elseif (isset($errors['not_activated'])) {                // not activated user
                        redirect('/auth/send_again/');

                    } else {                                                    // fail
                        foreach ($errors as $k => $v)   $data['errors'][$k] = $this->lang->line($v);
                    }
            }
        }
        $data['show_captcha'] = FALSE;
        if ($this->tank_auth->is_max_login_attempts_exceeded($login)) {
            $data['show_captcha'] = TRUE;
            if ($data['use_recaptcha']) {
                $data['recaptcha_html'] = $this->_create_recaptcha();
            } else {
                $data['captcha_html'] = $this->_create_captcha();
            }
        }
        $this->load->view('view_header');
        $this->load->view('auth/login_form', $data);
    }
}
rev_dev_01
  • 500
  • 3
  • 20

2 Answers2

1

Sorted it myself - I added the following to the Java Activity file in the /src folder, just before the super.loadUrl line:

super.setBooleanProperty("loadInWebView", true);

This makes all links open in the WebView, i.e. inside the app. Fine for something simple like this.

Spent 5 hours trawling round, but got there in the end... :/

hammar
  • 138,522
  • 17
  • 304
  • 385
rev_dev_01
  • 500
  • 3
  • 20
0

You may want to look at this tutorial:

http://www.mobiledevelopersolutions.com/home/start/twominutetutorials/tmt5p1

It uses the ChildBrowser in PhoneGap to do oauth login. You may be able to adapt it to do you tank auth login.

Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
  • Thanks - I am looking at ChildBrowser but was wondering if there was a way to process authentication without a popup window... – rev_dev_01 Nov 23 '11 at 15:57