-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
183 lines (160 loc) · 7.92 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Trang chủ - PT Travel</title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<!-- <link rel="stylesheet" href="css/style.css" /> -->
<!-- Icon FontAwesome v6.4.2 -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.4.2/css/all.css" />
<!-- CSS Boostrap 5 -->
<link href="css/bootstrap.min.css" rel="stylesheet" />
<!-- JavaScript Boostrap 5 -->
<script src="js/bootstrap.bundle.js"></script>
<!-- Angular -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<!-- AngularJS Route -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-route.js"></script>
<!-- jQuery v3.7.0 -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
</head>
<body ng-app="myApp">
<div ng-controller="HeaderController" ng-include="'header.html'"></div>
<div ng-view></div>
<div ng-include="'footer.html'"></div>
<script>
var app = angular.module("myApp", ["ngRoute"]);
app.config(function ($routeProvider) {
$routeProvider
.when("/", { templateUrl: "main.html", controller: "myCtrl" })
.when("/detail/:id", { templateUrl: "oneProduct.html", controller: "myCtrl" })
.when("/du-lich-nuoc-ngoai", { templateUrl: "tour-nuoc-ngoai.html", controller: "myCtrl" })
.when("/login", { templateUrl: "login.html", controller: "LoginController" })
.when("/register", { templateUrl: "register.html", controller: "RegisterController" })
.otherwise({ templateUrl: "index.html", controller: "myCtrl" })
});
app.controller('HeaderController', function ($scope) {
// Kiểm tra xem người dùng đã đăng nhập hay chưa
var isLoggedIn = false;
var userData = localStorage.getItem('loggedInUser');
if (userData) {
// Đã đăng nhập
isLoggedIn = true;
// Lưu thông tin người dùng vào $scope
$scope.loggedInUser = JSON.parse(userData);
}
// Gán biến isLoggedIn vào $scope để sử dụng trên giao diện
$scope.isLoggedIn = isLoggedIn;
// Hàm đăng xuất
$scope.logout = function () {
// Xóa thông tin người dùng khỏi localStorage
localStorage.removeItem('loggedInUser');
// Đặt lại trạng thái đăng nhập về false
$scope.isLoggedIn = false;
// Xóa thông tin người dùng khỏi $scope
$scope.loggedInUser = null;
};
});
app.controller("myCtrl", function ($scope, $rootScope, $routeParams, $http) {
//Khai báo 1 mảng products rỗng
$scope.products = [];
//Đọc dữ liệu từ json server rồi đổ mảng vào trong products
$http.get("http://localhost:3000/products")
.then(function (reponse) {
$scope.products = reponse.data;
console.log($scope.products);
// Lấy sản phẩm chi tiết thông qua id truyền vào routeParams
$scope.detailPro = $scope.products.find(item => item.id == $routeParams.id);
});
$scope.limitToShow = 4;
$scope.loadMore = function () {
$scope.limitToShow += 4;
};
$scope.loadDete = function () {
$scope.limitToShow = 4;
}
// All tour
$scope.limitToAll = 9;
$scope.orderByAll = 'id';
$scope.limitPrice = 'price';
$scope.moiNhat = function () {
$scope.orderByAll = '-id';
}
$scope.tangdan = function () {
$scope.orderByAll = 'price';
}
$scope.giamdan = function () {
$scope.orderByAll = '-price';
}
$scope.huybo = function () {
$scope.orderByAll = 'id';
}
});
// Hàm loại bỏ dấu và chuyển đổi thành chữ không dấu
function removeDiacritics(str) {
return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
}
// Đăng nhập
app.controller('LoginController', function ($scope, $http) {
$scope.user = {};
// Hàm xử lý khi người dùng nhấn nút Đăng nhập
$scope.submitLoginForm = function () {
// Gọi API để lấy danh sách người dùng từ server
$http.get('http://localhost:3000/users')
.then(function (response) {
// Lấy danh sách người dùng từ response.data
var users = response.data;
// Tìm kiếm trong danh sách người dùng để kiểm tra đăng nhập
var loggedInUser = users.find(function (user) {
return user.email === $scope.user.email && user.password === $scope.user.password;
});
if (loggedInUser) {
// Lưu thông tin người dùng vào localStorage khi đăng nhập thành công
localStorage.setItem('loggedInUser', JSON.stringify(loggedInUser));
// Thực hiện các thao tác khác sau khi đăng nhập thành công
alert('Đăng nhập thành công!');
window.location.href = 'index.html#!/';
} else {
// Đăng nhập thất bại
alert('Đăng nhập thất bại. Vui lòng kiểm tra lại email và mật khẩu.');
}
});
};
});
// Đăng ký
app.controller('RegisterController', function ($scope, $http) {
// Khởi tạo đối tượng đăng ký
$scope.user = {};
// Hàm xử lý khi người dùng nhấn nút Đăng ký
$scope.submitRegistration = function () {
if ($scope.registrationForm.$valid) {
// Loại bỏ dấu và chuyển thành chữ không dấu
var processedName = removeDiacritics($scope.user.name);
// Xóa khoảng trắng và chuyển thành chữ thường
processedName = processedName.replace(/\s+/g, '').toLowerCase();
// Gán giá trị cho username
$scope.user.username = processedName;
$scope.user.role = 0;
// Gọi API hoặc xử lý dữ liệu ở đây
$http.post("http://localhost:3000/users", $scope.user)
.then(function (response) {
// Xử lý khi đăng ký thành công
alert("Đăng ký thành công!");
})
.catch(function (error) {
// Xử lý khi đăng ký thất bại
alert("Đăng ký thất bại:", error);
});
} else {
// Hiển thị thông báo lỗi nếu form chưa hợp lệ
console.error('Form đăng ký chưa hợp lệ.');
}
};
});
</script>
<!-- <script src="js/script.js"></script> -->
</body>
</html>