updateUser() public method

modify user's information
public updateUser ( $token, $alias = null, $password = null, $avatar = null )
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // update the user information
     $this->_userInfo->setEmail(Textfilter::filterAllHTML($this->_request->getValue("userEmail")));
     if ($this->_userPassword != "") {
         $this->_userInfo->setPassword($this->_userPassword);
     }
     $this->_userInfo->setAboutMyself(Textfilter::filterAllHTML($this->_request->getValue("userAbout")));
     $this->_userInfo->setFullName(Textfilter::filterAllHTML($this->_request->getValue("userFullName")));
     $this->_userInfo->setPictureId($this->_request->getValue("userPictureId"));
     $this->_userInfo->setProperties($this->_request->getValue("properties"));
     $this->notifyEvent(EVENT_PRE_USER_UPDATE, array("user" => &$this->_userInfo));
     $this->_session->setValue("userInfo", $this->_userInfo);
     $this->saveSession();
     // update the user information
     $this->_view = new AdminUserProfileView($this->_blogInfo, $this->_userInfo);
     $users = new Users();
     if (!$users->updateUser($this->_userInfo)) {
         $this->_view->setErrorMessage($this->_locale->tr("error_updating_user_settings"));
     } else {
         $this->_view->setSuccessMessage($this->_locale->pr("user_settings_updated_ok", $this->_userInfo->getUsername()));
         // if everything fine, also say so...
         $this->notifyEvent(EVENT_POST_USER_UPDATE, array("user" => &$this->_userInfo));
     }
     $this->setCommonData();
     return true;
 }
 function perform()
 {
     $this->_userNameHash = $this->_request->getValue("b");
     $this->_requestHash = $this->_request->getValue("a");
     $this->_newPassword = $this->_request->getValue("newPassword");
     $this->_retypeNewPassword = $this->_request->getValue("retypePassword");
     $this->_userId = $this->_request->getValue("userId");
     // check if the passwords are correct and are the same
     if ($this->_newPassword != $this->_retypeNewPassword) {
         $this->_view = new SummaryView("changepassword");
         $this->_view->setErrorMessage($this->_locale->tr("error_passwords_do_not_match"));
         $this->setCommonData(true);
         return false;
     }
     $userInfo = SummaryTools::verifyRequest($this->_userNameHash, $this->_requestHash);
     if (!$userInfo) {
         $this->_view = new SummaryView("summaryerror");
         $this->_view->setErrorMessage($this->_locale->tr("error_incorrect_request"));
         $this->setCommonData(true);
         return false;
     }
     // so if everything went fine, we can *FINALLY* change the password!
     $users = new Users();
     $userInfo->setPassword($this->_newPassword);
     $users->updateUser($userInfo);
     $this->_view = new SummaryView("message");
     $this->_view->setSuccessMessage($this->_locale->tr("password_updated_ok"));
     return true;
 }
 function perform()
 {
     $this->username = $this->_request->getValue("username");
     $this->activeCode = $this->_request->getValue("activeCode");
     $users = new Users();
     $userInfo = $users->getUserInfoFromUsername($this->username);
     if (!$userInfo) {
         $this->_view = new SummaryView("summaryerror");
         $this->_view->setErrorMessage($this->_locale->tr("error_invalid_user"));
         return false;
     }
     $activeCode = $userInfo->getValue("activeCode");
     if ($activeCode != $this->activeCode) {
         $this->_view = new SummaryView("summaryerror", $this->_locale->tr("error_invalid_activation_code"));
         return false;
     }
     // active user
     $userInfo->setStatus(USER_STATUS_ACTIVE);
     $users->updateUser($userInfo);
     // also active the blog that user owned
     // FIXME: how about other blogs that this user take part in?
     $blogId = $users->getUserBlogId($this->username);
     $blogs = new Blogs();
     $blog = $blogs->getBlogInfo($blogId);
     $blog->setStatus(BLOG_STATUS_ACTIVE);
     $blogs->updateBlog($blogId, $blog);
     $blogUrl = $blog->getBlogRequestGenerator();
     // create the message that we're going to show
     $message = "<p>" . $this->_locale->tr("blog_activated_ok") . "</p><p>" . $this->_locale->pr("register_blog_link", $blog->getBlog(), $blogUrl->blogLink()) . "</p><p>" . $this->_locale->tr("register_blog_admin_link") . "</p>";
     $this->_view = new SummaryMessageView($message);
     $this->setCommonData();
     return true;
 }
 /**
  * The default action - show the registration form
  */
 public function adminAction()
 {
     $this->authenticate();
     // check if admin
     $identity = Zend_Auth::getInstance()->getIdentity();
     if ($identity['role'] != 'admin') {
         $this->_helper->getHelper('Redirector')->goto('view', 'portal');
     }
     if ($this->getRequest()->isPost()) {
         // submitting form
         $data = $this->_request->getParams();
         // update the user
         try {
             $this->users->updateUser($data);
         } catch (Exception $e) {
             $this->view->message = $e->getMessage();
         }
     }
     // show form
     $this->view->roles = UserRow::getRoles();
 }
Example #5
0
 /**
  *
  * function: register
  * Register a new user
  * @access public
  * @param string $username
  * @param string $password
  * @param boolean $sticky (optional)
  * @return [boolean,User]
  */
 public function register($username, $password, $info = false)
 {
     $sql = 'INSERT INTO ' . $this->table . ' (username,password) VALUES (?,?);';
     $userId = $this->insert($sql, array($username, $this->bcrypt->hash(md5($password))));
     if (empty($userId)) {
         return false;
     } else {
         if (!empty($info)) {
             Users::updateUser($info, $userId);
         }
         Session::setUser($userId);
         if (!empty($sticky)) {
             Cookie::setCookie('user', $userId);
         }
         return $userId;
     }
 }
 function perform()
 {
     // get the data
     $this->_userId = $this->_request->getValue("userId");
     $this->_userPassword = trim(Textfilter::filterAllHTML($this->_request->getValue("userProfilePassword")));
     $this->_userEmail = Textfilter::filterAllHTML($this->_request->getValue("userEmail"));
     $this->_userAbout = Textfilter::filterAllHTML($this->_request->getValue("userAbout"));
     $this->_userFullName = Textfilter::filterAllHTML($this->_request->getValue("userFullName"));
     $this->_adminPrivs = $this->_request->getValue("userIsSiteAdmin");
     $this->_userProperties = $this->_request->getValue("properties");
     $this->_userStatus = $this->_request->getValue("userStatus");
     // load the user settings
     $users = new Users();
     $user = $users->getUserInfoFromId($this->_userId);
     // if no info could be fetched, shown an error and quit
     if (!$user) {
         $this->_view = new AdminSiteUsersListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_invalid_user"));
         $this->setCommonData();
         return false;
     }
     // update the user settings
     $user->setEmail($this->_userEmail);
     $user->setAboutMyself($this->_userAbout);
     $user->setSiteAdmin($this->_adminPrivs);
     $user->setFullName($this->_userFullName);
     $user->setProperties($this->_userProperties);
     $user->setStatus($this->_userStatus);
     if ($this->_userPassword != "") {
         $user->setPassword($this->_userPassword);
     }
     $this->notifyEvent(EVENT_PRE_USER_UPDATE, array("user" => &$user));
     // and now update them
     if (!$users->updateUser($user)) {
         $this->_view = new AdminSiteUsersListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_updating_user"));
         $this->setCommonData();
         return false;
     }
     // the post-update event... if needed
     $this->notifyEvent(EVENT_POST_USER_UPDATE, array("user" => &$user));
     $this->_view = new AdminSiteUsersListView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->pr("user_updated_ok", $user->getUsername()));
     $this->setCommonData();
     return true;
 }
Example #7
0
 /**
  * Edit a users
  */
 public function editAction()
 {
     $usersModel = new Users();
     $form = $this->_getForm(false);
     $user = $usersModel->getUser($this->_getParam('userId'));
     $form->setDefaults($user);
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         $data = $form->getValues();
         if ($usersModel->isUserNameInUse($data['user_name'], $user['user_id'])) {
             $form->getElement('user_name')->addValidator('customMessages', false, array('Username is already in use'));
         }
         if ($usersModel->isEmailInUse($data['user_email'], $user['user_id'])) {
             $form->getElement('user_email')->addValidator('customMessages', false, array('E-Mail is already in use'));
         }
         if ($form->isValid($_POST)) {
             $password = !empty($data['user_password']) ? $data['user_password'] : null;
             $usersModel->updateUser($user['user_id'], $data['user_name'], $data['user_email'], $data['user_role'], $password);
             $this->_helper->getHelper('Redirector')->gotoRouteAndExit(array(), 'users-index');
         }
     }
     $this->view->form = $form;
     $this->view->users = $usersModel->getUsers();
 }
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    if ($success) {
        if (isset($_SESSION['upload'])) {
            $_SESSION['upload'] = array_merge($_SESSION['upload'], $loader->getNameList());
        } else {
            $_SESSION['upload'] = $loader->getNameList();
        }
        header("Location: review.php");
        die;
    }
}
if (isset($validUpdate)) {
    $dbUsers = new Users($conn);
    $dbUsers->updateUser($_SESSION['userID'], $_SESSION['first_name'], $_SESSION['last_name'], $email, $username, $password);
    $_SESSION['username'] = $username;
    $_SESSION['user_email'] = $email;
}
//Gets all images user can delete.
//Replace with database
$dbImages = new Images($conn);
$filenames = $dbImages->imageList($_SESSION['userID']);
if (isset($_POST['delete'])) {
    //delete Code (rember to check if user has permission to delete image)
}
include './includes/title.php';
?>
<!DOCTYPE html>
<?php 
require "./includes/head.php";
Example #9
0
include "../models/Views.php";
include "../helpers/db.php";
//must be above the Post.php - order of operation
include "../models/Users.php";
$myview = new Views();
$users = new Users();
?>
<!--<link href="/day4/css/site.css" rel="stylesheet" />--> <!--dirrect path - can use this due to the ../ paths-->
<?php 
if (!empty($_GET["action"])) {
    if ($_GET["action"] == "updateUser") {
        $data = $users->readUser($_GET["userId"]);
        $myview->getView("../views/formUpdate.php", $data);
    } elseif ($_GET["action"] == "changeUser") {
        $users->updateUser($_POST["userName"], $_POST["password"], $_POST["email"], $_POST["userId"]);
        $data = $users->readUsers();
        $myview->getView("../views/body.php", $data);
    } elseif ($_GET["action"] == "deleteUser") {
        $users->deleteUser($_GET["userId"]);
        $data = $users->readUsers();
        $myview->getView("../views/body.php", $data);
    } elseif ($_GET["action"] == "createUser") {
        $users->createUser($_POST["userName"], $_POST["password"], $_POST["email"]);
        $data = $users->readUsers();
        $myview->getView("../views/body.php", $data);
    }
} elseif (empty($_GET["userId"])) {
    $data = $users->readUsers();
    $myview->getView("../views/body.php", $data);
}
Example #10
0
<?php

include_once 'users.php';
$edit = new Users();
if (!empty($_POST)) {
    $edit_name = $_POST['edit_name'];
    $edit_address = $_POST['edit_address'];
    if ($edit->updateUser($_GET['id'], $edit_name, $edit_address)) {
        header("Location: manage_veiw.php");
    } else {
        echo 'Error';
    }
}
?>
<html>
<head>
    <meta charset="utf-8">
</head>
<body>
<form method="post" action="edit_user.php?<?php 
echo $_SERVER['QUERY_STRING'];
?>
">

    <h2>Edit user</h2>
    <?php 
foreach ($edit->getUser($_GET['id']) as $value) {
    echo "<input type=\"text\" name=\"edit_name\" value='{$value['1']}'><br >";
    echo "<input type=\"text\" name=\"edit_address\" value='{$value['2']}'><br >";
}
?>
Example #11
0
<?php

session_start();
?>
<!doctype html>
<?php 
if (isset($_POST['update'])) {
    $firstname = trim($_POST['firstname']);
    $lastname = trim($_POST['lastname']);
    $email = trim($_POST['email']);
    $password = trim($_POST['password']);
    require_once 'connection.php';
    require_once 'Users.php';
    $dbUsers = new Users($conn);
    print_r($_POST);
    $status = $dbUsers->updateUser($_SESSION['ID'], $firstname, $lastname, $email, $_SESSION['registername'], $password);
    if ($status) {
        $success = "Your account has been updated";
    } else {
        $errors[] = "Update failure";
    }
}
?>
<html class="no-js" lang="en">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>Picture Libary</title>
    <link rel="stylesheet" href="http://dhbhdrzi4tiry.cloudfront.net/cdn/sites/foundation.min.css">
    <link rel="stylesheet" href="styles.css">
    <?php 
Example #12
0
 /**
  * funkce updatne uzivatele
  * @param int $user_id
  * @param object $data
  * @param bool $verification optional
  * @return array
  */
 public static function updateUser($user_id, $data, $verification = false)
 {
     try {
         return Users::updateUser($user_id, $data, $verification = false);
     } catch (Exception $e) {
         throw new RPCFault($e->getMessage(), $e->getCode(), $e->getCode());
     }
 }
 /**
  * send confirm email to user.
  * user will active his/her account according to this email
  */
 function sendConfirmEmail()
 {
     $activeCode = $this->generateActiveCode();
     // store the active code to the backend db in the properties field of user table
     $users = new Users();
     $userInfo = $users->getUserInfoFromUsername($this->userName);
     $userInfo->setProperties(array("activeCode" => $activeCode));
     $users->updateUser($userInfo);
     $message = new ConfirmEmailMessage();
     $message->setFrom($this->_config->getValue("post_notification_source_address"));
     $message->addTo($this->userEmail);
     $message->setSubject("pLog user registration confirmation for: " . $this->userName);
     $message->setUsername($this->userName);
     $message->setActiveCode($activeCode);
     // create active Link
     $base_url = $this->_config->getValue("base_url");
     $message->setActiveLink($base_url . "/summary.php?op=activeAccount&username="******"&activeCode=" . $activeCode);
     $message->createBody();
     $service = new EmailService();
     $service->sendMessage($message);
 }
Example #14
0
            $is_admin = 1;
        } else {
            $is_admin = 0;
        }
        $user->saveData($_POST['reg_login'], $_POST['email_addr'], $_POST['reg_password'], $is_admin, $_POST['name'], $_POST['surname'], $_POST['address'], $_POST['mob_phone']);
        header("Location: " . PATHSITE . "/admin-users");
        break;
    case "register":
        $user = new Users();
        $user->saveData($_POST['reg_login'], $_POST['email_addr'], $_POST['reg_password'], 0, $_POST['name'], $_POST['surname'], $_POST['address'], $_POST['mob_phone']);
        header("Location: " . PATHSITE);
        break;
    case "remove":
        $good = new Users();
        $good->deleteData("users", $_POST['id_user']);
        header("Location: " . PATHSITE . "/admin-users");
        break;
    case "update":
        if ($_POST['reg_password'] == "") {
            //если пароль пуст, то не меняем его
            $pass = $_POST['md5_old_password'];
        } else {
            $pass = md5($_POST['reg_password']);
        }
        $user = new Users();
        $user->updateUser($_POST['id_user'], $_POST['reg_login'], $_POST['email_addr'], $pass, $_POST['is_admin'], $_POST['name'], $_POST['surname'], $_POST['address'], $_POST['mob_phone']);
        header("Location: " . $_SERVER['HTTP_REFERER']);
        break;
    default:
        break;
}