<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/* Author: Jorge Torres
 * Description: Login controller class
 */

class Login extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
    }

    public function index($msg = null)
    {
        $data = [
            '_title' => '碩士教室 Mastery Education System - 登入',
            '_description' => '登入',
            '_error' => $msg,
            'username' => $this->input->post('username'),
            'password' => $this->input->post('password'),
        ];
		 $this->load->library('form_validation');
		$this->load->helper('form');
        $this->load->library("session");
        $this->load->view('/login', $data);
    }

    public function process()
    {
        // Load the model
        $this->load->model('login_model');
        // Validate the user can login
        $result = $this->login_model->validate();
        // Now we verify the result
        if (!$result) {
            // If user did not validate, then show them login page again
            $msg = '<font color=red>錯誤的登入名稱或密碼</font><br/>';
            $this->index($msg);
        } else {
            redirect('dashboard');
        }
    }
}
