Thông tin tài khoản
-
+
+
+
+
+ Hello
+ Hello
+
+
+
+
+
+ Hello
+
diff --git a/frontend-manager-student/src/redux/store.js b/frontend-manager-student/src/redux/store.js
index 16b4458..3f8553e 100644
--- a/frontend-manager-student/src/redux/store.js
+++ b/frontend-manager-student/src/redux/store.js
@@ -12,10 +12,9 @@ const rootReducer = (state, action) => {
return AuthenticationSlice(state, action);
};
-let store;
-store = configureStore({
+const store = configureStore({
reducer: {
- auth_user: AuthenticationSlice,
+ auth_student: AuthenticationSlice,
reducer: rootReducer,
},
middleware:
diff --git a/frontend-manager-student/src/redux/student/authentication_slice/auth_slice.js b/frontend-manager-student/src/redux/student/authentication_slice/auth_slice.js
index de41113..2ae0ccf 100644
--- a/frontend-manager-student/src/redux/student/authentication_slice/auth_slice.js
+++ b/frontend-manager-student/src/redux/student/authentication_slice/auth_slice.js
@@ -2,35 +2,64 @@
import { createSlice } from '@reduxjs/toolkit';
//! CALL API REDUX THUNK
-import { Login_Mssv_Initial } from './auth_thunk';
+import { Login_Mssv_Initial, Profile_Student_Initial, Renew_Token_Student_Initial } from './auth_thunk';
const initialState = {
loading: false,
error: null,
- student_auth: [],
+ token_student: null,
+ profile_student: null,
};
const Authentication = createSlice({
- name: 'STUDENT AUTH',
+ name: 'AUTH STUDENT',
initialState,
reducers: {
- reset_auth: (state) => {
- state.student_auth = [];
+ reset_profile: (state) => {
+ state.profile_student = null;
+ },
+ reset_token: (state) => {
+ state.token_student = null;
},
},
extraReducers: {
- //* Login Email_Phone have Password
+ //* POST LOGIN MSSV STUDENT
[Login_Mssv_Initial.pending]: (state, action) => {
state.loading = true;
},
[Login_Mssv_Initial.fulfilled]: (state, action) => {
state.loading = false;
- state.student_auth = action.payload;
+ state.token_student = action.payload;
},
[Login_Mssv_Initial.rejected]: (state, action) => {
state.loading = false;
state.error = action.payload;
},
+
+ //* GET PROFILE
+ [Profile_Student_Initial.pending]: (state, action) => {
+ state.loading = true;
+ },
+ [Profile_Student_Initial.fulfilled]: (state, action) => {
+ state.loading = false;
+ state.profile_student = action.payload;
+ },
+ [Profile_Student_Initial.rejected]: (state, action) => {
+ state.loading = false;
+ state.error = action.payload;
+ },
+ //* GET RE_NEW_TOKEN
+ [Renew_Token_Student_Initial.pending]: (state, action) => {
+ state.loading = true;
+ },
+ [Renew_Token_Student_Initial.fulfilled]: (state, action) => {
+ state.loading = false;
+ state.token_student = action.payload;
+ },
+ [Renew_Token_Student_Initial.rejected]: (state, action) => {
+ state.loading = false;
+ state.error = action.payload;
+ },
},
});
const AuthenticationSlice = Authentication.reducer;
diff --git a/frontend-manager-student/src/redux/student/authentication_slice/auth_thunk.js b/frontend-manager-student/src/redux/student/authentication_slice/auth_thunk.js
index 5143d44..6028af7 100644
--- a/frontend-manager-student/src/redux/student/authentication_slice/auth_thunk.js
+++ b/frontend-manager-student/src/redux/student/authentication_slice/auth_thunk.js
@@ -1,6 +1,6 @@
//! LIBRARY
-import axios from 'axios';
import { createAsyncThunk } from '@reduxjs/toolkit';
+import axios from 'axios';
//! NOTIFICATION
import NOTIFICATION from 'utils/notification';
@@ -9,8 +9,10 @@ import NOTIFICATION from 'utils/notification';
import API_STUDENT from 'api/api_user';
//! SHARE
-import HELPERS from 'utils/helper';
+import CONSTANTS from 'configs/constants';
+import TEXT_NOTIFICATION from 'configs/text_notification';
import { setToken } from 'utils/auth';
+import HELPERS from 'utils/helper';
/**
* @author Nguyễn Tiến Tài
@@ -42,20 +44,109 @@ export const Login_Mssv_Initial = createAsyncThunk('student/mssv', async ({ mssv
//Check data
if (successData) {
- const success_general = {
- message: successData?.element?.result || successData.message,
- status: successData.status,
- access_token: successData?.element?.result?.access_token,
- };
+ // return result data
+ const result_data = HELPERS.takeDataResponse(successData);
// Save LocalStorage
- setToken(success_general.access_token);
+ setToken(CONSTANTS.AUTH_TOKEN, result_data.access_token);
// Notification Success
- NOTIFICATION.notifySuccess('Đăng nhập thành công' || successData.message);
+ NOTIFICATION.notifySuccess(TEXT_NOTIFICATION.NOTIFICATION_LOGIN_SUCCESS || result_data.message);
// return result data
- return successData;
+ return result_data;
+ }
+ } catch (error) {
+ if (error) {
+ //Take response Error
+ const errorData = error.response.data;
+
+ // return result data
+ const result_data = HELPERS.takeDataResponse(errorData);
+
+ if (errorData) {
+ // Notification Error
+ NOTIFICATION.notifyError(result_data.data || result_data.message);
+ }
+
+ // return error
+ return rejectWithValue(result_data);
+ }
+ }
+});
+
+/**
+ * @author Nguyễn Tiến Tài
+ * @created_at 03/03/2023
+ * @descriptionKey Call api Profile Student
+ * @function Profile_Student_Initial
+ * @return {Object}
+ */
+export const Profile_Student_Initial = createAsyncThunk('student/profile', async (_, { rejectWithValue }) => {
+ try {
+ //Call Api axios
+ const response = await axios.get(`${API_STUDENT.PROFILE_STUDENT}`, {
+ headers: HELPERS.headerBrowser(),
+ withCredentials: true,
+ });
+
+ //Take response Success
+ const successData = response.data;
+
+ //Check data
+ if (successData) {
+ // return result data
+ const result_data = HELPERS.takeDataResponse(successData);
+ return result_data;
+ }
+ } catch (error) {
+ if (error) {
+ //Take response Error
+ const errorData = error.response.data;
+
+ if (errorData) {
+ const error_general = {
+ message: errorData?.element?.result || errorData.message,
+ status: errorData.status,
+ };
+
+ // Notification Error
+ NOTIFICATION.notifyError(error_general.message);
+ }
+
+ // return error
+ return rejectWithValue(errorData);
+ }
+ }
+});
+
+/**
+ * @author Nguyễn Tiến Tài
+ * @created_at 03/03/2023
+ * @descriptionKey Call api renew token Student
+ * @function Renew_Token_Student_Initial
+ * @return {Object}
+ */
+export const Renew_Token_Student_Initial = createAsyncThunk('student/new/token', async (_, { rejectWithValue }) => {
+ try {
+ //Call Api axios
+ const response = await axios.get(`${API_STUDENT.RE_NEW_TOKEN_STUDENT}`, {
+ headers: HELPERS.headerBrowser(),
+ withCredentials: true,
+ });
+
+ //Take response Success
+ const successData = response.data;
+
+ //Check data
+ if (successData) {
+ // return result data
+ const result_data = HELPERS.takeDataResponse(successData);
+
+ // Save LocalStorage
+ setToken(CONSTANTS.AUTH_TOKEN, result_data.data.access_token);
+
+ return result_data;
}
} catch (error) {
if (error) {
diff --git a/frontend-manager-student/src/styles/_base.scss b/frontend-manager-student/src/styles/_base.scss
index 38b8a72..2ba8488 100644
--- a/frontend-manager-student/src/styles/_base.scss
+++ b/frontend-manager-student/src/styles/_base.scss
@@ -87,7 +87,6 @@ img {
.main {
margin-top: $header-height;
margin-bottom: 2rem;
- min-height: 100vh;
@include tablet {
margin-top: calc(#{$header-tablet-height} + 20px);
diff --git a/frontend-manager-student/src/styles/pages/_user_profile.scss b/frontend-manager-student/src/styles/pages/_user_profile.scss
new file mode 100644
index 0000000..f44b060
--- /dev/null
+++ b/frontend-manager-student/src/styles/pages/_user_profile.scss
@@ -0,0 +1,3 @@
+.profile {
+ padding: 0 8rem;
+}
diff --git a/frontend-manager-student/src/styles/style.scss b/frontend-manager-student/src/styles/style.scss
index 2dc84a5..b751d5d 100644
--- a/frontend-manager-student/src/styles/style.scss
+++ b/frontend-manager-student/src/styles/style.scss
@@ -15,3 +15,4 @@
@import './pages/book';
@import './pages/detail-book';
@import './pages/change-password';
+@import './pages/user_profile';
diff --git a/frontend-manager-student/src/utils/auth.js b/frontend-manager-student/src/utils/auth.js
index 3a1a415..6231617 100644
--- a/frontend-manager-student/src/utils/auth.js
+++ b/frontend-manager-student/src/utils/auth.js
@@ -29,8 +29,8 @@ export function getDeviceId() {
* @function getToken
* @return {String}
*/
-export function getToken() {
- return localStorage.getItem(CONSTANTS.AUTH_TOKEN);
+export function getToken(key) {
+ return localStorage.getItem(key);
}
/**
@@ -40,6 +40,6 @@ export function getToken() {
* @function getToken
* @return {String}
*/
-export function setToken(token) {
- return localStorage.setItem(CONSTANTS.AUTH_TOKEN, JSON.stringify(token));
+export function setToken(key, value) {
+ return localStorage.setItem(key, value);
}
diff --git a/frontend-manager-student/src/utils/dummy.js b/frontend-manager-student/src/utils/dummy.js
new file mode 100644
index 0000000..1f9d6df
--- /dev/null
+++ b/frontend-manager-student/src/utils/dummy.js
@@ -0,0 +1,51 @@
+/**
+ * @author Nguyễn Tiến Tài
+ * @created_at 04/03/2023
+ * @descriptionKey Nav Info
+ */
+export const navInfo = [
+ {
+ displayText: 'Giới thiệu',
+ path: '/',
+ submenu: [
+ {
+ displayText: 'Submenu 1',
+ path: '/sub',
+ },
+ {
+ displayText: 'Submenu 1',
+ path: '/sub',
+ },
+ {
+ displayText: 'Submenu 1',
+ path: '/sub',
+ },
+ ],
+ },
+ {
+ displayText: 'Tra cứu',
+ path: '/book',
+ submenu: [
+ {
+ displayText: 'Thể loại',
+ path: '/category',
+ },
+ {
+ displayText: 'Tất cả tài liệu',
+ path: '/book',
+ },
+ {
+ displayText: 'Submenu 1',
+ path: '/sub',
+ },
+ ],
+ },
+ {
+ displayText: 'Phụ kiện',
+ path: '/accessories',
+ },
+ {
+ displayText: 'Liên hệ',
+ path: '/contact',
+ },
+];
diff --git a/frontend-manager-student/src/utils/helper.js b/frontend-manager-student/src/utils/helper.js
index 786da33..275386d 100644
--- a/frontend-manager-student/src/utils/helper.js
+++ b/frontend-manager-student/src/utils/helper.js
@@ -1,5 +1,9 @@
+//!LIBRARY
+import jwt_decode from 'jwt-decode';
+
//! SHARE
import { getDeviceId, getToken } from './auth';
+import CONSTANTS from 'configs/constants';
const HELPERS = {
/**
@@ -12,23 +16,75 @@ const HELPERS = {
headerBrowser: () => {
// add the authorization to the headers
const headers = {
+ 'Content-Type': 'application/json',
'X-DEVICE-ID': getDeviceId(),
- 'X-OS-TYPE': 'web',
- 'X-OS-VERSION': '1.0',
- 'X-APP-VERSION': '1.0',
+ 'X-OS-TYPE': CONSTANTS.OS_TYPE_HEADER,
+ 'X-OS-VERSION': CONSTANTS.OS_VERSION_HEADER,
+ 'X-APP-VERSION': CONSTANTS.APP_VERSION_HEADER,
'X-DEVICE-NAME': window.navigator.userAgent,
};
- const token = getToken();
+ const token = getToken(CONSTANTS.AUTH_TOKEN);
if (token) {
headers.authorization = token ? `Bearer ${token}` : null;
}
return headers;
},
+ /**
+ * @author Nguyễn Tiến Tài
+ * @created_at 02/03/2023
+ * @descriptionKey Form input
+ * @return {Object}
+ */
formDataGeneral: (target) => {
const formData = new FormData(target);
return Object.fromEntries(formData);
},
+ /**
+ * @author Nguyễn Tiến Tài
+ * @created_at 04/03/2023
+ * @descriptionKey Convert data response Thunk
+ * @return {Object}
+ */
+ takeDataResponse: (successData) => {
+ if (successData.element) {
+ return {
+ status: successData.status,
+ message: successData.message,
+ data: successData.element.result || null,
+ };
+ }
+ return {
+ status: successData.status,
+ message: successData.message,
+ };
+ },
+ /**
+ * @author Nguyễn Tiến Tài
+ * @created_at 04/03/2023
+ * @descriptionKey Check token access expired
+ * @return {Object}
+ */
+ isTokenExpired: (access_token) => {
+ //Check token not found
+ if (!access_token) {
+ return false;
+ }
+ try {
+ //Take Data from token
+ const decodedToken = jwt_decode(access_token);
+
+ // Expired
+ const currentTime = Math.floor(Date.now() / 1000);
+ if (decodedToken.exp < currentTime) {
+ return false;
+ }
+ // Due
+ return true;
+ } catch (err) {
+ return false;
+ }
+ },
};
export default HELPERS;
diff --git a/frontend-manager-student/src/utils/notification.js b/frontend-manager-student/src/utils/notification.js
index 9dd9042..d02aa8f 100644
--- a/frontend-manager-student/src/utils/notification.js
+++ b/frontend-manager-student/src/utils/notification.js
@@ -27,7 +27,6 @@ const NOTIFICATION = {
* @descriptionKey error
*/
notifyError(message) {
- console.log(message);
return toast.error(message, {
pposition: toast.POSITION.TOP_RIGHT,
autoClose: CONSTANTS.AUTO_CLOSE,
diff --git a/server-media-service/src/share/middlewares/access.token.middleware.js b/server-media-service/src/share/middlewares/access.token.middleware.js
index 5b9bd26..89ee2c1 100644
--- a/server-media-service/src/share/middlewares/access.token.middleware.js
+++ b/server-media-service/src/share/middlewares/access.token.middleware.js
@@ -39,7 +39,7 @@ const accessTokenMiddleware = async (req, res, next) => {
// Take token
const { device_id } = req.device;
- console.log(device_id, 'device_id')
+
// Take data device student
const data_device = await user_device_model.getDeviceId(
{ device_uuid: device_id },