| 1 |
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
class Freakauth_light |
|---|
| 65 |
{ |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
function Freakauth_light() |
|---|
| 77 |
{ |
|---|
| 78 |
$this->CI=& get_instance(); |
|---|
| 79 |
|
|---|
| 80 |
log_message('debug', "FreakAuth Class Initialized"); |
|---|
| 81 |
|
|---|
| 82 |
$this->CI->load->library('db_session'); |
|---|
| 83 |
$this->CI->load->helper('form'); |
|---|
| 84 |
$this->CI->load->helper('url'); |
|---|
| 85 |
$this->CI->load->helper('freakauth_light'); |
|---|
| 86 |
$this->CI->load->model('FreakAuth_light/usertemp', 'UserTemp'); |
|---|
| 87 |
$this->CI->load->model('usermodel', 'usermodel'); |
|---|
| 88 |
if($this->CI->config->item('FAL_create_user_profile')) |
|---|
| 89 |
$this->CI->load->model('Userprofile', 'userprofile'); |
|---|
| 90 |
|
|---|
| 91 |
$this->_init(); |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
function _init() |
|---|
| 102 |
{ |
|---|
| 103 |
|
|---|
| 104 |
if (!$this->CI->config->item('FAL')) |
|---|
| 105 |
{ |
|---|
| 106 |
|
|---|
| 107 |
$this->CI->lang->load('freakauth'); |
|---|
| 108 |
$website_name = $this->CI->config->item('FAL_website_name'); |
|---|
| 109 |
$message = sprintf( |
|---|
| 110 |
$this->CI->lang->line('FAL_turned_off_message'), |
|---|
| 111 |
$website_name |
|---|
| 112 |
); |
|---|
| 113 |
$data['website_name'] = $website_name; |
|---|
| 114 |
$data['message'] = $message; |
|---|
| 115 |
echo $this->CI->load->view($this->CI->config->item('FAL_template_dir').'content/turned_off', $data, true); |
|---|
| 116 |
exit; |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
function check($_lock_to_role=null, $_only=null) |
|---|
| 147 |
{ |
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
$_who_is = $this->CI->db_session->userdata('role'); |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
if ($this->CI->db_session AND $this->CI->config->item('FAL') AND !empty($_who_is)) |
|---|
| 154 |
{ |
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
$_hierarchy = $this->CI->config->item('FAL_roles'); |
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
if ($_lock_to_role==null){$_lock_to_role='user';} |
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
$_lock_hierarchy = $_hierarchy[$_lock_to_role]; |
|---|
| 165 |
|
|---|
| 166 |
$_request_hierarchy = $_hierarchy[$_who_is]; |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
switch ($_only) |
|---|
| 170 |
{ |
|---|
| 171 |
case true: |
|---|
| 172 |
$_request_hierarchy == $_lock_hierarchy ? $_condition = true : $_condition = false; |
|---|
| 173 |
break; |
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
default: |
|---|
| 177 |
$_request_hierarchy <= $_lock_hierarchy ? $_condition = true : $_condition = false; |
|---|
| 178 |
break; |
|---|
| 179 |
|
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
if ($_condition==false) |
|---|
| 184 |
{ |
|---|
| 185 |
$this->denyAccess($_who_is); |
|---|
| 186 |
} |
|---|
| 187 |
} |
|---|
| 188 |
|
|---|
| 189 |
else |
|---|
| 190 |
{ |
|---|
| 191 |
$this->denyAccess($_who_is); |
|---|
| 192 |
} |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
function denyAccess($role) |
|---|
| 213 |
{ |
|---|
| 214 |
$this->CI->lang->load('freakauth'); |
|---|
| 215 |
if ($this->CI->config->item('FAL_deny_with_flash_message')) |
|---|
| 216 |
{ |
|---|
| 217 |
|
|---|
| 218 |
if ($role == '') |
|---|
| 219 |
{ |
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
$this->CI->db_session->set_flashdata('requested_page', |
|---|
| 223 |
$this->CI->uri->uri_string()); |
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
$msg = $this->CI->lang->line('FAL_no_credentials_guest'); |
|---|
| 229 |
flashMsg($msg); |
|---|
| 230 |
redirect($this->CI->config->item('FAL_login_uri'), 'location'); |
|---|
| 231 |
} |
|---|
| 232 |
|
|---|
| 233 |
else |
|---|
| 234 |
{ |
|---|
| 235 |
$msg = $this->CI->lang->line('FAL_no_credentials_user'); |
|---|
| 236 |
flashMsg($msg); |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
if (isset($_SERVER['HTTP_REFERER'])) |
|---|
| 240 |
{ |
|---|
| 241 |
$referer = $_SERVER['HTTP_REFERER']; |
|---|
| 242 |
if (preg_match("|^".base_url()."|", $referer) == 0) |
|---|
| 243 |
{ |
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
redirect($this->CI->config->item('FAL_denied_from_ext_location')); |
|---|
| 247 |
} |
|---|
| 248 |
else |
|---|
| 249 |
{ |
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
$this->CI->db_session->keep_flashdata('requested_page'); |
|---|
| 254 |
header("location:".$_SERVER['HTTP_REFERER']); |
|---|
| 255 |
exit(); |
|---|
| 256 |
} |
|---|
| 257 |
} |
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
else |
|---|
| 261 |
{ |
|---|
| 262 |
redirect($this->CI->config->item('FAL_denied_from_ext_location'), 'location'); |
|---|
| 263 |
} |
|---|
| 264 |
} |
|---|
| 265 |
} |
|---|
| 266 |
else |
|---|
| 267 |
{ |
|---|
| 268 |
$page = $this->CI->config->item('FAL_denied_page'); |
|---|
| 269 |
$data['role'] = $role; |
|---|
| 270 |
|
|---|
| 271 |
echo $this->CI->load->view($page, $data, true); |
|---|
| 272 |
exit(); |
|---|
| 273 |
} |
|---|
| 274 |
} |
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
function isAdmin() |
|---|
| 289 |
{ |
|---|
| 290 |
|
|---|
| 291 |
if ($this->CI->db_session AND $this->CI->config->item('FAL')) |
|---|
| 292 |
{ |
|---|
| 293 |
$_username = $this->CI->db_session->userdata('user_name'); |
|---|
| 294 |
$_role = $this->CI->db_session->userdata('role'); |
|---|
| 295 |
|
|---|
| 296 |
if ($_username != false && $_role != false AND ($_role=='admin' OR $_role=='superadmin')) |
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
return true; |
|---|
| 300 |
} |
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
return false; |
|---|
| 304 |
} |
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
function isSuperAdmin() |
|---|
| 317 |
{ |
|---|
| 318 |
|
|---|
| 319 |
if ($this->CI->db_session AND $this->CI->config->item('FAL')) |
|---|
| 320 |
{ |
|---|
| 321 |
$_username = $this->CI->db_session->userdata('user_name'); |
|---|
| 322 |
$_role = $this->CI->db_session->userdata('role'); |
|---|
| 323 |
|
|---|
| 324 |
if ($_username != false AND $_role != false AND $_role=='superadmin') |
|---|
| 325 |
|
|---|
| 326 |
return true; |
|---|
| 327 |
} |
|---|
| 328 |
|
|---|
| 329 |
return false; |
|---|
| 330 |
} |
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 |
|
|---|
| 337 |
|
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
function isValidUser() |
|---|
| 341 |
{ |
|---|
| 342 |
|
|---|
| 343 |
if ($this->CI->db_session AND $this->CI->config->item('FAL')) |
|---|
| 344 |
{ |
|---|
| 345 |
if ($this->getUserName() != '') |
|---|
| 346 |
return true; |
|---|
| 347 |
} |
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 |
return false; |
|---|
| 351 |
} |
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
function belongsToGroup($_group=null, $_only=null) |
|---|
| 382 |
{ |
|---|
| 383 |
if ($this->CI->db_session AND $this->CI->config->item('FAL')) |
|---|
| 384 |
{ |
|---|
| 385 |
$_username = $this->CI->db_session->userdata('user_name'); |
|---|
| 386 |
$_who_is = $this->CI->db_session->userdata('role'); |
|---|
| 387 |
|
|---|
| 388 |
if ($_username != false AND $_who_is != false) |
|---|
| 389 |
{ |
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
if ($_group==null){$_group='user';} |
|---|
| 393 |
|
|---|
| 394 |
$_groups = explode(",", $_group); |
|---|
| 395 |
|
|---|
| 396 |
$_group = array(); |
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 |
foreach($_groups as $_grp) |
|---|
| 400 |
{ |
|---|
| 401 |
$_group[] = trim($_grp); |
|---|
| 402 |
} |
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 |
switch ($_only) |
|---|
| 407 |
{ |
|---|
| 408 |
|
|---|
| 409 |
case true: |
|---|
| 410 |
in_array($_who_is, $_group) ? $_condition = true : $_condition = false; |
|---|
| 411 |
break; |
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
default: |
|---|
| 416 |
|
|---|
| 417 |
$_hierarchy = $this->CI->config->item('FAL_roles'); |
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 |
foreach ($_group as $value) |
|---|
| 422 |
{ |
|---|
| 423 |
$_group_hierarchy []= $_hierarchy[$value]; |
|---|
| 424 |
} |
|---|
| 425 |
|
|---|
| 426 |
$_group_hierarchy = max($_group_hierarchy); |
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
$_who_hierarchy = $_hierarchy[$_who_is]; |
|---|
| 431 |
|
|---|
| 432 |
$_who_hierarchy <= $_group_hierarchy ? $_condition = true : $_condition = false; |
|---|
| 433 |
break; |
|---|
| 434 |
|
|---|
| 435 |
} |
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
if ($_condition==true) |
|---|
| 439 |
{ |
|---|
| 440 |
return TRUE; |
|---|
| 441 |
} |
|---|
| 442 |
} |
|---|
| 443 |
} |
|---|
| 444 |
|
|---|
| 445 |
return false; |
|---|
| 446 |
} |
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 |
function login() |
|---|
| 457 |
{ |
|---|
| 458 |
if (!$this->CI->config->item('FAL')) |
|---|
| 459 |
{ |
|---|
| 460 |
redirect($this->CI->config->item('FAL_login_success_action'), 'location'); |
|---|
| 461 |
} |
|---|
| 462 |
|
|---|
| 463 |
$message = $this->CI->lang->line('FAL_invalid_user_message'); |
|---|
| 464 |
|
|---|
| 465 |
if ($this->CI->db_session) |
|---|
| 466 |
{ |
|---|
| 467 |
$values = $this->getLoginForm(); |
|---|
| 468 |
$username = (isset($values['user_name']) ? $values['user_name'] : false); |
|---|
| 469 |
$password = (isset($values['password']) ? $values['password'] : false); |
|---|
| 470 |
|
|---|
| 471 |
if (($username != false) && ($password != false)) |
|---|
| 472 |
{ |
|---|
| 473 |
$password = $this->_encode($password); |
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
$query = $this->CI->usermodel->getUserForLogin($username, $password); |
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
if ($query->num_rows() == 1) |
|---|
| 481 |
{ |
|---|
| 482 |
$row = $query->row(); |
|---|
| 483 |
$fields = array('id', 'user_name', 'country_id', 'email', |
|---|
| 484 |
'role', 'last_visit', 'created', 'modified'); |
|---|
| 485 |
foreach($fields as $field) $userdata[$field] = $row->{$field}; |
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
if ($row->{'banned'} == 0) |
|---|
| 490 |
{ |
|---|
| 491 |
$this->_set_logindata($userdata); |
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
flashMsg( $this->CI->lang->line('FAL_login_message') ); |
|---|
| 496 |
return true; |
|---|
| 497 |
} |
|---|
| 498 |
else |
|---|
| 499 |
{ |
|---|
| 500 |
$message = $this->CI->lang->line('FAL_banned_user_message'); |
|---|
| 501 |
} |
|---|
| 502 |
} |
|---|
| 503 |
} |
|---|
| 504 |
} |
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
flashMsg( $message ); |
|---|
| 509 |
|
|---|
| 510 |
return false; |
|---|
| 511 |
} |
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 |
|
|---|
| 518 |
function logout() |
|---|
| 519 |
{ |
|---|
| 520 |
|
|---|
| 521 |
if ($this->CI->db_session) |
|---|
| 522 |
{ |
|---|
| 523 |
$_username = $this->CI->db_session->userdata('user_name'); |
|---|
| 524 |
|
|---|
| 525 |
if ($_username != false) |
|---|
| 526 |
|
|---|
| 527 |
$this->_unset_user($_username); |
|---|
| 528 |
} |
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
$msg = $this->CI->lang->line('FAL_logout_message'); |
|---|
| 532 |
flashMsg($msg); |
|---|
| 533 |
|
|---|
| 534 |
redirect($this->CI->config->item('FAL_logout_success_action'), 'location'); |
|---|
| 535 |
} |
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 |
|
|---|
| 541 |
|
|---|
| 542 |
|
|---|
| 543 |
|
|---|
| 544 |
function register() |
|---|
| 545 |
{ |
|---|
| 546 |
|
|---|
| 547 |
|
|---|
| 548 |
if (!$this->CI->config->item('FAL_register_direct')) |
|---|
| 549 |
{ |
|---|
| 550 |
$this->cleanExpiredUserTemp(); |
|---|
| 551 |
} |
|---|
| 552 |
|
|---|
| 553 |
|
|---|
| 554 |
if (!$this->CI->config->item('FAL') OR $this->CI->config->item('FAL_allow_user_registration')!=TRUE) |
|---|
| 555 |
return false; |
|---|
| 556 |
|
|---|
| 557 |
if ($this->CI->db_session) |
|---|
| 558 |
{ |
|---|
| 559 |
|
|---|
| 560 |
$values = $this->getRegistrationForm(); |
|---|
| 561 |
$username = (isset($values['user_name']) ? $values['user_name'] : false); |
|---|
| 562 |
$password = (isset($values['password']) ? $values['password'] : false); |
|---|
| 563 |
$email = (isset($values['email']) ? $values['email'] : false); |
|---|
| 564 |
|
|---|
| 565 |
if (($username != false) && ($password != false) && ($email != false)) |
|---|
| 566 |
{ |
|---|
| 567 |
$password_email=$password; |
|---|
| 568 |
$password = $this->_encode($password); |
|---|
| 569 |
|
|---|
| 570 |
|
|---|
| 571 |
$values['password'] = $password; |
|---|
| 572 |
|
|---|
| 573 |
|
|---|
| 574 |
|
|---|
| 575 |
if (!$this->CI->config->item('FAL_register_direct')) |
|---|
| 576 |
{ |
|---|
| 577 |
|
|---|
| 578 |
$activation_code = $this->_generateRandomString(); |
|---|
| 579 |
$values['activation_code'] = $activation_code; |
|---|
| 580 |
$query = $this->CI->UserTemp->insertUserForRegistration($values); |
|---|
| 581 |
|
|---|
| 582 |
|
|---|
| 583 |
|
|---|
| 584 |
$query = $this->CI->UserTemp->getUserLoginData($username, $password); |
|---|
| 585 |
|
|---|
| 586 |
$user_id = 0; |
|---|
| 587 |
if (($query != null) && ($query->num_rows() > 0)) |
|---|
| 588 |
{ |
|---|
| 589 |
$row = $query->row(); |
|---|
| 590 |
$user_id = $row->id; |
|---|
| 591 |
|
|---|
| 592 |
$this->_sendActivationEmail($user_id, $username, $password_email, $email, $activation_code); |
|---|
| 593 |
|
|---|
| 594 |
return true; |
|---|
| 595 |
} |
|---|
| 596 |
} |
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
else |
|---|
| 601 |
{ |
|---|
| 602 |
|
|---|
| 603 |
$query = $this->CI->usermodel->insertUser($values); |
|---|
| 604 |
|
|---|
| 605 |
|
|---|
| 606 |
if ($this->CI->db->affected_rows() == 1) |
|---|
| 607 |
{ |
|---|
| 608 |
|
|---|
| 609 |
if($this->CI->config->item('FAL_create_user_profile')) |
|---|
| 610 |
{ |
|---|
| 611 |
|
|---|
| 612 |
$data_profile['id'] = $this->CI->db->insert_id(); |
|---|
| 613 |
$this->CI->userprofile->insertUserProfile($data_profile); |
|---|
| 614 |
} |
|---|
| 615 |
|
|---|
| 616 |
flashMsg( $this->CI->lang->line('FAL_activation_success_message') ); |
|---|
| 617 |
return true; |
|---|
| 618 |
} |
|---|
| 619 |
|
|---|
| 620 |
|
|---|
| 621 |
} |
|---|
| 622 |
} |
|---|
| 623 |
else |
|---|
| 624 |
{ |
|---|
| 625 |
|
|---|
| 626 |
flashMsg( $this->CI->lang->line('FAL_invalid_register_message') ); |
|---|
| 627 |
|
|---|
| 628 |
return false; |
|---|
| 629 |
} |
|---|
| 630 |
} |
|---|
| 631 |
} |
|---|
| 632 |
|
|---|
| 633 |
|
|---|
| 634 |
|
|---|
| 635 |
|
|---|
| 636 |
|
|---|
| 637 |
|
|---|
| 638 |
|
|---|
| 639 |
|
|---|
| 640 |
|
|---|
| 641 |
|
|---|
| 642 |
|
|---|
| 643 |
function activation($id, $activation_code) |
|---|
| 644 |
{ |
|---|
| 645 |
|
|---|
| 646 |
|
|---|
| 647 |
if (!$this->CI->config->item('FAL_register_direct')) |
|---|
| 648 |
{ |
|---|
| 649 |
$this->cleanExpiredUserTemp(); |
|---|
| 650 |
} |
|---|
| 651 |
|
|---|
| 652 |
if (($id > 0) && ($activation_code != '')) |
|---|
| 653 |
{ |
|---|
| 654 |
|
|---|
| 655 |
$query = $this->CI->UserTemp->getUserForActivation($id, $activation_code); |
|---|
| 656 |
|
|---|
| 657 |
|
|---|
| 658 |
$this->CI->UserTemp->deleteUserAfterActivation($id); |
|---|
| 659 |
|
|---|
| 660 |
if ($query->num_rows() > 0) |
|---|
| 661 |
{ |
|---|
| 662 |
foreach ($query->result() as $row) |
|---|
| 663 |
{ |
|---|
| 664 |
$data['user_name'] = $row->user_name; |
|---|
| 665 |
$data['country_id'] = $row->country_id; |
|---|
| 666 |
$data['password'] = $row->password; |
|---|
| 667 |
$data['email'] = $row->email; |
|---|
| 668 |
} |
|---|
| 669 |
|
|---|
| 670 |
|
|---|
| 671 |
|
|---|
| 672 |
$this->CI->usermodel->insertUser($data); |
|---|
| 673 |
|
|---|
| 674 |
|
|---|
| 675 |
if($this->CI->config->item('FAL_create_user_profile')) |
|---|
| 676 |
{ |
|---|
| 677 |
|
|---|
| 678 |
$data_profile['id'] = $this->CI->db->insert_id(); |
|---|
| 679 |
$this->CI->userprofile->insertUserProfile($data_profile); |
|---|
| 680 |
} |
|---|
| 681 |
|
|---|
| 682 |
return true; |
|---|
| 683 |
} |
|---|
| 684 |
} |
|---|
| 685 |
|
|---|
| 686 |
return false; |
|---|
| 687 |
} |
|---|
| 688 |
|
|---|
| 689 |
|
|---|
| 690 |
|
|---|
| 691 |
|
|---|
| 692 |
|
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 |
|
|---|
| 696 |
function forgotten_password() |
|---|
| 697 |
{ |
|---|
| 698 |
if ($this->CI->db_session) |
|---|
| 699 |
{ |
|---|
| 700 |
$email = $this->CI->input->post('email'); |
|---|
| 701 |
|
|---|
| 702 |
|
|---|
| 703 |
|
|---|
| 704 |
if (($email != false)) |
|---|
| 705 |
{ |
|---|
| 706 |
$query = $this->CI->usermodel->getUserForForgottenPassword($email); |
|---|
| 707 |
|
|---|
| 708 |
if (($query != null) && ($query->num_rows() > 0)) |
|---|
| 709 |
{ |
|---|
| 710 |
$row = $query->row(); |
|---|
| 711 |
$user_id = $row->{'id'}; |
|---|
| 712 |
$user = $row->{'user_name'}; |
|---|
| 713 |
|
|---|
| 714 |
|
|---|
| 715 |
$activation_code = $this->_generateRandomString(50, 50); |
|---|
| 716 |
|
|---|
| 717 |
|
|---|
| 718 |
$this->CI->usermodel->updateUserForForgottenPassword($user_id, $activation_code); |
|---|
| 719 |
|
|---|
| 720 |
|
|---|
| 721 |
$this->_sendForgottenPasswordEmail($user_id, $user, $email, $activation_code); |
|---|
| 722 |
|
|---|
| 723 |
return true; |
|---|
| 724 |
} |
|---|
| 725 |
} |
|---|
| 726 |
|
|---|
| 727 |
|
|---|
| 728 |
$msg = $this->CI->lang->line('FAL_forgotten_password_user_not_found_message'); |
|---|
| 729 |
flashMsg($msg); |
|---|
| 730 |
|
|---|
| 731 |
return false; |
|---|
| 732 |
} |
|---|
| 733 |
} |
|---|
| 734 |
|
|---|
| 735 |
|
|---|
| 736 |
|
|---|
| 737 |
|
|---|
| 738 |
|
|---|
| 739 |
|
|---|
| 740 |
|
|---|
| 741 |
|
|---|
| 742 |
|
|---|
| 743 |
|
|---|
| 744 |
|
|---|
| 745 |
|
|---|
| 746 |
function forgotten_password_reset($id, $activation_code) |
|---|
| 747 |
{ |
|---|
| 748 |
|
|---|
| 749 |
if (($id > 0) && ($activation_code != '')) |
|---|
| 750 |
{ |
|---|
| 751 |
|
|---|
| 752 |
|
|---|
| 753 |
|
|---|
| 754 |
|
|---|
| 755 |
|
|---|
| 756 |
$query = $this->CI->usermodel->getUserForForgottenPasswordReset($id, $activation_code); |
|---|
| 757 |
|
|---|
| 758 |
|
|---|
| 759 |
if ($query->num_rows() > 0) |
|---|
| 760 |
{ |
|---|
| 761 |
$row = $query->row(); |
|---|
| 762 |
$user_id = $row->{'id'}; |
|---|
| 763 |
$user = $row->{'user_name'}; |
|---|
| 764 |
$email = $row->{'email'}; |
|---|
| 765 |
|
|---|
| 766 |
|
|---|
| 767 |
$password = $this->_generateRandomString($this->CI->config->item('FAL_user_password_min'), $this->CI->config->item('FAL_user_password_max')); |
|---|
| 768 |
|
|---|
| 769 |
|
|---|
| 770 |
$encrypted_password = $this->_encode($password); |
|---|
| 771 |
|
|---|
| 772 |
|
|---|
| 773 |
$this->_sendForgottenPasswordResetEmail($user_id, $user, $email, $password); |
|---|
| 774 |
|
|---|
| 775 |
|
|---|
| 776 |
$this->CI->usermodel->updateUserForForgottenPasswordReset($user_id, $encrypted_password); |
|---|
| 777 |
|
|---|
| 778 |
return true; |
|---|
| 779 |
} |
|---|
| 780 |
} |
|---|
| 781 |
|
|---|
| 782 |
return false; |
|---|
| 783 |
} |
|---|
| 784 |
|
|---|
| 785 |
|
|---|
| 786 |
|
|---|
| 787 |
|
|---|
| 788 |
|
|---|
| 789 |
|
|---|
| 790 |
|
|---|
| 791 |
|
|---|
| 792 |
function _change_password() |
|---|
| 793 |
{ |
|---|
| 794 |
if ($this->CI->db_session) |
|---|
| 795 |
{ |
|---|
| 796 |
$username = $this->CI->input->post('user_name'); |
|---|
| 797 |
$old_password = $this->CI->input->post('old_password'); |
|---|
| 798 |
$new_password = $this->CI->input->post('password'); |
|---|
| 799 |
|
|---|
| 800 |
|
|---|
| 801 |
if ($username != false AND $old_password != false AND $new_password != false) |
|---|
| 802 |
{ |
|---|
| 803 |
$query = $this->CI->usermodel->getUserForLogin($username, $this->_encode($old_password)); |
|---|
| 804 |
|
|---|
| 805 |
if (($query != null) && ($query->num_rows() == 1)) |
|---|
| 806 |
{ |
|---|
| 807 |
$row = $query->row(); |
|---|
| 808 |
$user_id = $row->{'id'}; |
|---|
| 809 |
$user = $row->{'user_name'}; |
|---|
| 810 |
$email = $row->{'email'}; |
|---|
| 811 |
|
|---|
| 812 |
|
|---|
| 813 |
$password_email = $new_password; |
|---|
| 814 |
|
|---|
| 815 |
|
|---|
| 816 |
$new_password = $this->_encode($new_password); |
|---|
| 817 |
|
|---|
| 818 |
|
|---|
| 819 |
$this->CI->usermodel->updateUserForForgottenPasswordReset($user_id, $new_password); |
|---|
| 820 |
|
|---|
| 821 |
|
|---|
| 822 |
$this->_sendChangePasswordEmail($user_id, $user, $email, $password_email); |
|---|
| 823 |
|
|---|
| 824 |
return true; |
|---|
| 825 |
} |
|---|
| 826 |
} |
|---|
| 827 |
|
|---|
| 828 |
|
|---|
| 829 |
$msg = $this->CI->lang->line('FAL_change_password_failed_message'); |
|---|
| 830 |
flashMsg($msg); |
|---|
| 831 |
|
|---|
| 832 |
redirect($this->CI->config->item('FAL_changePassword_uri'), 'location'); |
|---|
| 833 |
} |
|---|
| 834 |
} |
|---|
| 835 |
|
|---|
| 836 |
|
|---|
| 837 |
|
|---|
| 838 |
|
|---|
| 839 |
|
|---|
| 840 |
|
|---|
| 841 |
|
|---|
| 842 |
|
|---|
| 843 |
|
|---|
| 844 |
function _set_logindata($userdata) |
|---|
| 845 |
{ |
|---|
| 846 |
|
|---|
| 847 |
$this->CI->usermodel->updateUserForLogin($userdata['id']); |
|---|
| 848 |
$this->CI->db_session->set_userdata($userdata); |
|---|
| 849 |
} |
|---|
| 850 |
|
|---|
| 851 |
|
|---|
| 852 |
|
|---|
| 853 |
|
|---|
| 854 |
|
|---|
| 855 |
|
|---|
| 856 |
|
|---|
| 857 |
|
|---|
| 858 |
|
|---|
| 859 |
function _unset_user($_username) |
|---|
| 860 |
{ |
|---|
| 861 |
$users = $this->CI->db_session->userdata('user_name'); |
|---|
| 862 |
|
|---|
| 863 |
if (isset($users)) |
|---|
| 864 |
{ |
|---|
| 865 |
unset($users); |
|---|
| 866 |
|
|---|
| 867 |
$this->CI->db_session->unset_userdata('id'); |
|---|
| 868 |
$this->CI->db_session->unset_userdata('user_name'); |
|---|
| 869 |
$this->CI->db_session->unset_userdata('role'); |
|---|
| 870 |
} |
|---|
| 871 |
|
|---|
| 872 |
} |
|---|
| 873 |
|
|---|
| 874 |
|
|---|
| 875 |
|
|---|
| 876 |
|
|---|
| 877 |
|
|---|
| 878 |
|
|---|
| 879 |
|
|---|
| 880 |
|
|---|
| 881 |
|
|---|
| 882 |
|
|---|
| 883 |
function cleanExpiredUserTemp() |
|---|
| 884 |
{ |
|---|
| 885 |
$expiration = $this->CI->config->item('FAL_temporary_users_expiration'); |
|---|
| 886 |
|
|---|
| 887 |
$query = $this->CI->UserTemp->getUserTempCreated(); |
|---|
| 888 |
|
|---|
| 889 |
if ($query->num_rows() > 0) |
|---|
| 890 |
{ |
|---|
| 891 |
foreach ($query->result() as $row) |
|---|
| 892 |
{ |
|---|
| 893 |
if (time()>($row->created + $expiration)) |
|---|
| 894 |
{ |
|---|
| 895 |
$this->CI->UserTemp->deleteUserAfterActivation($row->id); |
|---|
| 896 |
} |
|---|
| 897 |
} |
|---|
| 898 |
} |
|---|
| 899 |
} |
|---|
| 900 |
|
|---|
| 901 |
|
|---|
| 902 |
|
|---|
| 903 |
|
|---|
| 904 |
|
|---|
| 905 |
|
|---|
| 906 |
|
|---|
| 907 |
|
|---|
| 908 |
|
|---|
| 909 |
|
|---|
| 910 |
|
|---|
| 911 |
function getUserName() |
|---|
| 912 |
{ |
|---|
| 913 |
if ($this->CI->config->item('FAL') && $this->CI->db_session) |
|---|
| 914 |
|
|---|
| 915 |
|
|---|
| 916 |
return $this->CI->db_session->userdata('user_name'); |
|---|
| 917 |
|
|---|
| 918 |
|
|---|
| 919 |
return ''; |
|---|
| 920 |
} |
|---|
| 921 |
|
|---|
| 922 |
|
|---|
| 923 |
|
|---|
| 924 |
|
|---|
| 925 |
|
|---|
| 926 |
|
|---|
| 927 |
|
|---|
| 928 |
|
|---|
| 929 |
|
|---|
| 930 |
|
|---|
| 931 |
|
|---|
| 932 |
|
|---|
| 933 |
|
|---|
| 934 |
|
|---|
| 935 |
|
|---|
| 936 |
function getUserProperty($prop) |
|---|
| 937 |
{ |
|---|
| 938 |
if ($this->CI->config->item('FAL') && $this->CI->db_session) |
|---|
| 939 |
|
|---|
| 940 |
|
|---|
| 941 |
return $this->CI->db_session->userdata($prop); |
|---|
| 942 |
|
|---|
| 943 |
|
|---|
| 944 |
return ''; |
|---|
| 945 |
} |
|---|
| 946 |
|
|---|
| 947 |
|
|---|
| 948 |
|
|---|
| 949 |
|
|---|
| 950 |
|
|---|
| 951 |
|
|---|
| 952 |
|
|---|
| 953 |
|
|---|
| 954 |
|
|---|
| 955 |
|
|---|
| 956 |
|
|---|
| 957 |
|
|---|
| 958 |
|
|---|
| 959 |
|
|---|
| 960 |
function getUserPropertyFromId($id, $prop) |
|---|
| 961 |
{ |
|---|
| 962 |
$query = $this->CI->usermodel->getUserById($id); |
|---|
| 963 |
if ($query->num_rows() == 1) |
|---|
| 964 |
{ |
|---|
| 965 |
$row = $query->row(); |
|---|
| 966 |
if (isset($row->{$prop})) return $row->{$prop}; |
|---|
| 967 |
else return ''; |
|---|
| 968 |
} |
|---|
| 969 |
else |
|---|
| 970 |
{ |
|---|
| 971 |
$this->CI->lang->load('freakauth'); |
|---|
| 972 |
return $this->CI->lang->line('FAL_unknown_user'); |
|---|
| 973 |
} |
|---|
| 974 |
} |
|---|
| 975 |
|
|---|
| 976 |
|
|---|
| 977 |
|
|---|
| 978 |
|
|---|
| 979 |
|
|---|
| 980 |
|
|---|
| 981 |
|
|---|
| 982 |
|
|---|
| 983 |
function captcha_init($action) |
|---|
| 984 |
{ |
|---|
| 985 |
|
|---|
| 986 |
if (!$this->CI->config->item('FAL_use_captcha'.$action)) |
|---|
| 987 |
|
|---|
| 988 |
|
|---|
| 989 |
return; |
|---|
| 990 |
|
|---|
| 991 |
|
|---|
| 992 |
$this->CI->db_session->unset_userdata('FreakAuth_captcha'); |
|---|
| 993 |
|
|---|
| 994 |
|
|---|
| 995 |
|
|---|
| 996 |
list($usec, $sec) = explode(" ", microtime()); |
|---|
| 997 |
$now = ((float)$usec + (float)$sec); |
|---|
| 998 |
|
|---|
| 999 |
|
|---|
| 1000 |
$this->_deleteOldCaptcha($now); |
|---|
| 1001 |
|
|---|
| 1002 |
|
|---|
| 1003 |
$this->_generateCaptcha($now); |
|---|
| 1004 |
} |
|---|
| 1005 |
|
|---|
| 1006 |
|
|---|
| 1007 |
|
|---|
| 1008 |
|
|---|
| 1009 |
|
|---|
| 1010 |
|
|---|
| 1011 |
|
|---|
| 1012 |
|
|---|
| 1013 |
|
|---|
| 1014 |
|
|---|
| 1015 |
|
|---|
| 1016 |
|
|---|
| 1017 |
function _deleteOldCaptcha($now) |
|---|
| 1018 |
{ |
|---|
| 1019 |
list($usec, $sec) = explode(" ", microtime()); |
|---|
| 1020 |
|
|---|
| 1021 |
|
|---|
| 1022 |
$expiration=60*10; |
|---|
| 1023 |
|
|---|
| 1024 |
$current_dir = @opendir($this->CI->config->item('FAL_captcha_image_path')); |
|---|
| 1025 |
|
|---|
| 1026 |
while($filename = @readdir($current_dir)) |
|---|
| 1027 |
{ |
|---|
| 1028 |
if ($filename != "." AND $filename != ".." AND $filename != "index.html") |
|---|
| 1029 |
{ |
|---|
| 1030 |
$name = str_replace(".jpg", "", $filename); |
|---|
| 1031 |
|
|---|
| 1032 |
if (($name + $expiration) < $now) |
|---|
| 1033 |
{ |
|---|
| 1034 |
@unlink($this->CI->config->item('FAL_captcha_image_path').$filename); |
|---|
| 1035 |
} |
|---|
| 1036 |
} |
|---|
| 1037 |
} |
|---|
| 1038 |
|
|---|
| 1039 |
@closedir($current_dir); |
|---|
| 1040 |
} |
|---|
| 1041 |
|
|---|
| 1042 |
|
|---|
| 1043 |
|
|---|
| 1044 |
|
|---|
| 1045 |
|
|---|
| 1046 |
|
|---|
| 1047 |
|
|---|
| 1048 |
|
|---|
| 1049 |
function _generateCaptcha($now) |
|---|
| 1050 |
{ |
|---|
| 1051 |
|
|---|
| 1052 |
$securityCode = $this->_generateRandomString($this->CI->config->item('FAL_captcha_min'), $this->CI->config->item('FAL_captcha_max')); |
|---|
| 1053 |
|
|---|
| 1054 |
$image = $now.'.jpg'; |
|---|
| 1055 |
$this->CI->config->set_item('FAL_captcha_image', $image); |
|---|
| 1056 |
|
|---|
| 1057 |
$config['image_library'] = $this->CI->config->item('FAL_captcha_image_library'); |
|---|
| 1058 |
$config['source_image'] = $this->CI->config->item('FAL_captcha_base_image_path').$this->CI->config->item('FAL_captcha_image_base_image'); |
|---|
| 1059 |
$config['new_image'] = $this->CI->config->item('FAL_captcha_image_path').$image; |
|---|
| 1060 |
$config['wm_text'] = $securityCode; |
|---|
| 1061 |
$config['wm_type'] = 'text'; |
|---|
| 1062 |
$config['wm_font_path'] = $this->CI->config->item('FAL_captcha_image_font'); |
|---|
| 1063 |
$config['wm_font_size'] = $this->CI->config->item('FAL_captcha_image_font_size'); |
|---|
| 1064 |
$config['wm_font_color'] = $this->CI->config->item('FAL_captcha_image_font_color'); |
|---|
| 1065 |
$config['wm_vrt_alignment'] = 'top'; |
|---|
| 1066 |
$config['wm_hor_alignment'] = 'left'; |
|---|
| 1067 |
$config['wm_padding'] = '10'; |
|---|
| 1068 |
|
|---|
| 1069 |
$image =& get_instance(); |
|---|
| 1070 |
$image->load->library('image_lib'); |
|---|
| 1071 |
$image->image_lib->initialize($config); |
|---|
| 1072 |
|
|---|
| 1073 |
if ( ! $image->image_lib->watermark()) |
|---|
| 1074 |
{ |
|---|
| 1075 |
echo $image->image_lib->display_errors(); |
|---|
| 1076 |
}; |
|---|
| 1077 |
|
|---|
| 1078 |
$this->CI->db_session->set_userdata('FreakAuth_captcha', $securityCode); |
|---|
| 1079 |
return $this->CI->config->item('FAL_captcha_image'); |
|---|
| 1080 |
|
|---|
| 1081 |
|
|---|
| 1082 |
} |
|---|
| 1083 |
|
|---|
| 1084 |
|
|---|
| 1085 |
|
|---|
| 1086 |
|
|---|
| 1087 |
|
|---|
| 1088 |
|
|---|
| 1089 |
|
|---|
| 1090 |
|
|---|
| 1091 |
|
|---|
| 1092 |
|
|---|
| 1093 |
|
|---|
| 1094 |
|
|---|
| 1095 |
|
|---|
| 1096 |
function _generateRandomString() |
|---|
| 1097 |
{ |
|---|
| 1098 |
$charset = "abcdefghijklmnopqrstuvwxyz"; |
|---|
| 1099 |
if ($this->CI->config->item('FAL_captcha_upper_lower_case')) |
|---|
| 1100 |
$charset .= "ABCDEFGHIJKLMNPQRSTUVWXYZ"; |
|---|
| 1101 |
if ($this->CI->config->item('FAL_captcha_use_numbers')) |
|---|
| 1102 |
$charset .= "23456789"; |
|---|
| 1103 |
if ($this->CI->config->item('FAL_captcha_use_specials')) |
|---|
| 1104 |
$charset .= "~@#$%^*()_+-={}|]["; |
|---|
| 1105 |
|
|---|
| 1106 |
$length = mt_rand($this->CI->config->item('FAL_captcha_min'), $this->CI->config->item('FAL_captcha_max')); |
|---|
| 1107 |
if ($this->CI->config->item('FAL_captcha_min') > $this->CI->config->item('FAL_captcha_max')) |
|---|
| 1108 |
$length = mt_rand($this->CI->config->item('FAL_captcha_max'), $this->CI->config->item('FAL_captcha_min')); |
|---|
| 1109 |
|
|---|
| 1110 |
$key = ''; |
|---|
| 1111 |
for ($i = 0; $i < $length; $i++) |
|---|
| 1112 |
$key .= $charset[(mt_rand(0, (strlen($charset)-1)))]; |
|---|
| 1113 |
|
|---|
| 1114 |
return $key; |
|---|
| 1115 |
} |
|---|
| 1116 |
|
|---|
| 1117 |
|
|---|
| 1118 |
|
|---|
| 1119 |
|
|---|
| 1120 |
|
|---|
| 1121 |
|
|---|
| 1122 |
|
|---|
| 1123 |
|
|---|
| 1124 |
|
|---|
| 1125 |
|
|---|
| 1126 |
|
|---|
| 1127 |
function _sendEmail($email, $subject, $message) |
|---|
| 1128 |
{ |
|---|
| 1129 |
$tobj =& get_instance(); |
|---|
| 1130 |
$tobj->load->library('email'); |
|---|
| 1131 |
$tobj->email->clear(); |
|---|
| 1132 |
$tobj->email->from($this->CI->config->item('FAL_user_support'), $this->CI->config->item('FAL_website_name').' '.$this->CI->config->item('FAL_email_from')); |
|---|
| 1133 |
$tobj->email->to($email); |
|---|
| 1134 |
$tobj->email->subject($subject); |
|---|
| 1135 |
$tobj->email->message($message); |
|---|
| 1136 |
$tobj->email->send(); |
|---|
| 1137 |
} |
|---|
| 1138 |
|
|---|
| 1139 |
|
|---|
| 1140 |
|
|---|
| 1141 |
|
|---|
| 1142 |
|
|---|
| 1143 |
|
|---|
| 1144 |
|
|---|
| 1145 |
|
|---|
| 1146 |
|
|---|
| 1147 |
|
|---|
| 1148 |
|
|---|
| 1149 |
|
|---|
| 1150 |
function _sendActivationEmail($id, $user, $password_email, $email, $activation_code) |
|---|
| 1151 |
{ |
|---|
| 1152 |
$activation_url = site_url($this->CI->config->item('FAL_activation_uri').'/'.$id.'/'.$activation_code); |
|---|
| 1153 |
$data = array('activation_url' => $activation_url, |
|---|
| 1154 |
'user_name' => $user, |
|---|
| 1155 |
'password'=>$password_email); |
|---|
| 1156 |
|
|---|
| 1157 |
$message = $this->CI->load->view($this->CI->config->item('FAL_activation_email'), $data, true); |
|---|
| 1158 |
|
|---|
| 1159 |
$subject= '['.$this->CI->config->item('FAL_website_name').'] '.$this->CI->lang->line('FAL_activation_email_subject'); |
|---|
| 1160 |
$this->_sendEmail($email, $subject , $message); |
|---|
| 1161 |
} |
|---|
| 1162 |
|
|---|
| 1163 |
|
|---|
| 1164 |
|
|---|
| 1165 |
|
|---|
| 1166 |
|
|---|
| 1167 |
|
|---|
| 1168 |
|
|---|
| 1169 |
|
|---|
| 1170 |
|
|---|
| 1171 |
|
|---|
| 1172 |
|
|---|
| 1173 |
|
|---|
| 1174 |
|
|---|
| 1175 |
function _sendForgottenPasswordEmail($id, $user, $email, $activation_code) |
|---|
| 1176 |
{ |
|---|
| 1177 |
$activation_url = site_url($this->CI->config->item('FAL_forgottenPasswordReset_uri').'/'.$id.'/'.$activation_code); |
|---|
| 1178 |
$data = array('activation_url' => $activation_url, |
|---|
| 1179 |
'user_name' => $user); |
|---|
| 1180 |
|
|---|
| 1181 |
$message = $this->CI->load->view($this->CI->config->item('FAL_forgotten_password_email'), $data, true); |
|---|
| 1182 |
|
|---|
| 1183 |
$subject= '['.$this->CI->config->item('FAL_website_name').'] '.$this->CI->lang->line('FAL_forgotten_password_email_subject'); |
|---|
| 1184 |
|
|---|
| 1185 |
$this->_sendEmail($email, $subject, $message); |
|---|
| 1186 |
} |
|---|
| 1187 |
|
|---|
| 1188 |
|
|---|
| 1189 |
|
|---|
| 1190 |
|
|---|
| 1191 |
|
|---|
| 1192 |
|
|---|
| 1193 |
|
|---|
| 1194 |
|
|---|
| 1195 |
|
|---|
| 1196 |
|
|---|
| 1197 |
|
|---|
| 1198 |
|
|---|
| 1199 |
|
|---|
| 1200 |
function _sendForgottenPasswordResetEmail($id, $user, $email, $password) |
|---|
| 1201 |
{ |
|---|
| 1202 |
$data = array('password' => $password, |
|---|
| 1203 |
'user_name' => $user, |
|---|
| 1204 |
'change_password_link'=> site_url($this->CI->config->item('FAL_changePassword_uri')) |
|---|
| 1205 |
); |
|---|
| 1206 |
|
|---|
| 1207 |
|
|---|
| 1208 |
|
|---|
| 1209 |
$message = $this->CI->load->view($this->CI->config->item('FAL_forgotten_password_reset_email'), $data, true); |
|---|
| 1210 |
|
|---|
| 1211 |
$subject= '['.$this->CI->config->item('FAL_website_name').'] '.$this->CI->lang->line('FAL_forgotten_password_email_reset_subject'); |
|---|
| 1212 |
|
|---|
| 1213 |
$this->_sendEmail($email, $subject, $message); |
|---|
| 1214 |
} |
|---|
| 1215 |
|
|---|
| 1216 |
|
|---|
| 1217 |
|
|---|
| 1218 |
|
|---|
| 1219 |
|
|---|
| 1220 |
|
|---|
| 1221 |
|
|---|
| 1222 |
|
|---|
| 1223 |
|
|---|
| 1224 |
|
|---|
| 1225 |
|
|---|
| 1226 |
|
|---|
| 1227 |
function _sendChangePasswordEmail($id, $user, $email, $password_email) |
|---|
| 1228 |
{ |
|---|
| 1229 |
$data = array('user_name' => $user, |
|---|
| 1230 |
'password'=>$password_email); |
|---|
| 1231 |
|
|---|
| 1232 |
$message = $this->CI->load->view($this->CI->config->item('FAL_change_password_email'), $data, true); |
|---|
| 1233 |
|
|---|
| 1234 |
$subject= '['.$this->CI->config->item('FAL_website_name').'] '.$this->CI->lang->line('FAL_forgotten_password_email_reset_subject'); |
|---|
| 1235 |
$this->_sendEmail($email, $subject , $message); |
|---|
| 1236 |
} |
|---|
| 1237 |
|
|---|
| 1238 |
|
|---|
| 1239 |
|
|---|
| 1240 |
|
|---|
| 1241 |
|
|---|
| 1242 |
|
|---|
| 1243 |
|
|---|
| 1244 |
|
|---|
| 1245 |
|
|---|
| 1246 |
function getLoginForm() |
|---|
| 1247 |
{ |
|---|
| 1248 |
$values['user_name'] = $this->CI->input->post('user_name'); |
|---|
| 1249 |
$values['password'] = $this->CI->input->post('password'); |
|---|
| 1250 |
|
|---|
| 1251 |
|
|---|
| 1252 |
|
|---|
| 1253 |
return $values; |
|---|
| 1254 |
} |
|---|
| 1255 |
|
|---|
| 1256 |
|
|---|
| 1257 |
|
|---|
| 1258 |
|
|---|
| 1259 |
|
|---|
| 1260 |
|
|---|
| 1261 |
|
|---|
| 1262 |
|
|---|
| 1263 |
function getRegistrationForm() |
|---|
| 1264 |
{ |
|---|
| 1265 |
$values['user_name'] = $this->CI->input->post('user_name', TRUE); |
|---|
| 1266 |
$values['password'] = $this->CI->input->post('password'); |
|---|
| 1267 |
$values['email'] = $this->CI->input->post('email'); |
|---|
| 1268 |
if ($this->CI->config->item('FAL_use_country')) |
|---|
| 1269 |
$values['country_id'] = $this->CI->input->post('country_id'); |
|---|
| 1270 |
|
|---|
| 1271 |
|
|---|
| 1272 |
|
|---|
| 1273 |
return $values; |
|---|
| 1274 |
} |
|---|
| 1275 |
|
|---|
| 1276 |
|
|---|
| 1277 |
|
|---|
| 1278 |
|
|---|
| 1279 |
|
|---|
| 1280 |
|
|---|
| 1281 |
|
|---|
| 1282 |
|
|---|
| 1283 |
function _encode($password) |
|---|
| 1284 |
{ |
|---|
| 1285 |
$majorsalt=null; |
|---|
| 1286 |
|
|---|
| 1287 |
|
|---|
| 1288 |
if ($this->CI->config->item('encryption_key')!='') |
|---|
| 1289 |
{ |
|---|
| 1290 |
|
|---|
| 1291 |
$_password = $this->CI->config->item('encryption_key').$password; |
|---|
| 1292 |
} |
|---|
| 1293 |
else {$_password=$password;} |
|---|
| 1294 |
|
|---|
| 1295 |
|
|---|
| 1296 |
if (function_exists('str_split')) |
|---|
| 1297 |
{ |
|---|
| 1298 |
$_pass = str_split($_password); |
|---|
| 1299 |
} |
|---|
| 1300 |
|
|---|
| 1301 |
else |
|---|
| 1302 |
{ |
|---|
| 1303 |
$_pass = array(); |
|---|
| 1304 |
if (is_string($_password)) |
|---|
| 1305 |
{ |
|---|
| 1306 |
for ($i = 0; $i < strlen($_password); $i++) |
|---|
| 1307 |
{ |
|---|
| 1308 |
array_push($_pass, $_password[$i]); |
|---|
| 1309 |
} |
|---|
| 1310 |
} |
|---|
| 1311 |
} |
|---|
| 1312 |
|
|---|
| 1313 |
|
|---|
| 1314 |
foreach ($_pass as $_hashpass) |
|---|
| 1315 |
{ |
|---|
| 1316 |
$majorsalt .= md5($_hashpass); |
|---|
| 1317 |
} |
|---|
| 1318 |
|
|---|
| 1319 |
|
|---|
| 1320 |
|
|---|
| 1321 |
return $password=md5($majorsalt); |
|---|
| 1322 |
|
|---|
| 1323 |
} |
|---|
| 1324 |
|
|---|
| 1325 |
|
|---|
| 1326 |
|
|---|
| 1327 |
|
|---|
| 1328 |
|
|---|
| 1329 |
|
|---|
| 1330 |
|
|---|
| 1331 |
|
|---|
| 1332 |
|
|---|
| 1333 |
function _getUserProfile($id) |
|---|
| 1334 |
{ |
|---|
| 1335 |
|
|---|
| 1336 |
|
|---|
| 1337 |
$field_name=$this->CI->config->item('FAL_user_profile_fields_names'); |
|---|
| 1338 |
|
|---|
| 1339 |
|
|---|
| 1340 |
$field_rule=$this->CI->config->item('FAL_user_profile_fields_validation_rules'); |
|---|
| 1341 |
|
|---|
| 1342 |
|
|---|
| 1343 |
|
|---|
| 1344 |
$db_fields=$this->CI->userprofile->getTableFields(); |
|---|
| 1345 |
|
|---|
| 1346 |
|
|---|
| 1347 |
|
|---|
| 1348 |
$num_db_fields=count($db_fields) - 1; |
|---|
| 1349 |
|
|---|
| 1350 |
|
|---|
| 1351 |
if ($num_db_fields!=0) |
|---|
| 1352 |
{ |
|---|
| 1353 |
|
|---|
| 1354 |
$query=$this->CI->userprofile->getUserProfileById($id); |
|---|
| 1355 |
|
|---|
| 1356 |
if ($query->num_rows() == 1) |
|---|
| 1357 |
{ |
|---|
| 1358 |
$row = $query->row(); |
|---|
| 1359 |
|
|---|
| 1360 |
for ($i=1; $i<=$num_db_fields; $i++) |
|---|
| 1361 |
{ |
|---|
| 1362 |
$field = $db_fields[$i]; |
|---|
| 1363 |
$data[$field]=$row->$db_fields[$i]; |
|---|
| 1364 |
} |
|---|
| 1365 |
|
|---|
| 1366 |
return $data; |
|---|
| 1367 |
|
|---|
| 1368 |
} |
|---|
| 1369 |
else |
|---|
| 1370 |
{ |
|---|
| 1371 |
|
|---|
| 1372 |
|
|---|
| 1373 |
|
|---|
| 1374 |
|
|---|
| 1375 |
|
|---|
| 1376 |
|
|---|
| 1377 |
|
|---|
| 1378 |
|
|---|
| 1379 |
|
|---|
| 1380 |
} |
|---|
| 1381 |
} |
|---|
| 1382 |
else |
|---|
| 1383 |
{ |
|---|
| 1384 |
return false; |
|---|
| 1385 |
} |
|---|
| 1386 |
|
|---|
| 1387 |
} |
|---|
| 1388 |
|
|---|
| 1389 |
|
|---|
| 1390 |
|
|---|
| 1391 |
|
|---|
| 1392 |
|
|---|
| 1393 |
|
|---|
| 1394 |
|
|---|
| 1395 |
|
|---|
| 1396 |
|
|---|
| 1397 |
function _buildUserProfileFieldsRules() |
|---|
| 1398 |
{ |
|---|
| 1399 |
|
|---|
| 1400 |
$field_name=$this->CI->config->item('FAL_user_profile_fields_names'); |
|---|
| 1401 |
|
|---|
| 1402 |
|
|---|
| 1403 |
$field_rule=$this->CI->config->item('FAL_user_profile_fields_validation_rules'); |
|---|
| 1404 |
|
|---|
| 1405 |
|
|---|
| 1406 |
|
|---|
| 1407 |
$db_fields=$this->CI->userprofile->getTableFields(); |
|---|
| 1408 |
|
|---|
| 1409 |
|
|---|
| 1410 |
|
|---|
| 1411 |
$num_db_fields=count($db_fields) - 1; |
|---|
| 1412 |
|
|---|
| 1413 |
|
|---|
| 1414 |
|
|---|
| 1415 |
for ($i=1; $i<=$num_db_fields; $i++) |
|---|
| 1416 |
{ |
|---|
| 1417 |
$field = $db_fields[$i]; |
|---|
| 1418 |
|
|---|
| 1419 |
|
|---|
| 1420 |
|
|---|
| 1421 |
|
|---|
| 1422 |
|
|---|
| 1423 |
array_key_exists($field, $field_rule) ? $data['rules'][$field] = $field_rule[$field] : ''; |
|---|
| 1424 |
|
|---|
| 1425 |
|
|---|
| 1426 |
|
|---|
| 1427 |
|
|---|
| 1428 |
array_key_exists($field, $field_name) ? $data['fields'][$field] = $field_name[$field] : $data['fields'][$field] = $field; |
|---|
| 1429 |
} |
|---|
| 1430 |
|
|---|
| 1431 |
|
|---|
| 1432 |
return $data; |
|---|
| 1433 |
} |
|---|
| 1434 |
|
|---|
| 1435 |
} |
|---|