Skip to content

Bugs fix #658

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

Merged
merged 7 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import "./App.css";
import { Provider } from "react-redux";
import store from "./store";
import jwt_decode from "jwt-decode";
import { setAuthToken } from "./utils/setAuthToken";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if authorization is not required in header, remove the function too instead of just removing from here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not understand.

import { allowCredentialsInHeader } from "./utils/allowCredentialsInHeader";
import { setCurrentUser, logoutUser } from "./actions/authAction";
import "./css/main.scss";
import ReactGA from "react-ga";

allowCredentialsInHeader()

function App() {
useEffect(() => {
ReactGA.initialize("UA-173245995-1");
setAuthToken()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might effect Analytics part cc @AuraOfDivinity

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was already there!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I make it work as componentDidMount?


});
return (
<Provider store={store}>
Expand Down
39 changes: 17 additions & 22 deletions src/actions/adminAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import axios from 'axios'
import { errorHandler } from '../utils/errorHandler'
import { setRequestStatus } from '../utils/setRequestStatus'
import { SET_ADMIN, GET_ADMIN } from './types'
import { setAuthToken } from '../utils/setAuthToken'
import jwt_decode from 'jwt-decode';
import { setCurrentUser } from './authAction'
import { BASE_URL } from './baseApi'
Expand All @@ -27,31 +26,27 @@ export const createAdmin = (adminInfo) => async (dispatch) => {
export const loginAdmin = (adminInfo, history) => async (dispatch) => {
try {
const res = await axios.post(`${BASE_URL}/auth/login/`, adminInfo)
dispatch(setRequestStatus(false));
if (res.status === 200) {
dispatch(setRequestStatus(false));
if (res.status === 200) {
dispatch(setRequestStatus(true));

const token = res.data.token;
dispatch(setRequestStatus(true));
// update state with user
localStorage.setItem('userId', res.data.user)
dispatch(setCurrentUser(res.data.user._id));

localStorage.setItem("jwtToken", (token));
setAuthToken(token);
// update localStorage with admin status
localStorage.setItem('username', `${res.data.user.name.firstName} ${res.data.user.name.lastName}`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local storage is not that secure!!
Try to come up with some secure approach!!
As of now, you can go with it but it's not acceptable at the production level

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting names in local storage won't do any harm as the protected resources sent from the server need that token in cookie.

localStorage.setItem('admin', res.data.user.isAdmin)
localStorage.setItem('ticketModerator', res.data.user.isTicketsModerator)
localStorage.setItem('orgId', res.data.user.orgId);

// update state with user
const decodedData = await jwt_decode(token);
localStorage.setItem('userId', decodedData._id)
dispatch(setCurrentUser(decodedData));

// update localStorage with admin status
localStorage.setItem('admin', true)

dispatch({
type: SET_ADMIN,
payload: true
})

history.push("/dashboard");
dispatch({
type: SET_ADMIN,
payload: res.data.user.isAdmin
})
history.push("/dashboard");
}
} catch (error) {
dispatch(errorHandler(error))
}
}
}
3 changes: 0 additions & 3 deletions src/actions/authAction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SET_CURRENT_USER, GET_USER_PROFILE, PASSWORD_SUCCESSFULLY_CHANGED, PASSWORD_CHANGE_REQUEST_SUCCESS, SET_ADMIN } from './types';
import axios from 'axios';
import { setAuthToken } from '../utils/setAuthToken';
import { errorHandler } from '../utils/errorHandler';
import { setRequestStatus } from '../utils/setRequestStatus';
import { BASE_URL } from './baseApi';
Expand Down Expand Up @@ -146,8 +145,6 @@ export const logoutUser = () => async (dispatch) => {
const orgId = localStorage.getItem('orgId');
localStorage.clear()
localStorage.setItem('orgId', orgId)
// delete authorization from the header
setAuthToken(false);
// set user to {}
setCurrentUser({});
// move to home
Expand Down
4 changes: 1 addition & 3 deletions src/css/components/_modals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@
padding-top: 5px;
}
.search_btn {
width: 6vw;
height: 5vh;
background: rgb(250, 251, 252);
border-radius: 100px;
color: #1a73e8;
padding: 0.3em;
padding: 0 1rem;
margin-left: 1em;
}
.edit__post__option {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function ToggleSwitch(props) {

let handleClose = () => {
console.log('close clicked!')
setCheck(!checked)
setModalShow(false)
}

Expand Down Expand Up @@ -99,4 +100,4 @@ const mapStateToProps = (state) => ({
error: state.error
})

export default connect(mapStateToProps)(withRouter(ToggleSwitch));
export default connect(mapStateToProps)(withRouter(ToggleSwitch));
4 changes: 2 additions & 2 deletions src/user/dashboard/news-feed/popups/AddEventModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const AddEventModal = (props) => {
>
<Form.Label className="modal__label">Date</Form.Label>
<Form.Control
type="text"
type="date"
placeholder="YYYY/MM/DD"
onChange={onEventDate}
/>
Expand All @@ -116,7 +116,7 @@ const AddEventModal = (props) => {
>
<Form.Label className="modal__label">Time</Form.Label>
<Form.Control
type="text"
type="time"
placeholder="10:00 AM"
onChange={onEventTime}
/>
Expand Down
15 changes: 12 additions & 3 deletions src/user/organization/popups/Admins.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Admins extends Component {

mapHelper = (allAdmins) => {
let adminInfo = []
if (allAdmins.length > 0) {
if (allAdmins && allAdmins.length > 0) {
allAdmins.forEach((admin) => {
adminInfo.push({ name: admin.name.firstName + ' ' + admin.name.lastName, desc: admin.info.about?.designation, _id: admin._id, isRemoved: admin?.isRemoved || false })
})
Expand Down Expand Up @@ -100,6 +100,15 @@ class Admins extends Component {
const { onHide, show } = this.props
const { inviteLink, whoCanSendInvite } = this.state
const adminList = [...this.state.admins]

const handleModalHide = () => {
this.setState({
query: ''
}, () => {
onHide()
})
}

let admins = adminList.map((item) => (
<Row className="modal__member" id="p1" key={item._id}>
<div className="member__image">
Expand All @@ -123,7 +132,7 @@ class Admins extends Component {
));
return (
<Modal
onHide={onHide}
onHide={handleModalHide}
show={show}
size="md"
aria-labelledby="contained-modal-title-vcenter"
Expand Down Expand Up @@ -213,4 +222,4 @@ const mapStateToProps = (state) => ({
org: state.org
})

export default connect(mapStateToProps, { removeAdmin, getMember, getInviteLink, getOrgProfile })(Admins)
export default connect(mapStateToProps, { removeAdmin, getMember, getInviteLink, getOrgProfile })(Admins)
15 changes: 12 additions & 3 deletions src/user/organization/popups/Members.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Members extends Component {

mapHelper = (allMembers) => {
let membersInfo = []
if(allMembers.length > 0) {
if(allMembers && allMembers.length > 0) {
allMembers.forEach((member) => {
membersInfo.push({
name: member.name.firstName + ' ' + member.name.lastName,
Expand Down Expand Up @@ -113,6 +113,15 @@ class Members extends Component {
const { onHide, show } = this.props
const { isAdmin, inviteLink, whoCanSendInvite } = this.state
const membersList = [ ...this.state.members]

const handleModalHide = () => {
this.setState({
query: ''
}, () => {
onHide()
})
}

let members = membersList.map((item) => (
<Row className="modal__member" id="p1" key={item._id}>
<div className="member__image">
Expand Down Expand Up @@ -142,7 +151,7 @@ class Members extends Component {
));
return (
<Modal
onHide={onHide}
onHide={handleModalHide}
show={show}
size="md"
aria-labelledby="contained-modal-title-vcenter"
Expand Down Expand Up @@ -239,4 +248,4 @@ export default connect(mapStateToProps, {
getMember,
getInviteLink,
getOrgProfile,
})(Members);
})(Members);
10 changes: 7 additions & 3 deletions src/user/proposals/ProposalEditor/EditorContent/DropZone.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useCallback, useState } from "react";
import React, { useMemo, useCallback, useState, useEffect } from "react";
import { useDropzone } from "react-dropzone";
import { toast, ToastContainer } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
Expand Down Expand Up @@ -33,7 +33,11 @@ const rejectStyle = {
};

function StyledDropzone(props) {
const [proposalId, setProposalId] = useState(props.idContent);
const [proposalId, setProposalId] = useState(null);

useEffect(() => {
setProposalId(props.idContent)
}, [props.idContent])

const onDrop = useCallback((acceptedFiles) => {
let formData = new FormData();
Expand All @@ -53,7 +57,7 @@ function StyledDropzone(props) {
.catch((err) => {
console.log(err);
});
}, []);
}, [proposalId]);

const {
getRootProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class EditorContent extends Component {
<div>
{!this.state.newProposal ? (
<StyledDropzone
idContent={this.props.location.state.proposalId}
idContent={this.state.proposalId}
/>
) : (
<div></div>
Expand Down
5 changes: 5 additions & 0 deletions src/utils/allowCredentialsInHeader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import axios from "axios";

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lazycipher now you are not using authorization header ?
Only sending cookie?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes after shifting the auth method to use cookies, we're using auth in the cookie header.

export const allowCredentialsInHeader = () => {
axios.defaults.withCredentials = true;
}
12 changes: 0 additions & 12 deletions src/utils/setAuthToken.js

This file was deleted.