示例#1
0
文件: User.php 项目: Rotron/ecommerce
 public function updateUser($id)
 {
     $req = $this->app->request();
     $imageName = $_FILES['image']['name'];
     $imageTmp = $_FILES['image']['tmp_name'];
     $uniqueID = md5(uniqid(rand(), true));
     $fileType = strchr($imageName, '.');
     $newUpload = 'assets/img_public/' . $uniqueID . $fileType;
     if ($imageName != null) {
         unlink(User::showImageUser($id));
     }
     move_uploaded_file($imageTmp, $newUpload);
     @chmod($newUpload, 0777);
     if ($imageName != null) {
         $sql = 'UPDATE users SET u_email = :u_email, u_password = :u_password, u_image = :u_image, level = :level WHERE user_id = :id';
     } else {
         $sql = 'UPDATE users SET u_email = :u_email, u_password = :u_password, level = :level WHERE user_id = :id';
     }
     $this->users = parent::connect()->prepare($sql);
     $this->users->bindValue(':u_email', $req->post('email'));
     $this->users->bindValue(':u_password', Bcrypt::hash($req->post('password')));
     if ($imageName != null) {
         $this->users->bindValue(':u_image', $newUpload);
     }
     $this->users->bindValue(':level', $req->post('level'));
     $this->users->bindValue(':id', $id);
     try {
         $this->users->execute();
     } catch (PDOException $e) {
         die($e->getMessage());
     }
 }
示例#2
0
    public function updateCustomer($id)
    {
        $req = $this->app->request();
        $sql = 'UPDATE customers SET c_email = :c_email, c_password = :c_password, c_name = :c_name, address = :address, phone = :phone, notes = :notes 
			WHERE customer_id = :id';
        $this->customers = parent::connect()->prepare($sql);
        $data = array('c_email' => $req->post('c_email'), 'c_password' => Bcrypt::hash($req->post('c_password')), 'c_name' => $req->post('c_name'), 'address' => $req->post('address'), 'phone' => $req->post('phone'), 'notes' => $req->post('notes'), 'id' => $id);
        try {
            $this->customers->execute($data);
        } catch (PDOException $e) {
            die($e->getMessage());
        }
    }
示例#3
0
 public function loggedIn()
 {
     $req = $this->app->request();
     foreach (User::showUserByEmail($req->post('email')) as $row) {
         $stored_email = $row['u_email'];
         $stored_user_id = $row['user_id'];
         $stored_level = $row['level'];
         $stored_password = $row['u_password'];
     }
     if (User::countUser($req->post('email'))->fetchColumn() == 1 && Bcrypt::check($req->post('password'), $stored_password) === true) {
         $_SESSION['emailAdmin'] = $stored_email;
         $_SESSION['idAdmin'] = $stored_user_id;
         $_SESSION['levelAdmin'] = $stored_level;
         parent::redirectTo('indexAdmin');
     } else {
         $this->app->flash('error', "Email or Password doesn't match");
         $this->app->flash('tmpEmail', $req->post('email'));
         parent::redirectTo('loginAdmin');
     }
 }
示例#4
0
 public function loggedIn()
 {
     $req = $this->app->request();
     foreach (Customer::showCustomerByEmail($req->post('email')) as $row) {
         $stored_id = $row['customer_id'];
         $stored_email = $row['c_email'];
         $stored_name = $row['c_name'];
         $stored_password = $row['c_password'];
     }
     if (Customer::countCustomer($req->post('email'))->fetchColumn() == 1 && Bcrypt::check($req->post('password'), $stored_password) === true) {
         $_SESSION['idCustomer'] = $stored_id;
         $_SESSION['emailCustomer'] = $stored_email;
         $_SESSION['nameCustomer'] = $stored_name;
         $_SESSION['passwordCustomer'] = $stored_password;
         parent::redirectTo('indexHome');
     } else {
         $this->app->flash('error', "Email or Password doesn't match");
         $this->app->flash('tmpEmail', $req->post('email'));
         parent::redirectTo('loginCustomer');
     }
 }