sử dụng authen.js nằm riêng để nhúng vào nhiều trang sau này.
-
Khi vào trang chủ
/, dựa vàoaccessTokenđể lấy thông tin usertokenđã được lưu ở client, sau quá trình đăng nhập ở/login.html
-
gọi profile api để lấy thông tin của user,
- hiển thị thông tin user (username) trên trang chủ
-
trường hợp không truy cập được, chưa có
accessTokenhoặc không lấy profile data thì trỏ về trang/login.html
-
Nếu đã đăng nhập thì trỏ về trang chủ
/ -
hiển thị form login
-
call api để lấy thông tin đăng nhập
- POST
/api/Users/login:
- POST
-
đăng nhập thành công, lưu
accessTokenvà trỏ về trang chủ.
hình ảnh được upload từ Ckeditor sẽ được xử lý bởi loopback API Container
- hình ảnh được upload trong CKeditor5
- cấu hình
cloudServices
- cấu hình
.create(document.querySelector('#ckeditor5-tabs-content-classic'),{
cloudServices: {
tokenUrl: '/api/containers/get-token',
uploadUrl: '/api/containers/folder1/upload'
}
})
- cấu hình
tokenUrl
//models/container.js
Container.getToken = function(cb) {
cb(null, 'dummy-token');
};
Container.remoteMethod(
'getToken', {
http: {
path: '/get-token',
verb: 'get'
},
returns: { type: 'file', root: true }
}
);
- truy cập link
/uploaded/{file_name}
//models/container.js
Container.afterRemote('upload', function(context, remoteMethodOutput, next) {
context.result = {
default: `/uploaded/${remoteMethodOutput.result.files.file[0].name}`
};
next();
});
- cấu hình loopback static
"loopback#static": [
{
"name": "uploaded",
"paths": ["/uploaded"],
"params": "server/storage/folder1"
},
{
"name": "root",
"paths": ["/"],
"params": "$!../web"
}
]
- lưu trữ tại thư mục
storage/folder1
//datasource.json
"root": "./server/storage"