아래는 수정된 내용입니다. 오류가 몇군데 있어서 좀 고생했네요..
아래 링크에서 다운 받으신후에 아래 소스와 비교해 보시면 오류 내용들을 찾을수 있습니다.
출처는 http://www.codeigniter-kr.org/source/view/473/page/2/
저 같은 CI초보자에게 아주 좋은 자료라고 판단됩니다. 오류만 없었다면...
controllers/account.php
<?php
class Account extends Controller
{
function Account()
{
parent::Controller();
$this->load->library(array('form_validation', 'session'));
$this->load->helper(array('url', 'form'));
$this->load->Model('account_model');
$this->_salt = '12345678987654321';
}
function index()
{
if ($this->account_model->logged_in() == true)
{
$this->dashboard(true);
}
else
{
$this->load->view('account/details');
}
}
function dashboard($condition = false)
{
if ($condition == true or $this->account_model->logged_in() == TRUE)
{
$this->load->view('account/dashboard');
}
else
{
$this->load->view('account/details');
}
}
function login()
{
$this->form_validation->set_rules('username', '아이디', 'xss_clean|required');
$this->form_validation->set_rules('password', '패스워드', 'xss_clean|required|min_length[4]|max_length[12]|callback_password_check');
$this->username = $this->input->post('username');
$this->password = sha1($this->_salt . $this->input->post('password'));
if ($this->form_validation->run() == false)
{
$this->load->view('account/login');
}
else
{
$this->account_model->login();
$data['message'] = '로그인 성공 ' . anchor('account/dashboard', '접속');
$this->load->view('account/success', $data);
}
}
/*///////////////////////////////////////////////////////////
function username_check($username)
{
$this->db->where('username', $this->username);
$query = $this->db->get('users');
$result = $query->row_array();
if ($result['username'] == $this->username)
{
return true;
}
if ($query->num_rows() == 0)
{
$this->form_validation->set_message('username_check', '존재하지 않는 아이디 입니다.');
return false;
}
}
/////////////////////////////////////////////////////////////
*/
function password_check($password)
{
$this->db->where('username', $this->username);
$query = $this->db->get('users');
$result = $query->row_array();
//echo $result['password'];
//echo $this->password;
//exit;
if ($result['password'] == $this->password)
{
return true;
}
else
{
$this->form_validation->set_message('password_check', '패스워드가 틀렸습니다.');
return false;
}
}
function register()
{
$this->form_validation->set_rules('username', '아이디', 'xss_clean|required|callback_username_exists');
$this->form_validation->set_rules('email', '이메일', 'xss_clean|required|valid_email|callback_email_exists');
$this->form_validation->set_rules('password', '패스워드', 'xss_clean|required|min_length[4]|max_length[12]|matches[password_conf]');
$this->form_validation->set_rules('password_conf', '패스워드(확인)', 'xss_clean|required|matches[password]|sha1');
if ($this->form_validation->run() == false)
{
$this->load->view('account/register');
}
else
{
$data['username'] = $this->input->post('username');
$data['email'] = $this->input->post('email');
$data['password'] = sha1($this->_salt . $this->input->post('password'));
if ($this->account_model->create($data) === true)
{
$data['message'] = "회원가입성공 " . anchor('account/login', 'here') . ".";
$this->load->view('account/success', $data);
}
else
{
$data['error'] = "회원가입에 실패했습니다.";
$this->load->view('account/error', $data);
}
}
}
function username_exists($username)
{
$query = $this->db->get_where('users', array('username' => $username));
if ($query->num_rows() > 0)
{
$this->form_validation->set_message('username_exists', '입력하신 %s 는 존재하는 아이디 입니다. .');
return false;
}
$query->free_result();
return true;
}
function email_exists($email)
{
$query = $this->db->get_where('users', array('email' => $email));
if ($query->num_rows() > 0)
{
$this->form_validation->set_message('email_exists', '입력하신 %s 은 존재하는 이메일 입니다.');
return false;
}
$query->free_result();
return true;
}
function logout()
{
$this->session->sess_destroy();
$this->load->view('account/logout');
}
}
?>
callbackup_password_check
함수명을 요렇게 바꿔보세요.
callback_password_check
$this->form_validation->set_rules('password', '패스워드', 'xss_clean|required|min_length[4]|max_length[12]|sha1|callback_password_check');