function forgot_password() { # Get the passed details into the url data array if any $urldata = $this->uri->uri_to_assoc(3, array('i')); # Pick all assigned data $data = assign_to_data($urldata); if ($this->input->post('sendnewpass')) { $required_fields = array('youremail*EMAILFORMAT'); $_POST = clean_form_data($_POST); $validation_results = validate_form('', $_POST, $required_fields); #Only proceed if the validation for required fields passes if ($validation_results['bool']) { #Check if a user with the specified email exists $userdata = $this->Query_reader->get_row_as_array('get_user_by_email_ignore_status', array('emailaddress' => $_POST['youremail'])); #Active user who just forgot their password if (!empty($userdata) && $userdata['isactive'] == 'Y') { $_POST['newpass'] = generate_new_password(); $pass_result = $this->db->query($this->Query_reader->get_query_by_code('update_user_password', array('emailaddress' => $_POST['youremail'], 'newpass' => sha1($_POST['newpass'])))); $flag_result = $this->db->query($this->Query_reader->get_query_by_code('update_user_changedpassword_flag', array('emailaddress' => $_POST['youremail'], 'flagvalue' => 'N'))); if (get_decision(array($pass_result, $flag_result))) { $send_result = $this->sysemail->email_form_data(array('fromemail' => SITE_ADMIN_MAIL), array_merge($userdata, $_POST, get_confirmation_messages($this, array('emailaddress' => $_POST['youremail'], 'newpass' => $_POST['newpass'], 'firstname' => $userdata['firstname']), 'changed_password_notify'))); if ($send_result) { $data['msg'] = "Your new password has been sent to your email address."; $data['issuccess'] = 'Y'; } } if (empty($send_result) || !empty($send_result) && !$send_result) { $data['msg'] = "ERROR: A new password could not be generated. <a href='javascript:void(0)'>Click here</a> to report this error."; } } else { if (!empty($userdata) && $userdata['isactive'] == 'N' && $userdata['forcedclose'] == 'Y') { $data['msg'] = "WARNING: Your account was previously deactivated due to activities contrary <BR>to our terms of use.<BR><BR>Please <a href='javascript:void(0)'>contact us</a> if you want to <BR>reactivate your account."; } else { if (!empty($userdata) && $userdata['isactive'] == 'N' && $userdata['forcedclose'] == 'N') { $_POST['newpass'] = generate_new_password(); $reactivate_result = $this->db->query($this->Query_reader->get_query_by_code('reactivate_old_user', array('emailaddress' => $_POST['youremail'], 'password' => sha1($_POST['newpass']), 'enddate' => date('Y-m-d', mktime(0, 0, 0, date("m"), 1, date("y") + 2))))); $flag_result = $this->db->query($this->Query_reader->get_query_by_code('update_user_changedpassword_flag', array('emailaddress' => $_POST['youremail'], 'flagvalue' => 'N'))); if (get_decision(array($reactivate_result, $flag_result))) { $send_result = $this->sysemail->email_form_data(array('fromemail' => SITE_ADMIN_MAIL), array_merge($userdata, $_POST, get_confirmation_messages($this, array('emailaddress' => $_POST['youremail'], 'newpass' => $_POST['newpass'], 'firstname' => $userdata['firstname']), 'changed_password_notify'))); if ($send_result) { $data['msg'] = "Your new password has been sent to your email address."; $data['issuccess'] = 'Y'; } } if (empty($send_result) || !empty($send_result) && !$send_result) { $data['msg'] = "ERROR: A new password could not be generated. <a href='javascript:void(0)'>Click here</a> to report this error."; } } } } } if (empty($data['msg'])) { $data['msg'] = "WARNING: The highlighted fields are required."; } $data['requiredfields'] = $validation_results['requiredfields']; $data['formdata'] = $_POST; } $data = add_msg_if_any($this, $data); $this->load->view('account/forgot_password', $data); }
function update_user_location() { # Get the passed details into the url data array if any $urldata = $this->uri->uri_to_assoc(3, array('m', 'i', 'd')); # Pick all assigned data $data = assign_to_data($urldata); #Get default location if none is given if (empty($_POST)) { $data['default_location'] = $this->user1->get_user_location(); $this->session->set_userdata('returnurl', base_url() . 'admin/load_dashboard'); } if ($this->input->post('updatelocation')) { $required_fields = array('city', 'state', 'zipcode', 'country', 'emailaddress*EMAILFORMAT', 'iagree'); $_POST = clean_form_data($_POST); if (empty($_POST['iagree'])) { $_POST['iagree'] = ''; } $validation_results = validate_form('', $_POST, $required_fields); if ($validation_results['bool']) { if ($this->session->userdata('emailaddress') || !empty($_POST['emailaddress'])) { $emailaddress = $this->session->userdata('emailaddress') ? $this->session->userdata('emailaddress') : $_POST['emailaddress']; $userdetails = $this->Query_reader->get_row_as_array('get_user_by_email_ignore_status', array('emailaddress' => $emailaddress)); } #Get the current location of the user $location = $this->user1->get_ip_location($this->input->ip_address()); #Just update the user location with a custom location if the account exists if ($this->session->userdata('emailaddress') && !empty($userdetails)) { $location_result = $this->db->query($this->Query_reader->get_query_by_code('save_user_location', array('useremail' => $_POST['emailaddress'], 'country' => $_POST['country'], 'region' => $_POST['state'], 'city' => $_POST['city'], 'zipcode' => $_POST['zipcode'], 'isp' => $location['isp'], 'latitude' => $location['latitude'], 'longitude' => $location['longitude']))); } else { if (!empty($userdetails)) { $data['msg'] = "WARNING: An account with the provided emailaddress already exists. <BR><BR>Please first login and then update this account owner's location."; } else { $_POST['newpass'] = generate_new_password(); $result = $this->db->query($this->Query_reader->get_query_by_code('add_user_data', array('firstname' => '', 'lastname' => '', 'username' => $_POST['emailaddress'], 'password' => sha1($_POST['newpass']), 'emailaddress' => $_POST['emailaddress'], 'telephone' => '', 'enddate' => date('Y-m-d', mktime(0, 0, 0, date("m"), 1, date("y") + 2))))); $location_result = $this->db->query($this->Query_reader->get_query_by_code('save_user_location', array('useremail' => $_POST['emailaddress'], 'country' => $_POST['country'], 'zipcode' => $_POST['zipcode'], 'city' => $_POST['city'], 'region' => $_POST['state'], 'isp' => $location['isp'], 'latitude' => $location['latitude'], 'longitude' => $location['longitude']))); #Notify user about creation of their account and new password if ($result && $location_result) { $_POST['step1email'] = $_POST['emailaddress']; $send_result = $this->sysemail->email_form_data(array('fromemail' => SITE_ADMIN_MAIL), array_merge($_POST, get_confirmation_messages($this, $_POST, 'registration_confirm'))); } } } #Check if the location was created if (!empty($result) && $result && $location_result) { $data['msg'] = "Your location has been updated.<BR><BR>In addition, an account with your emailaddress has been created. Login using the <BR>password sent to your email address."; $data['area'] = "show_close_btn"; #login the new user $userdata = $this->Query_reader->get_row_as_array('get_user_by_email', array('emailaddress' => $_POST['emailaddress'], 'isactive' => 'Y')); $userdata['userid'] = $userdata['id']; $this->user1->populate_user_details(array($userdata)); $this->Users->create_new_trust_record(array('useremail' => $_POST['emailaddress'])); #Update the location tracker string $this->session->set_userdata('resetlocation', 'Y'); } else { if (!empty($location_result) && $location_result) { $data['msg'] = "Your location has been updated."; $data['area'] = "show_close_btn"; #Update the location tracker string #$this->session->set_userdata('location_string', get_custom_location($this)); $this->session->set_userdata('resetlocation', 'Y'); } else { if (empty($data['msg'])) { $data['msg'] = "ERROR: Your location could not be updated. Please contact us about this issue."; } } } } else { $data['msg'] = "WARNING: The highlighted fields are required."; } $data['requiredfields'] = $validation_results['requiredfields']; $data['formdata'] = $_POST; } $data = add_msg_if_any($this, $data); $this->load->view('page/update_location', $data); }