Skip to content

Commit fe89cdb

Browse files
committed
- fixed explanation info text in aauth config
- added `pm_cleanup_max_age`-config_var - added 2 files (`pm_deleted_sender` & `pm_deleted_receiver`) in pm table - changed `list_pms()` to catch only not deleted pm's - changed `delete_pm()` now it need a user_id to delete a pm (like `get_pm()`) - changed `delete_pm()` sender's can now detete pm's from outbox - changed `count_unread_pms()` it counts now only not deleted pm's. - added `cleanup_pms()` removes pms older than X defined by `pm_cleanup_max_age`-config_var
1 parent e6e770a commit fe89cdb

4 files changed

Lines changed: 151 additions & 100 deletions

File tree

application/config/aauth.php

Lines changed: 100 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -5,139 +5,148 @@
55
| -------------------------------------------------------------------
66
| Aauth Config
77
| -------------------------------------------------------------------
8-
| A library Basic Authorization for CodeIgniter 2+
8+
| A library Basic Authorization for CodeIgniter 2.x and 3.x
99
|
1010
| -------------------------------------------------------------------
1111
| EXPLANATION
1212
| -------------------------------------------------------------------
1313
|
14-
| See http://codeigniter-aauth-test.readthedocs.org/en/latest/
15-
| for more details and explainations
14+
| ['no_permission'] If user don't have permisssion to see the page he will be redirected the page spesificed.
1615
|
16+
| ['admin_group'] Name of admin group
17+
| ['default_group'] Name of default group, the new user is added in it
18+
| ['public_group'] Public group , people who not logged in
1719
|
18-
| ['no_permission'] If user don't have permisssion to see the page he will be redirected the page spesificed.
20+
| ['db_profile'] The configuration database profile (definied in config/database.php)
1921
|
20-
| ['admin_group'] Name of admin group
21-
| ['default_group'] Name of default group, the new user is added in it
22-
| ['public_group'] Public group , people who not logged in
22+
| ['users'] The table which contains users
23+
| ['groups'] The table which contains groups
24+
| ['user_to_group'] The table which contains join of users and groups
25+
| ['perms'] The table which contains permissions
26+
| ['perm_to_group'] The table which contains permissions for groups
27+
| ['perm_to_user'] The table which contains permissions for users
28+
| ['pms'] The table which contains private messages
29+
| ['user_variables'] The table which contains users variables
30+
| ['login_attempts'] The table which contains login attempts
2331
|
24-
| ['db_profile'] The configuration database profile (see config/database.php)
32+
| ['remember'] Remember time (in relative format) elapsed after connecting and automatic LogOut for usage with Cookies
33+
| Relative Format (e.g. '+ 1 week', '+ 1 month', '+ first day of next month')
34+
| for details see http://php.net/manual/de/datetime.formats.relative.php
35+
| !!IMPORTANT!! If you use Session instead of Cookies,
36+
| remember time is definied by 'sess_expiration' in config/config.php
2537
|
26-
| ['users'] The table which contains users
27-
| ['groups'] The table which contains groups
28-
| ['user_to_group'] The table which contains join of users and groups
29-
| ['perms'] The table which contains permissions
30-
| ['perm_to_group'] The table which contains permissions for groups
31-
| ['perm_to_user'] The table which contains permissions for users
32-
| ['pms'] The table which contains private messages
33-
| ['user_variables'] The table which contains users variables
34-
| ['login_attempts'] The table which contains login attempts
38+
| ['max'] Maximum char long for Password
39+
| ['min'] Minimum char long for Password
3540
|
36-
| ['remember'] Remember time elapsed after connecting and automatic LogOut
41+
| ['additional_valid_chars'] Additional valid chars for username. Non alphanumeric characters that are allowed by default
3742
|
38-
| ['max'] Maximum char long for Password
39-
| ['min'] Minimum char long for Password
43+
| ['ddos_protection'] If it is true, the user will be banned temporary when he exceed the login 'try'
4044
|
41-
| ['additional_valid_chars'] Additional valid chars for username. Non alphanumeric characters that are allowed by default
45+
| ['recaptcha_active'] Enable reCAPTCHA (for details see www.google.com/recaptcha/admin)
46+
| ['recaptcha_login_attempts'] Login Attempts to display reCAPTCHA
47+
| ['recaptcha_siteKey'] The reCAPTCHA siteKey
48+
| ['recaptcha_secret'] The reCAPTCHA secretKey
4249
|
43-
| ['ddos_protection'] If it is true, the user will be banned temporary when he exceed the login 'try'
50+
| ['totp_active'] The Time-based One-time Password Algorithm
51+
| ['totp_only_on_ip_change'] TOTP only on IP Change
52+
| ['totp_reset_over_reset_password'] TOTP reset over reset Password
53+
| ['totp_two_step_login'] Enables/Disables TOTP two step login
54+
| ['totp_two_step_login_redirect'] Redirect path to TOTP Verification page used by control() & is_allowed()
4455
|
45-
| ['recaptcha_active'] Enable reCAPTCHA (see www.google.com/recaptcha/admin)
46-
| ['recaptcha_login_attempts'] :
47-
| ['recaptcha_siteKey'] The reCAPTCHA siteKey
48-
| ['recaptcha_secret'] The reCAPTCHA secretKey
56+
| ['max_login_attempt'] Login attempts time interval (default 10 times in one hour)
57+
| ['max_login_attempt_time_period'] Period of time for max login attempts (default "5 minutes")
58+
| ['remove_successful_attempts'] Enables/Disables removing login attempt after successful login
4959
|
50-
| ['totp_active'] The Time-based One-time Password Algorithm
51-
| ['totp_only_on_ip_change'] TOTP only on IP Change
52-
| ['totp_reset_over_reset_password'] TOTP reset over reset Password
53-
| ['totp_two_step_login'] Enables/Disables TOTP two step login
54-
| ['totp_two_step_login_redirect'] Redirect path to TOTP Verification page used by control() & is_allowed()
60+
| ['login_with_name'] Login Identificator, if TRUE username needed to login else email address.
5561
|
56-
| ['max_login_attempt'] Login attempts time interval (default 10 times in one hour)
57-
| ['max_login_attempt_time_period'] Period of time for max login attempts (default "5 minutes")
58-
| ['remove_successful_attempts'] Enables/Disables removing login attempt after successful login
62+
| ['use_cookies'] FALSE only on CI3
5963
|
60-
| ['login_with_name'] Login Identificator, if TRUE username needed to login else email address.
64+
| ['email'] Sender email address, used for remind_password, send_verification and reset_password
65+
| ['name'] Sender name, used for remind_password, send_verification and reset_password
6166
|
62-
| ['use_cookies'] FALSE only on CI3
67+
| ['verification'] User Verification, if TRUE sends a verification email on account creation.
68+
| ['verification_link'] Link for verification without site_url or base_url
69+
| ['reset_password_link'] Link for reset_password without site_url or base_url
6370
|
64-
| ['email'] Sender email address, used for remind_password, send_verification and reset_password
65-
| ['name'] Sender name, used for remind_password, send_verification and reset_password
66-
|
67-
| ['verification'] User Verification, if TRUE sends a verification email on account creation.
68-
| ['verification_link'] Link for verification without site_url or base_url
69-
| ['reset_password_link'] Link for reset_password without site_url or base_url
70-
|
71-
| ['hash'] Name of selected hashing algorithm (e.g. "md5", "sha256", "haval160,4", etc..)
71+
| ['hash'] Name of selected hashing algorithm (e.g. "md5", "sha256", "haval160,4", etc..)
7272
| Please, run hash_algos() for know your all supported algorithms
73-
| ['use_password_hash'] True to use PHP's own password_hash() function with BCrypt, needs PHP5.5 or higher
74-
| ['password_hash_algo'] password_hash algorithm (PASSWORD_DEFAULT, PASSWORD_BCRYPT) for details see http://php.net/manual/de/password.constants.php
75-
| ['password_hash_options'] password_hash options array for details see http://php.net/manual/en/function.password-hash.php
73+
| ['use_password_hash'] True to use PHP's own password_hash() function with BCrypt, needs PHP5.5 or higher
74+
| ['password_hash_algo'] password_hash algorithm (PASSWORD_DEFAULT, PASSWORD_BCRYPT)
75+
| for details see http://php.net/manual/de/password.constants.php
76+
| ['password_hash_options'] password_hash options array
77+
| for details see http://php.net/manual/en/function.password-hash.php
78+
|
79+
| ['pm_encryption'] Enables/Disables PM Encryption, needs configured CI Encryption Class.
80+
| for details see: http://www.codeigniter.com/userguide2/libraries/encryption.html
81+
| ['pm_cleanup_max_age'] PM Cleanup max age (in relative format), PM's are older than max age get deleted with 'cleanup_pms()'
82+
| Relative Format (e.g. '2 week', '1 month')
83+
| for details see http://php.net/manual/de/datetime.formats.relative.php
7684
|
7785
*/
7886
$config_aauth = array();
7987

8088
$config_aauth["default"] = array(
81-
'no_permission' => FALSE,
89+
'no_permission' => FALSE,
8290

83-
'admin_group' => 'admin',
84-
'default_group' => 'default',
85-
'public_group' => 'public',
91+
'admin_group' => 'admin',
92+
'default_group' => 'default',
93+
'public_group' => 'public',
8694

87-
'db_profile' => 'default',
95+
'db_profile' => 'default',
8896

89-
'users' => 'aauth_users',
90-
'groups' => 'aauth_groups',
91-
'group_to_group' => 'aauth_group_to_group',
92-
'user_to_group' => 'aauth_user_to_group',
93-
'perms' => 'aauth_perms',
94-
'perm_to_group' => 'aauth_perm_to_group',
95-
'perm_to_user' => 'aauth_perm_to_user',
96-
'pms' => 'aauth_pms',
97-
'user_variables' => 'aauth_user_variables',
98-
'login_attempts' => 'aauth_login_attempts',
97+
'users' => 'aauth_users',
98+
'groups' => 'aauth_groups',
99+
'group_to_group' => 'aauth_group_to_group',
100+
'user_to_group' => 'aauth_user_to_group',
101+
'perms' => 'aauth_perms',
102+
'perm_to_group' => 'aauth_perm_to_group',
103+
'perm_to_user' => 'aauth_perm_to_user',
104+
'pms' => 'aauth_pms',
105+
'user_variables' => 'aauth_user_variables',
106+
'login_attempts' => 'aauth_login_attempts',
99107

100-
'remember' => ' +3 days',
108+
'remember' => ' +3 days',
101109

102-
'max' => 13,
103-
'min' => 5,
110+
'max' => 13,
111+
'min' => 5,
104112

105-
'additional_valid_chars' => array(),
113+
'additional_valid_chars' => array(),
106114

107-
'ddos_protection' => true,
115+
'ddos_protection' => true,
108116

109-
'recaptcha_active' => false,
110-
'recaptcha_login_attempts' => 4,
111-
'recaptcha_siteKey' => '',
112-
'recaptcha_secret' => '',
117+
'recaptcha_active' => false,
118+
'recaptcha_login_attempts' => 4,
119+
'recaptcha_siteKey' => '',
120+
'recaptcha_secret' => '',
113121

114-
'totp_active' => false,
115-
'totp_only_on_ip_change' => false,
116-
'totp_reset_over_reset_password' => false,
117-
'totp_two_step_login_active' => false,
118-
'totp_two_step_login_redirect' => '/account/twofactor_verification/',
122+
'totp_active' => false,
123+
'totp_only_on_ip_change' => false,
124+
'totp_reset_over_reset_password' => false,
125+
'totp_two_step_login_active' => false,
126+
'totp_two_step_login_redirect' => '/account/twofactor_verification/',
119127

120-
'max_login_attempt' => 10,
121-
'max_login_attempt_time_period' => "5 minutes",
122-
'remove_successful_attempts' => true,
128+
'max_login_attempt' => 10,
129+
'max_login_attempt_time_period' => "5 minutes",
130+
'remove_successful_attempts' => true,
123131

124-
'login_with_name' => false,
132+
'login_with_name' => false,
125133

126-
'use_cookies' => true,
134+
'use_cookies' => true,
127135

128-
'email' => 'admin@admin.com',
129-
'name' => 'Emre Akay',
136+
'email' => 'admin@admin.com',
137+
'name' => 'Emre Akay',
130138

131-
'verification' => false,
132-
'verification_link' => '/account/verification/',
133-
'reset_password_link' => '/account/reset_password/',
139+
'verification' => false,
140+
'verification_link' => '/account/verification/',
141+
'reset_password_link' => '/account/reset_password/',
134142

135-
'hash' => 'sha256',
136-
'use_password_hash' => false,
137-
'password_hash_algo' => PASSWORD_DEFAULT,
138-
'password_hash_options' => array(),
143+
'hash' => 'sha256',
144+
'use_password_hash' => false,
145+
'password_hash_algo' => PASSWORD_DEFAULT,
146+
'password_hash_options' => array(),
139147

140-
'pm_encryption' => false
148+
'pm_encryption' => false,
149+
'pm_cleanup_max_age' => "6 months",
141150
);
142151

143152
$config['aauth'] = $config_aauth['default'];

application/libraries/Aauth.php

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,14 +1963,14 @@ public function send_pms( $sender_id, $receiver_ids, $title, $message ){
19631963
* @param int $receiver_id User id of private message receiver
19641964
* @return object Array of private messages
19651965
*/
1966-
public function list_pms($limit=5, $offset=0, $receiver_id = FALSE, $sender_id=FALSE){
1967-
1968-
if ( $receiver_id != FALSE){
1966+
public function list_pms($limit=5, $offset=0, $receiver_id=NULL, $sender_id=NULL){
1967+
if (is_numeric($sender_id)){
19691968
$query = $this->aauth_db->where('receiver_id', $receiver_id);
1969+
$query = $this->aauth_db->where('pm_deleted_receiver', 0);
19701970
}
1971-
1972-
if( $sender_id != FALSE ){
1971+
if (is_numeric($sender_id)){
19731972
$query = $this->aauth_db->where('sender_id', $sender_id);
1973+
$query = $this->aauth_db->where('pm_deleted_sender', 0);
19741974
}
19751975

19761976
$query = $this->aauth_db->order_by('id','DESC');
@@ -1991,7 +1991,7 @@ public function get_pm($pm_id, $user_id = NULL, $set_as_read = TRUE){
19911991
if(!$user_id){
19921992
$user_id = $this->CI->session->userdata('id');
19931993
}
1994-
if( !is_numeric($user_id)){
1994+
if( !is_numeric($user_id) || !is_numeric($pm_id)){
19951995
$this->error( $this->CI->lang->line('aauth_error_no_pm') );
19961996
return FALSE;
19971997
}
@@ -2028,9 +2028,46 @@ public function get_pm($pm_id, $user_id = NULL, $set_as_read = TRUE){
20282028
* @param int $pm_id Private message id to be deleted
20292029
* @return bool Delete success/failure
20302030
*/
2031-
public function delete_pm($pm_id){
2032-
2033-
return $this->aauth_db->delete( $this->config_vars['pms'], array('id' => $pm_id) );
2031+
public function delete_pm($pm_id, $user_id = NULL){
2032+
if(!$user_id){
2033+
$user_id = $this->CI->session->userdata('id');
2034+
}
2035+
if( !is_numeric($user_id) || !is_numeric($pm_id)){
2036+
$this->error( $this->CI->lang->line('aauth_error_no_pm') );
2037+
return FALSE;
2038+
}
2039+
2040+
$query = $this->aauth_db->where('id', $pm_id);
2041+
$query = $this->aauth_db->where('receiver_id', $user_id);
2042+
$query = $this->aauth_db->or_where('sender_id', $user_id);
2043+
$query = $this->aauth_db->get( $this->config_vars['pms'] );
2044+
$result = $query->row();
2045+
if ($user_id == $result->sender_id){
2046+
if($result->pm_deleted_receiver == 1){
2047+
return $this->aauth_db->delete( $this->config_vars['pms'], array('id' => $pm_id));
2048+
}
2049+
2050+
return $this->aauth_db->update( $this->config_vars['pms'], array('pm_deleted_sender'=>1), array('id' => $pm_id));
2051+
}else if ($user_id == $result->result->receiver_id){
2052+
if($result->pm_deleted_sender == 1){
2053+
return $this->aauth_db->delete( $this->config_vars['pms'], array('id' => $pm_id));
2054+
}
2055+
2056+
return $this->aauth_db->update( $this->config_vars['pms'], array('pm_deleted_receiver'=>1), array('id' => $pm_id) );
2057+
}
2058+
}
2059+
2060+
/**
2061+
* Cleanup PMs
2062+
* Removes PMs older than 'pm_cleanup_max_age' (definied in aauth config).
2063+
* recommend for a cron job
2064+
*/
2065+
public function cleanup_pms(){
2066+
$pm_cleanup_max_age = $this->config_vars['pm_cleanup_max_age'];
2067+
$date_sent = date('Y-m-d H:i:s', strtotime("now -".$pm_cleanup_max_age));
2068+
$this->aauth_db->where('date_sent <', $date_sent);
2069+
2070+
return $this->aauth_db->delete($this->config_vars['pms']);
20342071
}
20352072

20362073
//tested
@@ -2047,6 +2084,7 @@ public function count_unread_pms($receiver_id=FALSE){
20472084
}
20482085

20492086
$query = $this->aauth_db->where('receiver_id', $receiver_id);
2087+
$query = $this->aauth_db->where('pm_deleted_receiver', 0);
20502088
$query = $this->aauth_db->where('date_read', NULL);
20512089
$query = $this->aauth_db->get( $this->config_vars['pms'] );
20522090

sql/Aauth_v2.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ CREATE TABLE `aauth_pms` (
7777
`message` text,
7878
`date_sent` datetime DEFAULT NULL,
7979
`date_read` datetime DEFAULT NULL,
80+
`pm_deleted_sender` int(1) DEFAULT '0',
81+
`pm_deleted_receiver` int(1) DEFAULT '0',
8082
PRIMARY KEY (`id`),
8183
KEY `full_index` (`id`,`sender_id`,`receiver_id`,`date_read`)
8284
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

sql/Aauth_v2_BCrypt.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ CREATE TABLE `aauth_pms` (
7777
`message` text,
7878
`date_sent` datetime DEFAULT NULL,
7979
`date_read` datetime DEFAULT NULL,
80+
`pm_deleted_sender` int(1) DEFAULT '0',
81+
`pm_deleted_receiver` int(1) DEFAULT '0',
8082
PRIMARY KEY (`id`),
8183
KEY `full_index` (`id`,`sender_id`,`receiver_id`,`date_read`)
8284
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

0 commit comments

Comments
 (0)