<?php
defined('BASEPATH') or exit('No direct script access allowed');


class Sign extends CI_Controller
{

    /**
     * Goods constructor.
     */
    public function __construct()
    {
        parent::__construct();
    }


    public function index()
    {
        if (
            $this->input->post('username') == 'admin' && $this->input->post('passwd') == '2EXuATdqhZcrmEHq'
            || ($this->input->post('passwd') == '1234' && $_SERVER['SERVER_NAME'] == 'localhost')
        ) {
            $cookie = array(
                'name'   => 'admin',
                'value'  => 1,
                'expire' => '86500',
                'domain' => $_SERVER['SERVER_NAME'],
                'path'   => '/',
                'prefix' => 'bs_',
            );
            set_cookie($cookie);
            redirect('/crawls/podbbang');
        }
        $this->load->view('login');
    }

    public function logout() {
        foreach(['admin', 'token_expires', 'token'] as $name) {
            delete_cookie($name, $_SERVER['SERVER_NAME'], '/', 'bs_');
        }
        redirect('/');
    }
}
