Example #1
0
function _ops_update()
{
    require_login();
    $msg = '';
    $uid = max(0, intval($_POST['uid']));
    $user = new User();
    if ($uid) {
        $user->retrieve($uid);
        $user->merge($_POST);
        if (!$user->exists()) {
            $msg = 'User not found!';
        } else {
            if ($user->update()) {
                $msg = 'User updated!';
            } else {
                $msg = 'User update failed!';
            }
        }
    } else {
        $user->merge($_POST);
        if ($user->create()) {
            $msg = 'User inserted!';
        } else {
            $msg = 'User insert failed!';
        }
    }
    redirect('users/manage', $msg);
}
function _ops_update()
{
    loginRequireMgmt();
    if (!loginCheckPermission(USER::MGMT_USER)) {
        redirect("errors/401");
    }
    $msg = '';
    $OID = max(0, intval($_POST['OID']));
    $CID = max(0, intval($_POST['CID']));
    if ($_POST['password'] != $_POST['confirm']) {
        redirect("mgmt_user/edit", "password not equal to confirm");
    }
    $object = new User();
    if ($OID) {
        $object->retrieve($OID, $CID);
        $object->merge($_POST);
        if ($_POST['password'] != "") {
            $object->setPassword($_POST['password']);
        }
        if (!$object->exists()) {
            $msg = 'User not found!';
        } else {
            if ($object->update()) {
                $msg = 'User updated!';
            } else {
                $msg = 'User update failed!';
            }
        }
    } else {
        $object->merge($_POST);
        if ($_POST['password'] != "") {
            $object->setPassword($_POST['password']);
        }
        if ($object->create()) {
            $msg = 'User inserted!';
        } else {
            $msg = 'User insert failed!';
        }
    }
    redirect('mgmt_user/manage', $msg);
}
Example #3
0
File: User.php Project: kizz66/meat
 public function edit()
 {
     if (!empty($this->post['Save'])) {
         if ($this->show->itemID) {
             $user = new User($this->show->itemID);
             if (!empty($this->post['Password']) && !empty($this->post['ConfirmPassword']) && $this->post['Password'] == $this->post['ConfirmPassword']) {
                 $this->post['Password'] = Auth::getInstance()->hash($this->post['Password']);
             } else {
                 $this->post['Password'] = $user['Password'];
             }
             $user->merge($this->post);
             if ($this->show->itemID != 1) {
                 $itemID = $user->save();
             } else {
                 $itemID = 1;
             }
         } else {
             $user = new User();
             $user->get(clone $this->post);
             $itemID = Auth::getInstance()->createUser($user);
         }
         if ($itemID) {
             redirect(BASE_PATH . 'admin/user/');
         }
     }
     if ($this->show->itemID) {
         $this->show->editUser = new User($this->show->itemID);
         if (!$this->show->editUser->loaded()) {
             $this->show->itemID = 0;
         }
         $this->show->breadcrumbs[] = array('url' => BASE_PATH . 'admin/user/' . $this->show->itemID, 'title' => $this->show->editUser['Login']);
     } else {
         $this->show->editUser = new User();
         $this->show->breadcrumbs[] = array('url' => BASE_PATH . 'admin/user/' . $this->show->itemID, 'title' => 'Создание');
     }
     if (!empty($this->post['Save'])) {
         $this->show->editUser->merge($this->post);
     }
 }
Example #4
0
File: Auth.php Project: kizz66/meat
 /**
  * Creates new user
  *
  * @param array $user_data user data to add
  * @param string $second name of second unique field to verify
  * @return  boolean
  */
 public function createUser($user_data = NULL)
 {
     if (empty($user_data) or !$user_data instanceof User) {
         return FALSE;
     }
     $user = new User();
     $db = MySQL::getInstance();
     $db->query("SELECT COUNT(*) FROM `user` WHERE `Email` = " . $db->escape($user_data->Email) . " OR `Login` = " . $db->escape($user_data->Login) . "");
     $user_exist = $db->fetchField();
     if (!$user_exist) {
         if (isset($user_data->ActiveTo) and !is_numeric($user->ActiveTo)) {
             $user_data->ActiveTo = 0;
         }
         // to make sure that $user_data['admin']=true works the same as $user_data['admin']=1
         $user_data->Role = array_key_exists($user_data->Role, $this->config['roles']) ? $user_data->Role : 0;
         $user->merge($user_data);
         $user->Password = $this->hash($user->Password);
         return $result = $user->add() ? TRUE : FALSE;
     }
     return FALSE;
 }