mourne_rcpp_fw/Mourne-CI/application/controllers/user.php

139 lines
3.6 KiB
PHP
Raw Normal View History

2021-10-30 19:02:07 +02:00
<?php
class User extends MO_Controller
{
public function __construct()
2021-10-30 19:02:07 +02:00
{
parent::__construct();
2021-10-30 19:02:07 +02:00
}
public function login()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
2021-10-30 19:02:07 +02:00
//is_unique[users.username]
2021-10-30 19:02:07 +02:00
//xss_validation
//TODO figure rules out
$this->form_validation->set_rules(
'username',
'Username',
'required'
);
//password callback -> $this->input->post('username'), after xss filter
$this->form_validation->set_rules(
'password',
'Password',
'required|callback_login_check'
);
if ($this->form_validation->run() == false) {
$this->load->view('login/login');
} else {
$this->load->helper('url');
redirect('news/index');
//$this->load->view('login/success');
}
2021-10-30 19:02:07 +02:00
}
public function register()
2021-10-30 19:02:07 +02:00
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
//is_unique[users.username]
//xss_clean
$this->form_validation->set_rules(
'username',
'Username',
'required|min_length[4]|max_length[32]|callback_register_username_check'
);
$this->form_validation->set_rules(
'password',
'Password',
'required|min_length[5]|matches[password_check]'
);
$this->form_validation->set_rules('password_check', 'Password check', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|matches[email_check]');
$this->form_validation->set_rules('email_check', 'Email_check', 'required');
//$this->form_validation->set_rules('license', 'License', 'required');
if ($this->form_validation->run() == false) {
$this->load->view('register/register');
} else {
if ($this->register_write()) {
$this->load->view('register/success');
}
}
2021-10-30 19:02:07 +02:00
}
public function logout()
{
$this->session->unset_userdata('userid');
2021-10-30 19:02:07 +02:00
$this->load->helper('url');
redirect('user/login');
2021-10-30 19:02:07 +02:00
//TODO make it look cool
2021-10-30 19:02:07 +02:00
//$this->load->view('redirect_to_login');
}
2021-10-30 19:02:07 +02:00
public function register_username_check($attr)
2021-10-30 19:02:07 +02:00
{
$this->load->model('user_model');
if ($this->user_model->reg_username_check($attr)) {
return true;
} else {
$this->form_validation->set_message('register_username_check', 'Username already exists!');
return false;
}
2021-10-30 19:02:07 +02:00
}
public function register_write()
2021-10-30 19:02:07 +02:00
{
$data['username'] = $this->input->post('username');
$data['password'] = md5($this->input->post('password'));
$data['email'] = $this->input->post('email');
$this->load->model('user_model');
return $this->user_model->reg_write($data);
2021-10-30 19:02:07 +02:00
}
public function login_check($attr)
2021-10-30 19:02:07 +02:00
{
$data['username'] = $this->input->post('username');
$data['password'] = md5($attr);
2021-10-30 19:02:07 +02:00
$this->load->model('user_model');
if ($this->user_model->login_check($data)) {
$this->session->set_userdata(
'userid',
$this->user_model->get_userid($data['username'])
);
return true;
} else {
return false;
}
2021-10-30 19:02:07 +02:00
}
public function settings()
{
$this->headers('settings');
2021-10-30 19:02:07 +02:00
$this->footer();
}
2021-10-30 19:02:07 +02:00
}//login class
//nowhitesp