This commit is contained in:
torun23 2024-07-11 17:35:44 +05:30
parent 605a538315
commit 7ca73f287d
14 changed files with 410 additions and 5 deletions

View File

@ -3,6 +3,9 @@ defined('BASEPATH') OR exit('No direct script access allowed');
$route['forms'] = 'Form_controller/index';
$route['default_controller'] = 'welcome';
$route['default_controller'] = 'home/index2';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['start'] = 'home/index';

View File

@ -0,0 +1,40 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Home extends CI_Controller
{
public function index()
{
$this->load->view('templates/header');
$this->load->view('templates/footer');
}
public function index1()
{
$this->load->view('templates/header');
$this->load->view('pages/about');
$this->load->view('templates/footer');
}
public function index2()
{
$this->load->view('templates/header');
$this->load->view('pages/formspage');
$this->load->view('templates/footer');
}
public function index3()
{
$this->load->view('templates/header');
$this->load->view('pages/homepage');
$this->load->view('templates/footer');
}
public function create_form(){
$this->load->view('templates/forms_ui');
}
}

View File

@ -0,0 +1,122 @@
<?php
class Users extends CI_Controller
{
//signup user
public function register()
{
$data['title'] = 'Sign Up';
$this->form_validation->set_rules('username', 'Username', 'required|callback_check_username_exists');
$this->form_validation->set_rules('email', 'Email', 'required|callback_check_email_exists');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('password2', 'Confirm Passsword', 'matches[password]');
if ($this->form_validation->run() === FALSE) {
$this->load->view('templates/header');
$this->load->view('users/register', $data);
$this->load->view('templates/footer');
} else {
$enc_password = md5($this->input->post('password'));
$this->load->model('user_model');
$this->user_model->register($enc_password);
// $this->user_model->register();
$this->session->set_flashdata('user_registered', 'You are now registered and can log in');
redirect('start');
}
}
//login user
public function login()
{
$data['title'] = 'Sign In';
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() === FALSE) {
$this->load->view('templates/header');
$this->load->view('users/login', $data);
$this->load->view('templates/footer');
} else {
// Get username
$username = $this->input->post('username');
// Get and encrypt the password
$password = md5($this->input->post('password'));
$this->load->model('user_model');
// Login user
$user_id = $this->user_model->login($username, $password);
if ($user_id) {
// Create session
$user_data = array(
'user_id' => $user_id,
'username' => $username,
'logged_in' => true
);
$this->session->set_userdata($user_data);
// Set message
$this->session->set_flashdata('user_loggedin', 'You are now logged in');
redirect('start');
} else {
// Set message
$this->session->set_flashdata('login_failed', 'Login is invalid');
redirect('users/login');
}
}
}
public function logout()
{
$this->session->unset_userdata('logged_in');
$this->session->unset_userdata('user_id');
$this->session->unset_userdata('username');
$this->session->set_flashdata('user_loggedout', 'You are now logged out');
redirect('users/login');
}
// check if username exists
public function check_username_exists($username)
{
$this->form_validation->set_message('check_username_exists', 'The username is taken.Please choose a different one');
$this->load->model('user_model');
if ($this->user_model->check_username_exists($username)) {
return true;
} else {
return false;
}
}
public function check_email_exists($email)
{
$this->form_validation->set_message('check_email_exists', 'The email is taken.Please choose a different one');
$this->load->model('user_model');
if ($this->user_model->check_email_exists($email)) {
return true;
} else {
return false;
}
}
// public function callback_user_id_exists($id)
// {
// $this->form_validation->set_message('user_id_exists', 'The ID is taken.Please choose a different one');
// $this->load->model('user_model');
// if ($this->user_model->user_id_exists($id)) {
// return true;
// } else {
// return false;
// }
// }
}
?>

View File

@ -0,0 +1,49 @@
<?php
class User_model extends CI_Model{
public function register($enc_password){
$data = array(
'email'=> $this->input->post('email'),
'username'=> $this->input->post('username'),
'password'=> $enc_password
);
return $this->db->insert('users', $data);
}
public function login($username,$password){
$this->db->where('username',$username);
$this->db->where('password',$password);
$result = $this->db->get('users');
if($result->num_rows()==1){
return $result->row(0)->id;
}
else{
return false;
}
}
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;
}
}
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;
}
}
}
?>

View File

@ -0,0 +1 @@
<h4>This is about page</h4>

View File

@ -0,0 +1 @@
<h4>Welcome to Google Forms !</h4>

View File

@ -0,0 +1 @@
<h4>This is the home page</h4>

View File

@ -0,0 +1,6 @@
</div>
<script>
CKEDITOR.replace( 'editor1' );
</script>
</body>
</html>

View File

@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@ -8,8 +9,48 @@
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/jquery-ui.css">
<style>
.navbar-custom {
background-color: rgb(103, 58, 183);
color: white;
border-radius: 0;
}
.navbar-custom .navbar-brand {
color: white;
font-size: 18px; /* Adjust font size for navbar links */
}
.navbar-custom .navbar-nav > li > a {
color: white;
font-size: 16px; /* Adjust font size for navbar links */
}
/* Additional styling for submit button */
#submit-btn {
margin-top: 20px;
float: left; /* Align button to the left */
clear: both; /* Clear float to ensure proper layout */
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse navbar-custom">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index2">Google Forms</a>
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index3">Home</a>
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index1">About</a>
</div>
<div id="navbar">
<ul class="nav navbar-nav navbar-right">
<a class="navbar-brand" href="<?php echo base_url(); ?>users/logout">Logout</a>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="form-header">
<button id="preview-btn" class="btn btn-info"><i class="fas fa-eye"></i></button>
@ -17,6 +58,9 @@
<button id="add-section-btn" class="btn btn-primary">+</button>
</div>
<div id="form-container"></div>
<!-- Submit button -->
<button class="btn btn-success" style="margin-left: 240px; margin-top: 20px">Submit</button>
</div>
<script src="<?php echo base_url('assets/js/jquery.min.js'); ?>"></script>
@ -24,4 +68,5 @@
<script src="<?php echo base_url('assets/js/jquery-ui.js'); ?>"></script>
<script src="<?php echo base_url('assets/js/scripts.js'); ?>"></script>
</body>
</html>

View File

@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blog App</title>
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/header_styles.css">
<script src="https://cdn.ckeditor.com/4.16.0/standard/ckeditor.js"></script>
</head>
<body style = "background-color: rgb(240,235,248);" >
<nav class="navbar navbar-inverse" style="background-color: rgb(103, 58, 183);" >
<div class="container" style="background-color: rgb(103, 58, 183);">
<div class="navbar-header">
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index2">Google Forms</a>
</div>
<div id="navbar">
<ul class="nav navbar-nav">
<li><a href="<?php echo base_url(); ?>home/index3">Home</a></li>
<li><a href="<?php echo base_url(); ?>home/index1">About</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<?php if (!$this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>users/login">Login</a></li>
<li><a href="<?php echo base_url(); ?>users/register">Register</a></li>
<?php endif; ?>
<?php if ($this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>home/create_form">Create Form</a></li>
<li><a href="<?php echo base_url(); ?>users/logout">Logout</a></li>
<?php endif; ?>
</ul>
</div>
</div>
</nav>
<div class="container">
<?php if ($this->session->flashdata('user_registered')): ?>
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_registered') . '</p>'; ?>
<?php endif; ?>
<?php if ($this->session->flashdata('login_failed')): ?>
<?php echo '<p class="alert alert-danger">' . $this->session->flashdata('login_failed') . '</p>'; ?>
<?php endif; ?>
<?php if ($this->session->flashdata('user_loggedin')): ?>
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_loggedin') . '</p>'; ?>
<?php endif; ?>
<?php if ($this->session->flashdata('user_loggedout')): ?>
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_loggedout') . '</p>'; ?>
<?php endif; ?>
</div>
<div>

View File

@ -0,0 +1,19 @@
<?php echo form_open('users/login'); ?>
<div class="row">
<div class="col-md-4 col-md-offset-4">
<h1 class="text-center">
<?php echo $title; ?>
</h1>
<div class="form-group">
<input type = "text" name ="username" class="form-control" placeholder = "Enter Username" required autofocus>
</div>
<div class="form-group">
<input type = "password" name ="password" class="form-control" placeholder = "Enter Password" required autofocus>
</div>
<button type = "submit" class = "btn btn-primary btn-block">Login</button>
</div>
</div>
<?php echo form_close(); ?>

View File

@ -0,0 +1,27 @@
<?php echo validation_errors(); ?>
<?php echo form_open('users/register'); ?>
<div class="row">
<div class="col-md-4 col-md-offset-4">
<h1 class="text-center"><?= $title; ?></h1>
<div class="form-group">
<label>Username</label>
<input type=" text" class="form-control" name="username" placeholder="Username">
</div>
<div class="form-group">
<label>Email</label>
<input type=" text" class="form-control" name="email" placeholder="Email">
</div>
<div class="form-group">
<label>Password</label>
<input type=" password" class="form-control" name="password" placeholder="Password ">
</div>
<div class="form-group">
<label>Confirm Password</label>
<input type="password" class="form-control" name="password2" placeholder="Confirm Password ">
</div>
<button type="submit" class="btn btn-primary btn-block">Submit</button>
</div>
</div>
<?php echo form_close(); ?>

View File

@ -0,0 +1,30 @@
.post-date{
background: #f4f4f4;
padding: 4px;
margin:3px 0;
display: block;
}
.post-thumb{
width: 100%;
}
.pagination-link{
margin:30px 0;
}
.pagination-links strong{
padding: 8px 13px;
margin:5px;
background: #f4f4f4;
border: 1px #ccc solid;
}
a.pagination-link{
padding: 8px 13px;
margin:5px;
background: #f4f4f4;
border: 1px #ccc solid;
}
.cat-delete{
display:inline;
}

View File

@ -1,5 +1,4 @@
body {
background-color: rgb(240, 235, 248);
font-family: Arial, sans-serif;