|
32 | 32 |
|
33 | 33 | class login_index { |
34 | 34 |
|
35 | | -public $status = ''; |
36 | | -private $target = ''; |
37 | | - |
38 | | -public function render() { |
| 35 | + public $status = ''; |
| 36 | + private $target = ''; |
| 37 | + private $app; |
| 38 | + private $conf; |
39 | 39 |
|
40 | | - if(isset($_SESSION['s']['user']) && is_array($_SESSION['s']['user']) && is_array($_SESSION['s']['module'])) { |
41 | | - die('HEADER_REDIRECT:'.$_SESSION['s']['module']['startpage']); |
| 40 | + public function __construct() |
| 41 | + { |
| 42 | + global $app, $conf; |
| 43 | + $this->app = $app; |
| 44 | + $this->conf = $conf; |
42 | 45 | } |
43 | 46 |
|
44 | | - global $app, $conf; |
45 | | - $app->uses('tpl'); |
46 | | - $app->tpl->newTemplate('form.tpl.htm'); |
47 | | - |
48 | | - $error = ''; |
49 | | - |
50 | | - |
51 | | - //* Login Form was send |
52 | | - if(count($_POST) > 0) { |
53 | | - |
54 | | - // iporting variables |
55 | | - $username = $app->db->quote($_POST['username']); |
56 | | - $passwort = $app->db->quote($_POST['passwort']); |
57 | | - |
58 | | - if($username != '' and $passwort != '') { |
59 | | - $sql = "SELECT * FROM sys_user WHERE USERNAME = '$username' and ( PASSWORT = '".md5($passwort)."' or PASSWORT = password('$passwort') )"; |
60 | | - $user = $app->db->queryOneRecord($sql); |
61 | | - if($user) { |
62 | | - if($user['active'] == 1) { |
63 | | - $user = $app->db->toLower($user); |
64 | | - $_SESSION = array(); |
65 | | - $_SESSION['s']['user'] = $user; |
66 | | - $_SESSION['s']['user']['theme'] = isset($user['app_theme']) ? $user['app_theme'] : 'default'; |
67 | | - $_SESSION['s']['language'] = $user['language']; |
68 | | - $_SESSION["s"]['theme'] = $_SESSION['s']['user']['theme']; |
69 | | - |
70 | | - if(is_file($_SESSION['s']['user']['startmodule'].'/lib/module.conf.php')) { |
71 | | - include_once($_SESSION['s']['user']['startmodule'].'/lib/module.conf.php'); |
72 | | - $_SESSION['s']['module'] = $module; |
73 | | - } |
74 | | - echo 'HEADER_REDIRECT:'.$_SESSION['s']['module']['startpage']; |
75 | | - |
76 | | - exit; |
77 | | - } else { |
78 | | - $error = $app->lng(1003); |
79 | | - } |
80 | | - } else { |
81 | | - //* Incorrect login - Username and password incorrect |
82 | | - $error = $app->lng(1002); |
83 | | - if($app->db->errorMessage != '') $error .= '<br>'.$app->db->errorMessage != ''; |
84 | | - } |
85 | | - } else { |
86 | | - //* Username or password empty |
87 | | - $error = $app->lng(1001); |
88 | | - } |
89 | | - } |
90 | | - if($error != ''){ |
91 | | - $error = '<table class="error"> |
92 | | - <tr> |
93 | | - <td><strong>Error:</strong><br>'.$error.'</td> |
94 | | - </tr> |
95 | | - </table>'; |
96 | | - } |
97 | | - |
98 | | - |
99 | | - |
100 | | - $app->tpl->setVar('error', $error); |
101 | | - $app->tpl->setInclude('content_tpl','login/templates/index.htm'); |
102 | | - $app->tpl_defaults(); |
| 47 | + public function render() { |
| 48 | + |
| 49 | + if(isset($_SESSION['s']['user']) && is_array($_SESSION['s']['user']) && is_array($_SESSION['s']['module'])) { |
| 50 | + die('HEADER_REDIRECT:'.$_SESSION['s']['module']['startpage']); |
| 51 | + } |
| 52 | + |
| 53 | + $this->app->uses('tpl'); |
| 54 | + $this->app->tpl->newTemplate('form.tpl.htm'); |
| 55 | + |
| 56 | + $error = ''; |
| 57 | + |
| 58 | + |
| 59 | + //* Login Form was send |
| 60 | + if(count($_POST) > 0) { |
| 61 | + |
| 62 | + // iporting variables |
| 63 | + $ip = $this->app->db->quote(ip2long($_SERVER['REMOTE_ADDR'])); |
| 64 | + $username = $this->app->db->quote($_POST['username']); |
| 65 | + $passwort = $this->app->db->quote($_POST['passwort']); |
| 66 | + |
| 67 | + if($username != '' and $passwort != '') { |
| 68 | + //* Check if there already wrong logins |
| 69 | + $sql = "SELECT * FROM `attempts_login` WHERE `ip`= '{$ip}' AND `login_time` < NOW() + INTERVAL 15 MINUTE LIMIT 1"; |
| 70 | + $alreadyfailed = $this->app->db->queryOneRecord($sql); |
| 71 | + //* login to much wrong |
| 72 | + if($alreadyfailed['times'] > 5) { |
| 73 | + $error = $this->app->lng(1004); |
| 74 | + } else { |
| 75 | + $sql = "SELECT * FROM sys_user WHERE USERNAME = '$username' and ( PASSWORT = '".md5($passwort)."' or PASSWORT = password('$passwort') )"; |
| 76 | + $user = $this->app->db->queryOneRecord($sql); |
| 77 | + if($user) { |
| 78 | + if($user['active'] == 1) { |
| 79 | + // User login right, so attempts can be deleted |
| 80 | + $sql = "DELETE FROM `attempts_login` WHERE `ip`='{$ip}'"; |
| 81 | + $this->app->db->query($sql); |
| 82 | + $user = $this->app->db->toLower($user); |
| 83 | + $_SESSION = array(); |
| 84 | + $_SESSION['s']['user'] = $user; |
| 85 | + $_SESSION['s']['user']['theme'] = isset($user['app_theme']) ? $user['app_theme'] : 'default'; |
| 86 | + $_SESSION['s']['language'] = $user['language']; |
| 87 | + $_SESSION["s"]['theme'] = $_SESSION['s']['user']['theme']; |
| 88 | + |
| 89 | + if(is_file($_SESSION['s']['user']['startmodule'].'/lib/module.conf.php')) { |
| 90 | + include_once($_SESSION['s']['user']['startmodule'].'/lib/module.conf.php'); |
| 91 | + $_SESSION['s']['module'] = $module; |
| 92 | + } |
| 93 | + echo 'HEADER_REDIRECT:'.$_SESSION['s']['module']['startpage']; |
| 94 | + |
| 95 | + exit; |
| 96 | + } else { |
| 97 | + $error = $this->app->lng(1003); |
| 98 | + } |
| 99 | + } else { |
| 100 | + if(!$alreadyfailed['times'] ) |
| 101 | + { |
| 102 | + //* user login the first time wrong |
| 103 | + $sql = "INSERT INTO `attempts_login` (`ip`, `times`, `login_time`) VALUES ('{$ip}', 1, NOW())"; |
| 104 | + $this->app->db->query($sql); |
| 105 | + } elseif($alreadyfailed['times'] >= 1) { |
| 106 | + //* update times wrong |
| 107 | + $sql = "UPDATE `attempts_login` SET `times`=`times`+1, `login_time`=NOW() WHERE `login_time` >= '{$time}' LIMIT 1"; |
| 108 | + $this->app->db->query($sql); |
| 109 | + } |
| 110 | + //* Incorrect login - Username and password incorrect |
| 111 | + $error = $this->app->lng(1002); |
| 112 | + if($this->app->db->errorMessage != '') $error .= '<br />'.$this->app->db->errorMessage != ''; |
| 113 | + } |
| 114 | + } |
| 115 | + } else { |
| 116 | + //* Username or password empty |
| 117 | + $error = $this->app->lng(1001); |
| 118 | + } |
| 119 | + } |
| 120 | + if($error != ''){ |
| 121 | + $error = '<table class="error"> |
| 122 | + <tr> |
| 123 | + <td><strong>Error:</strong><br>'.$error.'</td> |
| 124 | + </tr> |
| 125 | + </table>'; |
| 126 | + } |
103 | 127 |
|
104 | | - $this->status = 'OK'; |
105 | 128 |
|
106 | | - return $app->tpl->grab(); |
107 | 129 |
|
108 | | -} // << end function |
| 130 | + $this->app->tpl->setVar('error', $error); |
| 131 | + $this->app->tpl->setInclude('content_tpl','login/templates/index.htm'); |
| 132 | + $this->app->tpl_defaults(); |
| 133 | + |
| 134 | + $this->status = 'OK'; |
| 135 | + |
| 136 | + return $this->app->tpl->grab(); |
| 137 | + |
| 138 | + } // << end function |
109 | 139 |
|
110 | 140 | } // << end class |
111 | 141 |
|
|
0 commit comments