public function edit() { $process = Param::get('process', 'edit'); $user = new User(); switch ($process) { case self::EDIT_ACCOUNT: $user->id = get_authenticated_user_id($_SESSION['userid']); $user->fname = Param::get('firstname'); $user->lname = Param::get('lastname'); $user->new_username = Param::get('username'); $user->new_email = Param::get('email'); try { $user->updateAccount(); $_SESSION['username'] = $user->new_username; $user->editSuccess = true; } catch (ValidationException $e) { } break; case self::EDIT_PROFILE: $user->id = get_authenticated_user_id($_SESSION['userid']); $user->company = Param::get('company'); $user->division = Param::get('division'); $user->specialization = Param::get('specialization'); try { $user->updateProfile(); $user->editSuccess = true; } catch (ValidationException $e) { } break; case self::EDIT_PASSWORD: $user->id = get_authenticated_user_id($_SESSION['userid']); //set username and old password to password //property to authenticate user $user->username = $_SESSION['username']; $user->password = htmlentities(Param::get('oldPassword')); if (!$user->isRegistered()) { $user->validation_errors['notAuthorized']['authenticate'] = true; break; } //Unset username so it won't be included in validation unset($user->username); $user->password = htmlentities(Param::get('password')); $user->confirmpassword = htmlentities(Param::get('confirmPassword')); try { $user->updatePassword(); $user->editSuccess = true; } catch (ValidationException $e) { } break; case self::EDIT_PICTURE: $user = new User(); $target_directory = "bootstrap/img/users/" . $_SESSION['username']; try { if (file_exists($file_tmp = $_FILES['picture']['tmp_name'])) { $finfo = new finfo(FILEINFO_MIME_TYPE); if (false === ($file_extension = array_search($finfo->file($_FILES['picture']['tmp_name']), $this->mime_types, true))) { throw new PictureFormatException("Invalid file format."); } $user_profile = glob("bootstrap/img/users/" . $_SESSION['username'] . ".*"); if ($user_profile) { foreach ($user_profile as $picture) { exec("rm {$picture}"); } } if (!move_uploaded_file($_FILES['picture']['tmp_name'], $target_directory . "." . $file_extension)) { throw new FileNotFound("File not found."); } } else { throw new FileNotFound('File not found.'); } $user->editSuccess = true; } catch (FileNotFound $e) { $_SESSION['upload_error'] = true; } catch (PictureFormatException $e) { $_SESSION['upload_error'] = true; } break; case self::EDIT_PAGE: $user->id = $_SESSION['userid']; break; } $user->getProfile(); $this->set(get_defined_vars()); }
<?php require_once 'models/User.php'; if (!empty($_POST['nickname'])) { $user = new User($_POST['nickname']); $updateResult = $user->updateProfile($_POST['newPassword'], $_POST['confirmNewPassword'], $_POST['newMail'], $_POST['newPhone'], $_POST['newFirstname'], $_POST['newLastname']); if (gettype($updateResult) === "string") { $result = ["success" => false, "error" => $updateResult]; } else { $result = ["success" => true]; } } else { $result = ["success" => false, "error" => "Empty nickname"]; } echo json_encode($result);
function updateProfile() { include_once "../model/User.php"; $user = new User(); $newcommunity = $_REQUEST['newcommunity']; $newphone = $_REQUEST['newphone']; $newemail = $_REQUEST['newemail']; if (!$user->updateProfile($newcommunity, $newphone, $newemail)) { echo '{"result": 0, "message": "Update was unsuccessful"}'; return; } echo '{"result": 1, "message": "Update was successful"}'; return; }
$user = new User(); switch ($action) { case 'signup': App::setJSONResponse($user->signup($request['fname'], $request['lname'], $request['age'], $request['address'], $request['prof'], $request['profession'], $request['email'], $request['phone'], $request['countryid'])); break; case 'presignup': App::setJSONResponse($user->presignup($request['email'])); break; case 'askquestion': App::setJSONResponse($user->askquestion($request['categoryid'], $request['deviceid'], $request['question'])); break; case 'updatedeviceid': App::setJSONResponse($user->updatedeviceid($request['device'], $request['phone'])); break; case 'update': App::setJSONResponse($user->updateProfile($request['authkey'], $request['fname'], $request['lname'], $request['email'], $request['photo'], $request['deviceid'], $request['allphones'])); break; case 'joincategory': App::setJSONResponse($user->joincategory($request['phone'], $request['category'])); break; case 'getarticle': App::setJSONResponse($user->getarticle($request['articleid'])); break; case 'getdefaultarticle': App::setJSONResponse($user->getdefaultarticle()); break; case 'sendsms': App::setJSONResponse($user->sendingSms($request['sender'], $request['phone'], $request['smsmessage'])); break; default: App::setJSONResponse(array('Status' => App::getActionResponse('Unknown')));
public function profile() { $user_sess = $this->session->userdata('user'); if ($this->input->post('user-id') != $user_sess['user_id']) { $this->load->view('access_denied'); } $this->load->library('form_validation'); $user = new User($this->input->post('user-id')); $this->_viewData['userProfile'] = $user->getProfile(); # check if updating password and add to validation process if ($this->input->post('user-oldpassword') || $this->input->post('user-password1') || $this->input->post('user-password2')) { $this->form_validation->set_rules('user-oldpassword', 'Old Password', 'callback_validate_oldpassword'); $this->form_validation->set_rules('user-password2', 'Confirm Password', 'required'); $this->form_validation->set_rules('user-password1', 'Password', 'required|min_length[6]|matches[user-password2]'); } if ($this->form_validation->run() == false) { $this->_backToForm(); } else { $user = new User($this->input->post('user-id')); $profile = $user->getProfile(); $data = array(); if ($profile['firstname'] != $this->input->post('user-firstname')) { $data['firstname'] = $this->input->post('user-firstname'); } if ($profile['lastname'] != $this->input->post('user-lastname')) { $data['lastname'] = $this->input->post('user-lastname'); } if ($profile['email'] != $this->input->post('user-email')) { $data['email'] = $this->input->post('user-email'); } if ($this->input->post('user-password1')) { $data['password'] = md5($this->input->post('user-password1') . SALT); } if (empty($data)) { $this->_errors['update'] = 'Are you sure you made changes coz I didn\'t see any. Nothing updated.'; $this->_backToForm(); } else { //var_dump($data);die(); if ($user->updateProfile($data, $this->input->post('user-id'))) { if (array_key_exists('password', $data) || array_key_exists('usergroup', $data) || array_key_exists('email', $data)) { $user->logout(); $this->load->view('user_logout_feedback'); } else { $this->session->set_userdata(array('status' => 'success')); redirect('Admin/user_profile', 'refresh'); } } else { $this->_errors = $user->errors; $this->_backToForm(); } } } }