52 lines
1.2 KiB
PHP
52 lines
1.2 KiB
PHP
<?php
|
|
//Here Users is the table from the database
|
|
|
|
class User_model extends CI_Model{
|
|
public function register($enc_password){
|
|
// User data array
|
|
$data = array(
|
|
'name' => $this->input->post('name'),
|
|
'email' => $this->input->post('email'),
|
|
'username' => $this->input->post('username'),
|
|
'password' => $enc_password,
|
|
);
|
|
|
|
// Insert user
|
|
return $this->db->insert('Users', $data);
|
|
}
|
|
|
|
// Log user in
|
|
public function login($username, $password){
|
|
// Validate
|
|
$this->db->where('username', $username);
|
|
$this->db->where('password', $password);
|
|
|
|
$result = $this->db->get('Users');
|
|
|
|
if($result->num_rows() == 1){
|
|
return $result->row(0)->user_id;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Check username exists
|
|
public function check_username_exists($username){
|
|
$query = $this->db->get_where('Users', array('username' => $username));
|
|
if(empty($query->row_array())){
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Check email exists
|
|
public function check_email_exists($email){
|
|
$query = $this->db->get_where('Users', array('email' => $email));
|
|
if(empty($query->row_array())){
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
} |