- Added new public method getLandingPage to AuthLib.php

- AuthLib->redirectToLandingPage now calls getLandingPage
- Added new controller system/Login.php to perform login operations
- Added new view system/login/usernamePassword.php to login with username and password
- Added css/Login.css, images/logo-300x160.png and js/Login.js to be used by usernamePassword.php
This commit is contained in:
Paolo
2019-03-21 17:00:08 +01:00
parent 400a1adfde
commit f92e32d8f0
6 changed files with 236 additions and 1 deletions
+102
View File
@@ -0,0 +1,102 @@
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* NOTE: extends the FHC_Controller instead of the Auth_Controller because we want to login ;) otherwise loooooop!
*/
class Login extends FHC_Controller
{
/**
*
*/
public function __construct()
{
parent::__construct();
}
/**
* Displays a login page with username and password
*/
public function usernamePassword()
{
$this->load->view('system/login/usernamePassword');
}
/**
* Called with HTTP POST via ajax to login using the LDAP authentication
*/
public function loginLDAP()
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$this->load->library('AuthLib', array(false)); // without authentication otherwise loooooop!
$login = $this->authlib->loginLDAP($username, $password);
if (isSuccess($login))
{
$this->outputJsonSuccess($this->authlib->getLandingPage()); // if login is success then retrieves the desired page
}
else
{
$this->outputJsonError(getCode($login)); // returns the error code
}
}
/**
* Called with HTTP POST via ajax to login as another user specified by uid
*/
public function loginASByUid()
{
$uid = $this->input->get('uid');
// With authentication -> you must be already logged to gain another identity
$this->load->library('AuthLib');
$loginAS = $this->authlib->loginASByUID($uid);
if (isSuccess($loginAS))
{
$this->outputJsonSuccess(true); // obtained!
}
else
{
$this->outputJsonSuccess(getCode($loginAS)); // returns the error code
}
}
/**
* Called with HTTP POST via ajax to login as another user specified by person id
*/
public function loginASByPersonId()
{
$person_id = $this->input->get('person_id');
// With authentication -> you must be already logged to gain another identity
$this->load->library('AuthLib');
$loginAS = $this->authlib->loginASByPersonId($person_id);
if (isSuccess($loginAS))
{
$this->outputJsonSuccess(true); // obtained!
}
else
{
$this->outputJsonSuccess(getCode($loginAS)); // returns the error code
};
}
/**
* To login into the system with email and code as credentials
*/
public function emailCode()
{
}
/**
* To login into the system using SSO
*/
public function sso()
{
}
}
+9 -1
View File
@@ -181,6 +181,14 @@ class AuthLib
* Redirect to the previously stored landing page
*/
public function redirectToLandingPage($altLandingPage = null)
{
$this->_redirectTemporarily($this->getLandingPage($altLandingPage)); // redirect to landing page
}
/**
* Returns the landing page
*/
public function getLandingPage($altLandingPage = null)
{
// Tries to get the previously stored landing page
$landingPage = getSessionElement(self::SESSION_NAME, self::SESSION_LANDING_PAGE);
@@ -200,7 +208,7 @@ class AuthLib
// Clean the previously stored landing page
cleanSessionElement(self::SESSION_NAME, self::SESSION_LANDING_PAGE);
$this->_redirectTemporarily($landingPage); // redirect to landing page
return $landingPage;
}
/**
@@ -0,0 +1,45 @@
<?php
$this->load->view(
'templates/FHC-Header',
array(
'title' => 'Login',
'jquery' => true,
'jqueryui' => true,
'bootstrap' => true,
'fontawesome' => true,
'sbadmintemplate' => true,
'ajaxlib' => true,
'dialoglib' => true,
'customCSSs' => 'public/css/Login.css',
'customJSs' => 'public/js/Login.js'
)
);
?>
<body>
<div class="login-form">
<p class="text-center">
<img src="<?php echo base_url('public/images/logo-300x160.png'); ?>" >
</p>
<br>
<div class="form-group">
<input id="username" type="text" class="form-control" placeholder="Username" required="required">
</div>
<div class="form-group">
<input id="password" type="password" class="form-control" placeholder="Password" required="required">
</div>
<div class="form-group">
<button id="btnLogin" ype="submit" class="btn btn-primary btn-block">Log in</button>
</div>
<p class="text-center"><a href="#">Forgot Password?</a></p>
</div>
</body>
<?php $this->load->view('templates/FHC-Footer'); ?>
+25
View File
@@ -0,0 +1,25 @@
.login-form {
width: 340px;
margin: 50px auto;
}
.login-form form {
margin-bottom: 15px;
background: #f7f7f7;
box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
padding: 30px;
}
.login-form h2 {
margin: 0 0 15px;
}
.form-control, .btn {
min-height: 38px;
border-radius: 2px;
}
.btn {
font-size: 15px;
font-weight: bold;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

+55
View File
@@ -0,0 +1,55 @@
/**
* To login via LDAP
*/
function loginLDAP()
{
// Ajax call to login with LDAP
FHC_AjaxClient.ajaxCallPost(
"system/Login/loginLDAP",
{
username: $("#username").val(),
password: $("#password").val()
},
{
successCallback: function(data, textStatus, jqXHR) {
if (FHC_AjaxClient.isError(data))
{
if (FHC_AjaxClient.getError(data) == 10)
{
FHC_DialogLib.alertError("Username not foud");
}
if (FHC_AjaxClient.getError(data) == 2)
{
FHC_DialogLib.alertError("Wrong password");
}
}
else
{
$(location).attr("href", FHC_AjaxClient.getData(data));
}
},
errorCallback: function(jqXHR, textStatus, errorThrown) {
FHC_DialogLib.alertError(textStatus);
}
}
);
}
/**
* When JQuery is up
*/
$(document).ready(function() {
$("#btnLogin").click(loginLDAP);
$("#username").keydown(function(e) {
if (e.keyCode == 13) loginLDAP();
})
$("#password").keydown(function(e) {
if (e.keyCode == 13) loginLDAP();
})
});