| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | ** @desc: PHP ajax login form using jQuery |
|---|
| 4 | ** @author: programmer@chazzuka.com |
|---|
| 5 | ** @url: http://www.chazzuka.com/blog |
|---|
| 6 | ** @date: 15 August 2008 |
|---|
| 7 | ** @license: Free!, but i'll be glad if i my name listed in the credits' |
|---|
| 8 | */ |
|---|
| 9 | |
|---|
| 10 | // @ error reporting setting ( modify as needed ) |
|---|
| 11 | ini_set("display_errors", 1); |
|---|
| 12 | error_reporting (E_ALL ^ E_NOTICE); |
|---|
| 13 | |
|---|
| 14 | //@ explicity start session just if not automatically started at php.ini |
|---|
| 15 | session_start(); |
|---|
| 16 | |
|---|
| 17 | //@ validate inclusion |
|---|
| 18 | define('VALID_ACL_', true); |
|---|
| 19 | |
|---|
| 20 | //@ load dependency files |
|---|
| 21 | require('login.config.php'); |
|---|
| 22 | require('login.lang.php'); |
|---|
| 23 | require('login.class.php'); |
|---|
| 24 | |
|---|
| 25 | //@ new acl instance |
|---|
| 26 | $acl = new Authorization; |
|---|
| 27 | |
|---|
| 28 | //@check session status |
|---|
| 29 | $status = $acl->check_status(); |
|---|
| 30 | |
|---|
| 31 | if ($status) { |
|---|
| 32 | // @ session already active |
|---|
| 33 | echo "{'status':true, 'message':'<div class=\"welcome\">Welcome, <b>".$_SESSION['exp_user']['username']."!</div> <div class=\"logout\"><img src=\"http://images.acelogisticsllc.com/layout/user-48.png\" alt=\"Ace Logistics\" class=\"avatar\"/> <a href=\"php/index.php?logoff=1\">Logout</a></b> | <b><a id=\"changeP\" href=\"#change\">Change password</a></b></div>'}"; |
|---|
| 34 | } else { |
|---|
| 35 | //@ session not active |
|---|
| 36 | if ($_SERVER['REQUEST_METHOD']=='GET') { |
|---|
| 37 | //@ first load |
|---|
| 38 | echo "{'status':false,'message':'".$acl->form()."'}"; |
|---|
| 39 | } else { |
|---|
| 40 | //@ form submission |
|---|
| 41 | $u = (!empty($_POST['u']))?trim($_POST['u']):false; |
|---|
| 42 | // retrive user var |
|---|
| 43 | $p = (!empty($_POST['p']))?trim($_POST['p']):false; |
|---|
| 44 | // retrive password var |
|---|
| 45 | |
|---|
| 46 | // @ try to signin |
|---|
| 47 | $is_auth = $acl->signin($u,$p); |
|---|
| 48 | $acl->loginTime(); |
|---|
| 49 | |
|---|
| 50 | if ($is_auth) { |
|---|
| 51 | //@ success |
|---|
| 52 | echo "{'status':true, 'message':'Welcome, <b>".$_SESSION['exp_user']['username']."!</b>', 'url':'".SUCCESS_URL."'}"; |
|---|
| 53 | } else { |
|---|
| 54 | //@ failed |
|---|
| 55 | echo "{'status': false,'message':'<span class=\"warning\"> <b>*Your ".((LOGIN_METHOD=='user'||LOGIN_METHOD=='both')?'username':'')." or password was entered incorrectly.</b></span>'}"; |
|---|
| 56 | } |
|---|
| 57 | } |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | //@ destroy instance |
|---|
| 61 | unset($acl); |
|---|