跳到主要內容

發表文章

Hyper-v 使用 PowerShell 設定 VM 的螢幕解析度

 因為利用 Hyper-V 安裝  Xubuntu  來測試伺服器和程式,預設的螢幕解析是 1024x768,實在非常的不夠用。 而 xubuntu 的設定和硬體支援比較陽春,沒有其他螢幕解析度可以調,所以查網路的資料發現可以用 Powershell 直接在 vm 上設定。 參考資料: https://superuser.com/questions/1660150/change-screen-resolution-of-ubuntu-vm-in-hyper-v 在 PowerShell 中輸入: set-vmvideo xubuntu -horizontalresolution:1920 -verticalresolution:1080 -resolutiontype single

CI4 利用 gmail 發信

最近一個專案須要在預約登記成功之後,發送通知信至使用者的電子郵件信箱,所以研究了一下 CI4 中的 Email Library。 CI4 Email Class 參考網址: https://codeigniter.com/user_guide/libraries/email.html CI4 已經有內建電子郵件的服務(/Config/Services::Email()),只需要在 app/Config/Email.php 中填入必要的參數即可。其中可用的發信 protocol 可使用 mail、sendmail 和 smtp,使用 smtp 可以由 smtp.gmail.com 也就是用 Gmail 的 SMTP 來發信。 利用 Gmail SMPT 需要設定的參數: public $protocol =  'mail'; public $SMTPHost =  'smtp.gmail.com'; public $SMTPUser =  'Gmail帳號'; public $SMTPPass =  'Google 應用程式密碼'; public $SMTPPost =  465; public $SMTPCrypto = 'ssl';  //預設為 tls,一定要改成 ssl,否則發不出去。 其他參數: public $wordWrap = false; //取消自動斷行 Google 應用程式密碼 以前寫過利用 Gmail SMTP 發信的程式,用的是原有的 gmail 帳號和密碼,需要將該帳號安全性定開啟「 低安全性應用程式存取權 」: 但這樣子會降低 google 帳號的安全性,並不建議如此做!現今的方式是使用「 Google 應用程式密碼 」來處理。 參考網址:【2021最新版】如何使用Google SMTP寄信(兩段式驗證+應用程式密碼) - 主機架站寄信教學  https://www.webdesigntooler.com/google-smtp-send-mail   CI4 發信程式 取自 CodeIgniter 4 官網說明

firebase 1:簡介

  firebase 是 Google 推出的網站整合性服務,提供認證(Authentication)、資料庫(Realtime Database、Firebase Database)、雲端空間(Storage、Functions、Extensions)、網頁空間(Hosting)、雲計算(Machine Learning)…等。 相關網站: Google Firebase Console  https://console.firebase.google.com/ 文件: https://firebase.google.com/docs?authuser=0&hl=zh 參考資料: Firebase 教學 - Firestore 安裝、寫入和讀取  https://www.oxxostudio.tw/articles/201905/firebase-firestore.html Firebase 教學 - 簡單的使用者註冊功能  https://www.oxxostudio.tw/articles/201905/firebase-simple-signup.html Firebase 教學 - RealTime Database 安裝與使用  https://www.oxxostudio.tw/articles/201904/firebase-realtime-database-start.html Day29 前端福音(4/4): Firebase-帳號系統&資料讀寫規則  https://ithelp.ithome.com.tw/articles/10206354 Firebase網頁教學[二] - 驗證篇  http://sj82516-blog.logdown.com/posts/1050619 用 Firebase Authentication 做一套簡易會員系統 – 電子郵件 密碼  https://www.letswrite.tw/firebase-auth-email/ 利用 Firebase Authentication 來實現註冊帳號和登入的功能  https://franksios.medium.com/ios-%E5%88%A9%E7%94...

網頁引入相機及QRCode判讀

 之前有寫過實名制及報名網站內含 QRCode 的判讀功能,使用 Intascan 及 Webrtc 的 javascript 模組。 參考資料:[day14]-使用網頁開啟相機掃描QR Code-instascan介紹+實際應用( https://ithelp.ithome.com.tw/articles/10206308 ) Instscan: https://github.com/schmich/instascan Webrtc: https://github.com/webrtc/adapter 網頁 html 上半部是掃描結果訊息顯示的部份,result_icon 用 materical design icons 顯示各個圖示;scan_text 顯示掃描結東;result_text 顯示文字化結果。 下半以 video 顯示 WebRTC 從 Camera 擷取的畫面,並由 Instascan 依此資料判讀 QRCode 資訊。camera_select 作為切換 Camera 的功能。 Javascript <script>         let precode = '';         let res = '';         let audio = new Audio('audio_beep.mp3');         let scanner = new Instascan.Scanner({             video: document.getElementById('preview'),             mirror: false         });         scanner.addListener('scan', function(content) {            ...

CI4 + Google Oauth2

因自己在教育處寫的系統無法使用 SSO OpenID 的認證服務,所以改以使用 Google OAuth2.0 作 gm.kl.edu.tw 網域帳號的認證。不過,後來發現把這一部份研究清楚也很有好處,首先不會受限於一定要是 OpenID 帳號才能使用的系統,因為現實面上有很多老師和承辦還是不習慣使用 OpenID 附帶的 gm.kl.edu.tw 帳號;再後來用了 firebase 服務後,更可以擴大到更廣的 OAuth(如FB、Github…等)。  Google API 提供 OAuth2.0 的帳號認證服務,主要的功能是提供網頁系統可以認證 Google 帳號,並提供認證帳號的基本資訊。 Google Cloud 網址: https://console.cloud.google.com/ 在CI4要使用 Google OAuth2.0須先在 CI4 系統中安裝 「Google APIs Client Library for PHP」 composer require google/apiclient:^2.12.1 認證程式參考資料:Login with Google for Codeigniter  https://github.com/angel-of-death/Codeigniter-Google-OAuth-Login Google Cloud API 設定 1. 到 Google Cloud 建立專案 2. 在專案的 「API和服務」功能下建立 OAuth2.0用戶端憑證: 用戶端憑證有兩種情形:內部及外部。 「內部」表可以直接使用來認證與專案同網域的帳號,「外部」表可以用來認證任何網域的 Google 帳號,但需要經過 Google 的程式審查,我還沒試過!後來用了 firebase 後就可認證其他網域的帳號了。 在憑證的設定中,最重要的已授權的重新導向URI的部份,也就是一般的 Call Back URI,成功經過 Google 認證後會自動導向的網址,並會附帶 token,利用這個 token 就可以進一步取得使用者的基本資訊。 而同時有好幾個網站都用這一個用戶端憑證時(基本上我寫的所有網站都是用這個憑證…),要如何分辨是哪個網站來的?要回去哪邊? 就是用設定來指定 redirectURI: 我採用上述的範例程式改的,所以...

CI4 補充

CodeIgniter Shield CI4 新增的使用者管理系統,含登入、註冊及權限管理 安裝: composer require codeigniter4/shield 官方網站: https://github.com/codeigniter4/shield 說明: https://github.com/codeigniter4/shield/tree/develop/docs CodeIgniter 4 Settings 設定管理系統,類似之前自已程式使用的 ParamModel,在資料庀中儲存設定,用 service 方式處理。 安裝:  composer require codeigniter4/settings 官方網站:  https://github.com/codeigniter4/settings 使用:用 helper(setting) 或 service('setting') Myth:Auth https://github.com/lonnieezell/myth-auth Tatter\Fireauth https://github.com/tattersoftware/codeigniter4-fireauth

CI 4.2.0 之後新增的 Auto Routing 設定

 一直以來都是利用  compose 來創建  CI4 的網站架構,在 CI4 更新到 4.2.0 版本之後,原本 function ***() 為作路徑的方式突然不能使用了,找了一下官網的說明之後,才發現有了新的 auto-routing 的設定。 Enable Auto Routing 開啟 auto-routing 的設定:修改 app/Config/Routes.php 設定 $routes->setAutoRoute(true) Enable Auto Routing (Improved) 基本上開啟上面的 auto-routing 的設定後,CI4 的路徑就會和以前一樣用 function name 來自動路由,但官網有建立還要再開啟 auto-routing(improved) 這個設定。 修改 app/Config/Features.php 開啟 auto-routing(improved)後,function 的名稱須要再加上 http method, 例如 getIndex()、postUpdate(),function 名稱配合 http method 才能正常執行,以增加網路安全,避免惡意的嚐試。