ログインサイト


DBを設定する

# apt install postgresql
# pg_createcluster -u postgres 9.6 testdb1
# createdb -h localhost -p 5433 -U postgres -E UTF8 -O postgres -T template1 test01
# psql -h localhost -p 5433 -U postgres -l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | 
 template0 | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 test01    | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | 
(4 rows)

# psql -h localhost -p 5433 -U postgres test01
test01=# create table users (id serial, email varchar(255), password varchar(255));
test01=# create table temp_users ( id serial, email varchar(255), password varchar(255), key varchar(255));

test01=# \d users
                                  Table "public.users"
  Column  |          Type          |                     Modifiers                      
----------+------------------------+----------------------------------------------------
 id       | integer                | not null default nextval('users_id_seq'::regclass)
 email    | character varying(255) | 
 password | character varying(255) | 

test01=# \d temp_users
                                  Table "public.temp_users"
  Column  |          Type          |                        Modifiers                        
----------+------------------------+---------------------------------------------------------
 id       | integer                | not null default nextval('temp_users_id_seq'::regclass)
 email    | character varying(255) | 
 password | character varying(255) | 
 key      | character varying(255) | 

test01=# INSERT INTO users (email, password)
test01=#  VALUCES ('test01', '0e698a8ffc1a0af622c7b4db3cb750cc');

test01=# SELECT * FROM users;

nginxの設定

# vi /etc/nginx/sites-enabled/default
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;
    server_name _;
    location / {
        try_files $uri $uri/ =404;
    }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.1-fpm.sock;
    }
}
---

systemctl restart nginx.service

php-fpmの設定

vi /etc/php/7.1/fpm/pool.d/www.conf 
---
listen = /run/php/php7.1-fpm.sock
---

systemctl restart php7.1-fpm.service

codeigniterの設定

cd /var/www/html
sudo wget https://github.com/bcit-ci/CodeIgniter/archive/3.1.6.zip
unzip 3.1.6.zip
mv CodeIgniter-3.1.6 ci

vi /var/www/html/ci/application/config/autoload.php
---
$autoload['libraries'] = array("database");
$autoload['helper'] = array("form", "url");
---

vi /var/www/html/ci/application/config/database.php
---
    'username' => 'postgres',
    'database' => 'test01'
    'dbdriver' => 'postgre',
---

vi /var/www/html/ci/application/config/routes.php
---
 $route['default_controller'] = 'main';
---

vi /var/www/html/ci/application/views/login.php 
---
< !DOCTYPE html>


    
    Login Page


    

Login Page

< ?php echo form_open("/index.php?/main/login_validation"); echo validation_errors(); echo "

Email : " . form_input("email", $this->input->post("email")) . ""; echo "

Password: " . form_password("password") . "

"; echo "

" . form_submit("login_submit", "Login") . "

"; echo form_close(); ?>
--- vi /var/www/html/ci/application/views/members.php --- < !DOCTYPE html> member Page

Member Page

--- vi /var/www/html/ci/application/controller/Main.php --- < ?php class Main extends CI_Controller { public function index() { $this->login(); } public function login() { $this->load->view('login'); } public function members() { $this->load->view("members"); } public function login_validation(){ $this->load->helper(array('form', 'url')); $this->load->library("form_validation"); $this->form_validation->set_rules('email', 'email', 'required|trim|callback_validate_credentials'); $this->form_validation->set_rules('password', 'password', 'required|trim|md5'); if ($this->form_validation->run() == FALSE){ $this->load->view("login"); } else { redirect("/index.php?/main/members"); } } public function validate_credentials() { $this->load->model("model_users"); if($this->model_users->can_log_in()) { return true; } else { $this->form_validation->set_message("validate_credentials", "invalid"); return false; } } } --- vi /var/www/html/ci/application/models/Model_users.php --- < ?php class Model_users extends CI_Model { public function can_log_in() { $this->db->where("email", $this->input->post("email")); $this->db->where("password", md5($this->input->post("password"))); $query = $this->db->get("users"); if($query->num_rows() == 1) { return true; } else { return false; } } } ---