CodeIgniter_Gforms/application/models/User_model.php

52 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2024-07-11 13:04:55 +00:00
<?php
2024-07-12 09:55:29 +00:00
//Here users is the table from the database
2024-07-11 13:04:55 +00:00
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
2024-07-12 09:55:29 +00:00
return $this->db->insert('users', $data);
2024-07-11 13:04:55 +00:00
}
// Log user in
public function login($username, $password){
// Validate
$this->db->where('username', $username);
$this->db->where('password', $password);
2024-07-12 09:55:29 +00:00
$result = $this->db->get('users');
2024-07-11 13:04:55 +00:00
if($result->num_rows() == 1){
return $result->row(0)->user_id;
} else {
return false;
}
}
// Check username exists
public function check_username_exists($username){
2024-07-12 09:55:29 +00:00
$query = $this->db->get_where('users', array('username' => $username));
2024-07-11 13:04:55 +00:00
if(empty($query->row_array())){
return true;
} else {
return false;
}
}
// Check email exists
public function check_email_exists($email){
2024-07-12 09:55:29 +00:00
$query = $this->db->get_where('users', array('email' => $email));
2024-07-11 13:04:55 +00:00
if(empty($query->row_array())){
return true;
} else {
return false;
}
}
}