Phalcon-designing-login-page

提供:Dev Guides
移動先:案内検索

Phalcon-ログインページの設計

UsersController.php

<?php
class UsersController extends Phalcon\Mvc\Controller {
   public function indexAction() {
   }
   public function loginAction() {
      if ($this->request->isPost()) {
         $user = Users::findFirst(array(
            'login = :login: and password = :password:', 'bind' => array(
               'login' => $this->request->getPost("login"),
               'password' => $this->request->getPost("password")
            )
         ));
         if ($user === false) {
            $this->flash->error("Incorrect credentials");
            return $this->dispatcher->forward(array(
               'controller' => 'users', 'action' => 'index'
            ));
         }
         $this->session->set('auth', $user->id);
         $this->flash->success("You've been successfully logged in");
      }
      return $this->dispatcher->forward(array(
         'controller' => 'posts', 'action' => 'index'
      ));
   }
   public function logoutAction() {
      $this->session->remove('auth');
      return $this->dispatcher->forward(array(
         'controller' => 'posts', 'action' => 'index'
      ));
   }
}
*UsersController* には、ログインおよびログアウト機能を備えた機能が含まれています。 「ユーザー」テーブルのレコードの関連値を確認します。 値が認証されると、ユーザーは正常にログインするか、エラーメッセージを受け取ります。

上記のコードの出力は次のとおりです。

UsersController

Webアプリケーションにログインすると、出力は次のスクリーンショットのようになります。

スクリーンショット

次の章では、カテゴリと投稿の管理に焦点を当てたビューの実装について見ていきます。