Skip to content

PlusMagi's Blog By Pitt Phunsanit

Plus emotional magic to the knowledge of logic.

  • About’s Pitt
Close Button

Laravel: login แบบมีเงื่อนไขLaravel: login แบบมีเงื่อนไข

2014-02-082014-02-08| phunsanitphunsanit| 0 Comment | 07:00

Laravel สร้างระบบ login ได้โดยทำตามคู่มือ Authentication หรือตาม ติดตั้ง laravel ลั๊ลลาเวล และ สร้างระบบ login ใน laravel 5

แต่เมื่อใคร ๆ ก็สามารถที่จะสมัครแล้วใช้งานได้เลย ทำให้ไม่ปลอดภัย จึงควรเพิ่มเงื่อนไขเข้าไป ทำได้โดย

การแก้ไขให้ตรวจสอบเพิ่มในการ login เข้าระบบทำได้โดย

  1. เพิ่ม column active ในตาราง users โดย
    ALTER TABLE `users` ADD `active` TINYINT (1) UNSIGNED NOT NULL DEFAULT '0' COMMENT '0 inactive, 1 active' AFTER `id`;
  2. เปิดไฟล์ \app\Http\Controllers\Auth\AuthController.php แก้ตามตัวอย่าง
    ...
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Auth;
    … /* redirect after login */ protected $redirectPath = 'home'; /* custom login condition */ protected function getCredentials (Request $request) { $crendentials = $request->only ($this->loginUsername () , 'password') ; $crendentials['active'] = 1; return $crendentials; } /* custom register process */ public function postRegister (Request $request) { $validator = $this->validator ($request->all ()) ; if ($validator->fails ()) { $this->throwValidationException; } Auth::login ($this->create ($request->all ())) ; Auth::logout () ; flash ('please contact system administrator for activation.') ; return redirect ('auth/login') ; }
    ...
    

    และถ้าต้องการให้เปลี่ยนไปหน้าอื่นหลังจาก login ให้แก้

    protected $redirectPath = '/home';

    ไป route ที่ต้องการ

  3. ทดลอง logout แล้วก็ login ใหม่จะมี message These credentials do not match our records. ขึ้นมาทั้ง ๆ ที username และ password ถูกต้อง
  4. ไปแก้ record user ที่ใช้ให้ active = 1 แล้ว login ดูอีกครั้ง จะเข้าระบบได้แล้ว
  5. logout แล้วทดลองสมัครสมาชิกใหม่ จะต้องวิ่งไปในหน้าที่ต้องการโดยไม่ได้ล๊อกอิน
  6. สร้างหน้าจัดการ user โดยเปลี่ยนสถานะ
    0
    login ไม่ได้
    1
    login ได้
Read MoreRead More

Posts pagination

ก่อนหน้า 1 … 731 732 733 … 1,022 ถัดไป

Projects

  • Statement Columns Mapping Helper
  • PlusMagi Site Search
  • jQuery Plus Repeater

Recent Posts

  • AI MCP: Model Context Protocol
  • React: TabulatorPlus
  • SonarQube: ติดตั้ง
  • Tabulator: TabulatorPlus (Wrapper Class )
  • AI:thClaws

Archives

Categories

  • AI (15)
  • Businesses (4)
  • Design (43)
    • UX/UI (12)
  • DevOps (59)
    • CI/CD (2)
    • Docker (32)
    • GIT (25)
  • Histories (10)
  • Life (81)
    • Books (28)
    • Tips and Tricks (21)
    • พุทธ (5)
  • Network (118)
    • Apache HTTP Server (14)
    • IOT (1)
    • Nginx (28)
    • Stalwart (5)
  • Operating Systems (254)
    • Unix-like (182)
      • Android (15)
        • F-Droid (5)
      • iPhone (8)
      • Linux (111)
      • macOS (95)
        • Homebrew (15)
        • OrbStack (11)
      • Oh My ZSH (4)
      • Shell Script (33)
      • SSH (11)
    • Windows (115)
      • PowerShell (24)
      • WSL (24)
  • Programming (686)
    • .NET (18)
      • .NET Core EF (5)
      • C# (17)
    • API (25)
      • REST (5)
      • Swagger (6)
    • Database (176)
      • DBeaver (3)
      • MariaDB (28)
      • MySql (66)
      • Oracle Database (6)
        • 10g (3)
      • PostgreSQL (8)
      • RDBMS (2)
      • SQL Server (85)
        • SSMS (8)
        • T-SQL (26)
      • SQLite (1)
    • PowerBuilder (10)
    • Python (1)
    • Rust (1)
    • System Analyst (SA) (8)
    • Testing (15)
      • Automated Testing (7)
        • Playwright (5)
    • UML (7)
    • Web (367)
      • Backend (238)
        • Golang (1)
        • Java (45)
          • Spring Boot (14)
        • Node.js (1)
        • PHP (192)
          • Laravel (16)
          • Yii (5)
      • Frontend (125)
        • CSS (17)
          • Tailwind CSS (5)
        • JavaScript (113)
          • Angular (2)
          • jQuery (60)
          • Tabulator (13)
          • Vue.js (4)
      • WordPress (25)
  • Programs (83)
    • Excel (10)
  • Security (52)
  • Uncategorized (1)
  • กฎหมาย (6)

Sirat WordPress Theme By VWThemes

Scroll Up