0

My plan is to use EE as an admin portal for users so they can update my CI application. The way I need it to work is, EE template Login -> give them access by using an external source API for the login Validation. Once they have access they will hit a search Template-> on typing a search query they will get results from an external database not exp_database (I'll be using a custom search module here.)

Like CodeIgniter I would like to connect my login template in EE to a custom controller in EE. Would I need to make a custom module for this functionality?

I did look up something on https://stackoverflow.com/questions/6588954/expression-engine-controllers and followed their ideas but it doesn't seem to work. I get errors like

"The following errors were encountered This form has expired. Please refresh and try again. Return to Previous Page"

Below is the index login page, I created: url is localhost/login/index.php

<title>Login Screen </title>
<link>bootstarp file</link>
</head>
<body>
  <div class="container">
    <div class="row">
                <div class="col-md-2">
                        <form class="form-horizontal" action='controllers/LoginController.php' method="POST">
                          <fieldset>
                            <div id="legend">
                              <legend class="">Login</legend>
                            </div>
                            <div class="form-group">
                              <!-- Username -->
                              <label c for="username">Username</label>
                              <div class="controls">
                                <input type="text" id="username" name="username" placeholder="" class="form-control input-xlarge ">
                              </div>
                            </div>
                            <div class="form-group">
                              <!-- Password-->
                              <label for="password">Password</label>
                              <div class="controls">
                                <input type="password" id="password" name="password" placeholder="" class="form-control input-xlarge">
                              </div>
                            </div>
                            <div class="form-group">
                              <!-- Button -->
                              <div class="controls">
                                <input name="submit" class="btn btn-success" type="submit" value=" Login ">

                              </div>
                            </div>
                          </fieldset>
                        </form>
                </div>
        </div>
</div>

</body>

</html>

here is the controller url (which is a template is the same login.group): login/CheckLogin -CheckLogin has Allow PHP enabled -php Parsing Stage - input and Output (tried both still gives me the same error)

<?php
    class CheckLogin extends CI_Controller {

            public function index() {
login_name     = $_POST['username'];
login_password = $_POST['password'];
            //Login Validation
        }
    }
?>

I have also disabled/commented out the routes in config.php as well

$route['default_controller'] = "ee/index";
$route['404_override'] = "ee/index";

It still doesn't work ... I'm hoping it will be something very very stupid (most of the time it is). Any kind of suggestion or example code structure would help.

  • It looks like you need some custom add-on (module, or extension) instead. If you can tell the community what goals you try to achieve, then you might get more help. – Yuri Salimovskiy Dec 11 '15 at 7:49
  • Thanks for your response, you and yuri are right I think I owe youll that much. My plan is to use EE as an admin portal for users so they can update my CI application. The way I need it to work is, EE template Login -> give them access by using an external source API for the login Validation. Once they have access they will hit a search Template-> on typing a search query they will get results from an external database not exp_database (I'll be using a custom search module here.) – luziio Dec 11 '15 at 16:06
1

CodeIgniter controllers and ExpressionEngine template groups are analogous in function but not in implementation. In this case, your template CheckLogin is being called without having to write a controller in between (EE does that for you).

In this case, you wouldn't need to write a class structure at all.

Here is an example of how you'd grab those data points from a POST submission to your CheckLogin template:

<?php

$login_name = ee()->input->post("username");
$login_pass = ee()->input->post("password");

?>

In your login/index file, do note that you need to add a {csrf_token} to your form, otherwise EE's core security class will bounce the POST request with the exact error you're getting; the form is stale because either it has no token or an old token.

https://docs.expressionengine.com/latest/development/guidelines/security.html#csrf-tokens-in-templates

Now at this point, it begs a serious question: Why aren't you using ExpressionEngine's native member utilities for users/sessions/login/logout... do you need to integrate with a separate service?

As Yuri said, if you expand on what you're trying to accomplish, our community can help you much better.

| improve this answer | |
  • Thanks for your response, you and yuri are right I think I owe youll that much. My plan is to use EE as an admin portal for users so they can update my CI application. The way I need it to work is, EE template Login -> give them access by using an external source API for the login Validation. Once they have access they will hit a search Template-> on typing a search query they will get results from an external database not exp_database (I'll be using a custom search module here.) – luziio Dec 11 '15 at 16:04
0

It look to me that you are trying to perform some actions (call to your API) when user logs in to EE.

You should not re-write EE controllers if you want to perform custom actions. While in theory you can do it, you'll spend a lot more time with much less profit then if you go EE way, which is writing an extension.

If I understand you correctly, you need an extension based on one of these hooks: https://docs.expressionengine.com/v2/development/extension_hooks/module/member_auth/index.html

| improve this answer | |
  • Yes but while the user log-in (authentication of the user ) will be determine by the API call. I have no intention of using EE member (database) or EE's member authentication. eg. User comes to the site. enters username and password. username and password is authenticated by api call. sends Authenticated user to EE- member area template. – luziio Dec 11 '15 at 20:53
  • @luziio I really can't tell why you're using EE at all. Everything you've described wanting to do in a specific manner is simply better done in CI. I'm not sure you're picking the right tool for the job. – jrothafer Dec 11 '15 at 22:28
  • If you want to do what you're asking, you'll still need to create your user sessions with EEs Sessions class. – jrothafer Dec 11 '15 at 22:33
  • I understand, CI was my plan at first but the client has already paid for the premium EE package. They want me to use in the mix. Is there a way you see I could use EE with what I have planned? – luziio Dec 11 '15 at 22:57
  • In order for me create user session would i have to use login functionality of EE or can I just call them when i need them ? i.e in my custom login – luziio Dec 11 '15 at 23:03
0

I have changed the a few things this is what I have so far

my login template

<!DOCTYPE html>
<html>
<head>
<title>Login Screen </title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

</head>
<body>
  <div class="container">
    <div class="row">
                <div class="col-md-2">
                        <form class="form-horizontal" action='controllers/Login' method="POST">
                            <input type="hidden" name="csrf_token" value="{csrf_token}">
                          <fieldset>
                            <div id="legend">
                              <legend class="">Login</legend>
                            </div>
                            <div class="form-group">
                              <!-- Username -->
                              <label c for="username">Username</label>
                              <div class="controls">
                                <input type="text" id="username" name="username" placeholder="" class="form-control input-xlarge ">
                              </div>
                            </div>
                            <div class="form-group">
                              <!-- Password-->
                              <label for="password">Password</label>
                              <div class="controls">
                                <input type="password" id="password" name="password" placeholder="" class="form-control input-xlarge">
                              </div>
                            </div>
                            <div class="form-group">
                              <!-- Button -->
                              <div class="controls">
                                <input name="submit" class="btn btn-success" type="submit" value=" Login ">

                              </div>
                            </div>
                          </fieldset>
                        </form>
                </div>
        </div>
</div>

</body>

</html>

My admin controller -- is a default controller as well

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include('ee.php');

class AdminController extends EE_Controller {

    function __construct()
    {
         // parent::Controller();
         // parent::CI_Controller();
         parent::__construct();

         // Initialize ExpressionEngine objects
            $this->EE = $this->core->EE;
            // get EE's template library
            $this->EE->TMPL = $this->EE->load->library('template');
    }

    function index()
    {
        // echo 'hi there';

        $this->EE->TMPL = new EE_Template();

        //pick our template
        $this->EE->TMPL->run_template_engine('login', 'index');
    }


}

a login controller which extends admin controller - basically this will get the input from the ee-> login template and send them to this controller where I can send it to the API.

class Login extends AdminController {

    function Login(){
        $loginVar = new LoginFunctions; 
        $loginInfo = $loginfun-> ConvioAPICall($loginVar->name = ee()->input->post("username");, $loginVar-> password = ee()->input->post("password"), 'SRConsAPI_login');
        $groupInfo = $loginfun-> ConvioAPICall($loginVar->name = ee()->input->post("username"), $loginVar-> password = ee()->input->post("password"), 'SRConsAPI_getUserGroups');

        print_r($loginInfo);

        if ($loginfun-> validateUser( $loginInfo, $groupInfo))
        {

            echo 'good';
        }else{
            echo 'bad';

        }

    //  $loginfun-> decodestring($loginfun-> jsonString = $userInfo);
    }
}

However I still unable to send the username and password to login controller. Error message

The requested URL /login/controllers/Login was not found on this server.

I'm I doing this right? Or should I create a module which will collect the login info and send an API call function?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.