diff --git a/application/controllers/system/Login.php b/application/controllers/system/Login.php new file mode 100644 index 000000000..8593a766a --- /dev/null +++ b/application/controllers/system/Login.php @@ -0,0 +1,102 @@ +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() + { + } +} diff --git a/application/libraries/AuthLib.php b/application/libraries/AuthLib.php index c59933613..d9480f6db 100644 --- a/application/libraries/AuthLib.php +++ b/application/libraries/AuthLib.php @@ -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; } /** diff --git a/application/views/system/login/usernamePassword.php b/application/views/system/login/usernamePassword.php new file mode 100644 index 000000000..944212b49 --- /dev/null +++ b/application/views/system/login/usernamePassword.php @@ -0,0 +1,45 @@ +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' + ) + ); +?> + +
+ + + +load->view('templates/FHC-Footer'); ?> diff --git a/public/css/Login.css b/public/css/Login.css new file mode 100644 index 000000000..c6c1bfae0 --- /dev/null +++ b/public/css/Login.css @@ -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; +} diff --git a/public/images/logo-300x160.png b/public/images/logo-300x160.png new file mode 100644 index 000000000..e47c48180 Binary files /dev/null and b/public/images/logo-300x160.png differ diff --git a/public/js/Login.js b/public/js/Login.js new file mode 100644 index 000000000..0cc7faf8d --- /dev/null +++ b/public/js/Login.js @@ -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(); + }) + +});