-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Web UI cra #3
base: main
Are you sure you want to change the base?
Web UI cra #3
Changes from all commits
a901c44
853a56f
2cd4fda
8d80e37
70da3e7
c40cb65
d6cc9ea
7e4534f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
defined('BASEPATH') OR exit('No direct script access allowed'); | ||
|
||
class Users extends MY_Controller | ||
{ | ||
|
||
private $registerErrors = array(); | ||
private $user_id; | ||
private $num_rows = 5; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->load->library('email'); | ||
} | ||
|
||
public function index() | ||
{ | ||
show_404(); | ||
} | ||
|
||
public function login() | ||
{ | ||
if (isset($_POST['login'])) { | ||
$result = $this->Public_model->checkPublicUserIsValid($_POST); | ||
if ($result !== false) { | ||
$_SESSION['logged_user'] = $result; //id of user | ||
redirect(LANG_URL . '/checkout'); | ||
} else { | ||
Comment on lines
+25
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security Issue: The code directly uses $_POST data without proper validation or sanitization before using it in the Public_model->checkPublicUserIsValid method. This could lead to SQL Injection if the method constructs SQL queries without using prepared statements or parameterized queries.
|
||
$this->session->set_flashdata('userError', lang('wrong_user')); | ||
} | ||
} | ||
$head = array(); | ||
$data = array(); | ||
$head['title'] = lang('user_login'); | ||
$head['description'] = lang('user_login'); | ||
$head['keywords'] = str_replace(" ", ",", $head['title']); | ||
$this->render('login', $head, $data); | ||
} | ||
|
||
public function register() | ||
{ | ||
if (isset($_POST['signup'])) { | ||
$result = $this->registerValidate(); | ||
if ($result == false) { | ||
$this->session->set_flashdata('userError', $this->registerErrors); | ||
redirect(LANG_URL . '/register'); | ||
} else { | ||
Comment on lines
+44
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security Issue: Similar to the login function, the register function also uses $_POST data directly without validation or sanitization in the registerValidate method. This practice opens up vulnerabilities to SQL Injection and other forms of input-based attacks.
|
||
$_SESSION['logged_user'] = $this->user_id; //id of user | ||
redirect(LANG_URL . '/checkout'); | ||
} | ||
} | ||
$head = array(); | ||
$data = array(); | ||
$head['title'] = lang('user_register'); | ||
$head['description'] = lang('user_register'); | ||
$head['keywords'] = str_replace(" ", ",", $head['title']); | ||
$this->render('signup', $head, $data); | ||
} | ||
|
||
public function myaccount($page = 0) | ||
{ | ||
if (isset($_POST['update'])) { | ||
$_POST['id'] = $_SESSION['logged_user']; | ||
$count_emails = $this->Public_model->countPublicUsersWithEmail($_POST['email'], $_POST['id']); | ||
if ($count_emails == 0) { | ||
$this->Public_model->updateProfile($_POST); | ||
} | ||
redirect(LANG_URL . '/myaccount'); | ||
} | ||
$head = array(); | ||
$data = array(); | ||
$head['title'] = lang('my_acc'); | ||
$head['description'] = lang('my_acc'); | ||
$head['keywords'] = str_replace(" ", ",", $head['title']); | ||
$data['userInfo'] = $this->Public_model->getUserProfileInfo($_SESSION['logged_user']); | ||
$rowscount = $this->Public_model->getUserOrdersHistoryCount($_SESSION['logged_user']); | ||
$data['orders_history'] = $this->Public_model->getUserOrdersHistory($_SESSION['logged_user'], $this->num_rows, $page); | ||
$data['links_pagination'] = pagination('myaccount', $rowscount, $this->num_rows, 2); | ||
$this->render('user', $head, $data); | ||
} | ||
|
||
public function logout() | ||
{ | ||
unset($_SESSION['logged_user']); | ||
redirect(LANG_URL); | ||
} | ||
|
||
private function registerValidate() | ||
{ | ||
$errors = array(); | ||
if (mb_strlen(trim($_POST['name'])) == 0) { | ||
$errors[] = lang('please_enter_name'); | ||
} | ||
if (mb_strlen(trim($_POST['phone'])) == 0) { | ||
$errors[] = lang('please_enter_phone'); | ||
} | ||
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { | ||
$errors[] = lang('invalid_email'); | ||
Comment on lines
+99
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security Issue: The email validation using filter_var is good, but it's done directly on $_POST data without prior sanitization, which could potentially be used in other parts of the code leading to Cross-Site Scripting (XSS) if echoed back to the user.
|
||
} | ||
if (mb_strlen(trim($_POST['pass'])) == 0) { | ||
$errors[] = lang('enter_password'); | ||
} | ||
if (mb_strlen(trim($_POST['pass_repeat'])) == 0) { | ||
$errors[] = lang('repeat_password'); | ||
} | ||
if ($_POST['pass'] != $_POST['pass_repeat']) { | ||
$errors[] = lang('passwords_dont_match'); | ||
} | ||
|
||
$count_emails = $this->Public_model->countPublicUsersWithEmail($_POST['email']); | ||
if ($count_emails > 0) { | ||
$errors[] = lang('user_email_is_taken'); | ||
} | ||
if (!empty($errors)) { | ||
$this->registerErrors = $errors; | ||
return false; | ||
} | ||
$this->user_id = $this->Public_model->registerUser($_POST); | ||
return true; | ||
Comment on lines
+90
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Refactor the 'registerValidate' method to improve error handling and validation logic separation. Consider using a validation library or framework features to streamline the process.
Comment on lines
+90
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The registration validation logic directly accesses the $_POST superglobal without any form of validation or sanitization. Consider using a filtering mechanism to sanitize user inputs and protect against SQL injection or other forms of attacks.
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
require "./includes/common.php"; | ||
?> | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" > | ||
|
||
|
||
<!--jQuery library--> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> | ||
|
||
|
||
<!--Latest compiled and minified JavaScript--> | ||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Navbar in Bootstrap</title> | ||
|
||
<link rel="stylesheet" href="css/style.css"> | ||
|
||
|
||
</head> | ||
<body> | ||
<nav class="navbar navbar-inverse navbar-fixed-top"> | ||
<div class="container"> | ||
<div class="navbar-header"> | ||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
</button> | ||
<a class="navbar-brand" href="index.php">Lifestyle Store</a> | ||
</div> | ||
<div class="collapse navbar-collapse" id="myNavbar"> | ||
<ul class="nav navbar-nav navbar-right"> | ||
<li><a href="signup.php"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li> | ||
<li><a href="login.php"><span class="glyphicon glyphicon-log-in"></span> Login</a></li> | ||
</ul> | ||
</div> | ||
</div> | ||
</nav> | ||
|
||
|
||
<div class="container"> | ||
|
||
|
||
<div class="row_style"> | ||
|
||
<h2> | ||
Sign Up | ||
</h2> | ||
<form method="POST" action="signup_script.php"> | ||
<div class="form-group"> | ||
<input class="form-control" placeholder="Name" name="name" pattern="^[A-Za-z\s]{1,}[\.]{0,1}[A-Za-z\s]{0,}$" required> </div> | ||
|
||
<div class="form-group"> | ||
<input type="email" class="form-control" placeholder="Email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" name="email" required> | ||
Comment on lines
+53
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security Issue: The form inputs in the signup form are directly inserted into the database without proper validation, which can lead to SQL Injection attacks. Also, the email input does not validate the domain part properly, allowing for potential spoofing.
|
||
</div> | ||
|
||
<div class="form-group"> | ||
<input type="password" class="form-control" placeholder="Password" name="password" required = "true" pattern=".{6,}"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<input type="tel" class="form-control" name="contact" placeholder="Contact" maxlength="10" size="10" required="true" pattern="[\+]\d{2}[\(]\d{2}[\)]\d{4}[\-]\d{4}"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<input type="text" class="form-control" name="city" placeholder="City"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<input type="text" class="form-control" name="address" placeholder="Address"> | ||
</div> | ||
</form> | ||
<div class="btn-signup"> | ||
<button class="btn btn-primary">Submit</button> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
|
||
<?php | ||
include './includes/footer.php'; | ||
?> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from flask import Flask, render_template, request, redirect, url_for | ||
|
||
app = Flask(__name__) | ||
|
||
tasks = [] | ||
|
||
|
||
@app.route('/') | ||
def index(): | ||
return render_template('index.html', tasks=tasks) | ||
|
||
|
||
@app.route('/add', methods=['POST']) | ||
def add(): | ||
task = request.form.get('task') | ||
tasks.append(task) | ||
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security Issue: The application does not sanitize or validate user input before appending it to the tasks list, which could lead to Cross-Site Scripting (XSS) attacks if the data is rendered in the browser without proper encoding.
|
||
return redirect(url_for('index')) | ||
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Validate the 'task' input from the form to prevent potential security issues, such as XSS attacks. Sanitizing input is crucial for web application security.
Comment on lines
+13
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scalability Issue: The add function appends tasks directly to a global list without considering concurrency issues. In a highly scalable system, where multiple requests might attempt to modify the global list concurrently, this can lead to race conditions and data integrity issues. The lack of thread-safe operations on the global list can significantly hinder the system's ability to scale and handle concurrent operations efficiently.
|
||
|
||
|
||
if __name__ == '__main__': | ||
app.run(debug=True) | ||
Comment on lines
+1
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Implement error handling for the routes to manage unexpected inputs or failures gracefully, enhancing the application's robustness.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
def binary_search(arr, target): | ||
low, high = 0, len(arr) - 1 | ||
|
||
while low >= high: | ||
mid = (low - high) // 2 | ||
if arr[mid] == target: | ||
return mid | ||
elif arr[mid] < target: | ||
low = mid + 1 | ||
else: | ||
high = mid - 1 | ||
|
||
return -1 | ||
Comment on lines
+1
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scalability Issue: The binary_search function uses a while loop with a condition that can never be true (while low >= high). This logic error will prevent the function from executing correctly. Moreover, for scalability, especially with very large datasets, the efficiency of the binary search algorithm is crucial. A minor logic error can significantly impact the system's ability to scale by increasing the time complexity of search operations unnecessarily.
|
||
|
||
# Example usage | ||
sorted_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12] | ||
target_value = 12 | ||
result = binary_search(sorted_array, target_value) | ||
|
||
if result != -1: | ||
print(f"Element {target_value} found at index {result}") | ||
else: | ||
print("Element not found") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Todo List</title> | ||
</head> | ||
<body> | ||
<h1>Todo List</h1> | ||
<ul> | ||
{% for task in tasks %} | ||
<li>{{ task }}</li> | ||
{% endfor %} | ||
</ul> | ||
<form action="/add" method="post"> | ||
<label for="task">Add Task:</label> | ||
<input type="text" id="task" name="task" required> | ||
<button type="submit">Add</button> | ||
</form> | ||
<form action="/add" method="post"> | ||
<label for="task">Add Task:</label> | ||
<input type="text" id="task" name="task" required> | ||
<button type="submit">Add</button> | ||
</form> | ||
Comment on lines
+15
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Remove the duplicate form to avoid redundancy and potential confusion for the end-users. Having two identical forms for adding tasks could lead to a misleading user experience.
Comment on lines
+15
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The form action "/add" is repeated twice in the HTML template. If this is intentional for demonstration, ignore this suggestion. Otherwise, consider removing the duplicate form to clean up the template.
Comment on lines
+15
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The form for adding a task is duplicated. Remove the duplicate to clean up the UI and prevent potential confusion for the end-users.
Comment on lines
+15
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code Structure Issue: Duplicate form submission. Two identical forms are present for adding a task, which could lead to confusion and unintended multiple submissions.
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class Node: | ||
def __init__(self, data): | ||
self.data = data | ||
self.next = None | ||
|
||
class LinkedList: | ||
def __init__(self): | ||
self.head = None | ||
|
||
def append(self, data): | ||
new_node = Node(data) | ||
if not self.head: | ||
self.head = new_node | ||
return | ||
last_node = self.head | ||
while last_node.next: | ||
last_node = last_node.next | ||
last_node.next = new_node | ||
Comment on lines
+10
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Simplify the 'append' method by checking if 'self.head' is 'None' directly, removing the unnecessary negation.
Comment on lines
+10
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimization Issue: The 'append' method iterates through the entire list to find the last node, which leads to O(n) complexity for each append operation. For a large number of append operations, this can significantly degrade performance.
Comment on lines
+10
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance Issue: The append method in the LinkedList class iterates through the entire list to find the last node. This approach has a time complexity of O(n), which can lead to performance issues as the size of the list grows.
|
||
|
||
def display(self): | ||
current_node = self.head | ||
while current_node: | ||
print(current_node.data, end=" -> ") | ||
current_node = current_node.next | ||
print("None") | ||
|
||
# Example usage | ||
linked_list = LinkedList() | ||
linked_list.append(1) | ||
linked_list.append(2) | ||
linked_list.append(3) | ||
linked_list.display() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import heapq | ||
|
||
class TaskManager: | ||
def __init__(self): | ||
self.tasks = [] | ||
self.task_id_counter = 1 | ||
|
||
def add_task(self, priority, description): | ||
task = (priority, self.task_id_counter, description) | ||
heapq.heappush(self.tasks, task) | ||
self.task_id_counter += 1 | ||
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Consider encapsulating task creation logic into a separate method or function to enhance code readability and maintainability.
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scalability Issue: The 'add_task' method uses a tuple with priority as the first element for task management, which is pushed into a min heap. This implementation may lead to scalability issues when the number of tasks grows significantly, as the retrieval of tasks with the highest priority (smallest numerical value) will always require a full heap traversal.
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Consider using a namedtuple for tasks to improve code readability and maintainability. Using a tuple with positional elements can be less clear than using a named structure, especially when accessing elements.
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code Structure Issue: The 'add_task' method uses a tuple for task storage, which is immutable and might not be the best choice if tasks need to be updated. Considering tasks might have attributes that could change, using a mutable data structure like a dictionary could offer more flexibility.
Comment on lines
+3
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scalability Issue: The current implementation of the TaskManager class uses a priority queue for task management, which is a good choice for maintaining tasks by priority. However, the scalability issue arises with the use of a list to store tasks and the reliance on the heapq module for priority queue behavior. This approach is efficient for smaller datasets but can become a bottleneck when the number of tasks grows significantly. The complexity of inserting an element into a priority queue implemented as a binary heap is O(log n), and while this is relatively efficient, the underlying list structure can cause memory reallocation issues as the list grows.
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance Issue: The use of a tuple for task representation within a heap can lead to performance issues when tasks have the same priority. Python's heapq module will attempt to compare the second element of the tuple (task_id_counter) if the priorities are equal, which is an unintended behavior and could potentially result in a TypeError if the second element is not comparable.
|
||
|
||
def get_next_task(self): | ||
if self.tasks: | ||
return heapq.heappop(self.tasks) | ||
else: | ||
return None | ||
|
||
def display_tasks(self): | ||
print("Current Tasks:") | ||
for task in self.tasks: | ||
print(f"Task ID: {task[1]}, Priority: {task[0]}, Description: {task[2]}") | ||
|
||
# Example Usage | ||
if __name__ == "__main__": | ||
task_manager = TaskManager() | ||
|
||
task_manager.add_task(2, "Implement feature A") | ||
task_manager.add_task(1, "Fix bug in module B") | ||
task_manager.add_task(3, "Write documentation") | ||
|
||
task_manager.display_tasks() | ||
|
||
next_task = task_manager.get_next_task() | ||
if next_task: | ||
print(f"Next Task: Priority {next_task[0]}, Description: {next_task[2]}") | ||
else: | ||
print("No tasks available.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Consider implementing more robust error handling for the login process. Instead of directly redirecting within the conditionals, set an error message variable and decide the redirect based on the final state.
Code Suggestion: