Commit 099ac80c authored by TJHeeringa's avatar TJHeeringa

Fixed CSRF cookie

parent bdd28247
......@@ -9904,6 +9904,11 @@
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.6.4.tgz",
"integrity": "sha512-pZe//GGmwJndub7ZghVHz7vjb2LgC1m8B07Au3eYqeqv9emhESByMXxaEgkUkEqJe87oBbSniGYoQNIBklc7IQ=="
},
"js-cookie": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-2.2.1.tgz",
"integrity": "sha512-HvdH2LzI/EAZcUwA8+0nKNtWHqS+ZmijLA30RwZA0bo7ToCckjK5MkGhjED9KoRcXO6BaGI3I9UIzSA1FKFPOQ=="
},
"js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
......
......@@ -29,6 +29,7 @@
"file-saver": "^2.0.2",
"i": "^0.3.6",
"jquery": "^3.5.1",
"js-cookie": "^2.2.1",
"json-loader": "^0.5.7",
"lodash": "^4.17.20",
"moment": "^2.29.0",
......
......@@ -11,11 +11,11 @@ import { useAlertHandler} from "../../Contexts/AlertHandler";
import Block from "../PageLayout/Content/Block";
const ProfileForm = (props) => {
if (props.container) {
return <ProfileFormWithContainer {...props} />;
const ProfileForm = ({container, ...rest}) => {
if (container) {
return <ProfileFormWithContainer {...rest} />;
} else {
return <ProfileFormWithoutContainer {...props} />;
return <ProfileFormWithoutContainer {...rest} />;
}
};
......@@ -53,9 +53,8 @@ const ProfileFormWithContainer = (props) => {
);
};
const ProfileFormWithoutContainer = (props) => {
const ProfileFormWithoutContainer = ({ update, profile, onSuccess, disabled, handleProfileChange }) => {
const alerthandler = useAlertHandler();
const { update, profile, onSuccess, disabled, handleProfileChange } = props;
let { data: studies, loading: loadingStudies, refetch } = useGet({
path: process.env.REACT_APP_API_URL + "/studies",
......@@ -70,6 +69,7 @@ const ProfileFormWithoutContainer = (props) => {
postProfile(profile);
}
};
const postProfile = (profile) => {
return Helper.api_call(process.env.REACT_APP_API_URL + "/profiles", "POST", profile, "json",
(data)=>{
......@@ -88,6 +88,7 @@ const ProfileFormWithoutContainer = (props) => {
()=>{alerthandler.handleAlertHandler("red", "Save failed");},
);
};
return (
<AvForm id={"noprofileyetform"} onValidSubmit={handleValidSubmit}>
<h5>General</h5>
......@@ -213,7 +214,7 @@ const ProfileFormWithoutContainer = (props) => {
label={"IBAN"}
value={profile.iban}
onChange={(event) => handleProfileChange("iban", event.target.value)}
helpMessage={"Enter the IBAN without spaces, e.g. NL12RABO0123456789"}
helpMessage={"Enter the IBAN without spaces, so NL12RABO0123456789 instead of NL12 RABO 0123 4567 89."}
disabled={disabled}
required
/>
......@@ -223,7 +224,7 @@ const ProfileFormWithoutContainer = (props) => {
label={"BIC"}
value={profile.bic_code}
// onChange={(event) => props.handleProfileChange('bic_code', event.target.value)}
helpMessage={"This will be derived from your IBAN automatically"}
helpMessage={"This will be derived from your IBAN. This will be entered automatically when the IBAN is valid."}
disabled
required
/>
......@@ -254,3 +255,14 @@ const ProfileFormWithoutContainer = (props) => {
</AvForm>
);
};
ProfileFormWithoutContainer.propTypes = {
update: PropTypes.bool.isRequired,
profile: PropTypes.object.isRequired,
handleProfileChange: PropTypes.func.isRequired,
onSuccess: PropTypes.func,
disabled: PropTypes.bool,
};
ProfileFormWithoutContainer.defaultProps = {
onSuccess: ()=>{},
disabled: false
};
import Cookies from "js-cookie";
export class Helper {
static api_call(url, method, object = undefined, json_or_form_data = "json", on_succes = undefined, on_failure = undefined, include = true) {
......@@ -36,7 +39,7 @@ export class Helper {
};
if (localStorage.getItem("SUN_backend") === "OIDC" && include === true){
fetch_parameters.credentials = "include";
headers["X-CSRFToken"] = decodeURIComponent(document.cookie.split("=")[1]);
headers["X-CSRFToken"] = Cookies.get("csrftoken");
}
if (!this.isEmpty(headers)) {
fetch_parameters.headers = headers;
......
......@@ -3,6 +3,7 @@ import { ProfileInfo } from "App/Components/Info/ProfileInfo";
import React, {Component} from "react";
import {NavLink, Redirect,Route, withRouter} from "react-router-dom";
import {Button, Col, Container, Row} from "reactstrap";
import Block from "../../Components/PageLayout/Content/Block";
......
......@@ -5,15 +5,13 @@ import makeStyles from "@material-ui/core/styles/makeStyles";
import Typography from "@material-ui/core/Typography";
import { AvField,AvForm } from "availity-reactstrap-validation";
import PropTypes from "prop-types";
import React, { Component } from "react";
import { Link, Redirect, useLocation,withRouter } from "react-router-dom";
import { Col, FormText, Row } from "reactstrap";
import React from "react";
import { Link, Redirect, useLocation } from "react-router-dom";
import { Col, Row } from "reactstrap";
import Block from "../../Components/PageLayout/Content/Block";
import TextBlock from "../../Components/PageLayout/Content/TextBlock";
import {AlertHandlerContext} from "../../Contexts/AlertHandler";
import {useAuth} from "../../Contexts/Authentication";
import { Helper } from "../../Helper";
const useStyles = makeStyles(theme => ({
login: {
......@@ -87,102 +85,8 @@ const Login = (props) => {
);
};
// class Login2 extends Component {
// constructor(props){
// super(props);
// this.state = {
// redirectToReferrer: false,
// };
// }
//
// login = (username, password) => {
// Helper.authenticate(
// ()=>{
// this.props.history.push("/protected/v/home");
// },
// ()=>this.context.handleAlertHandler("red", "Login failed; invalid username/password combination"),
// username,
// password
// );
// };
//
// handleValidSubmit = (event, values) => {
// this.login(values.username, values.password);
// };
//
// render() {
// const { from } = this.props.location.state || { from: { pathname: "/protected/v/home" } };
// const { classes } = this.props;
// const { redirectToReferrer } = this.state;
//
// if (redirectToReferrer === true) {
// console.info("Redirecting to referrer");
// return <Redirect to={from}/>;
// }
//
// return (
// <x-fragment>
// <Container>
// <Col sm={{ size: 10, offset: 1 }}>
// <Row>
// <Col sm={"6"}>
// <TextBlock
// title={"Welcome to My SU"}
// body={"Welcome to the SUN member administration system. Log in to join a wide range of student associations, or, if you’re a board, to see information about your members."}
// >
// <br/>
// { process.env.REACT_APP_PRODUCTION_ENV === "false" &&
// <Typography variant={"body1"}>This is the development environment. You can login with user `s1234567` with password `SUNetwork`. This user is a board of the demo association `Student Union` and regular member of demo association `Rising Sun Helios`.</Typography>
// }
// </TextBlock>
// </Col>
// <Col sm={"6"}>
// <Block>
// <div className={"login-form"}>
// <div className={"Login"}>
// <AvForm id={"loginform"} onValidSubmit={this.handleValidSubmit} ref={c => (this.form = c)}>
// <Button variant={"outlined"} color={"secondary"} className={classes.login} href={process.env.REACT_APP_API_URL + "/oidc/authenticate/?next=" + window.location.origin + "/oidc"}>
// Login with University Account
// </Button>
// <p className={"divider"}>or</p>
// <div className={"loginfields"}>
// <AvField
// type={"text"}
// name={"username"}
// placeholder={"Username or Email Address"}
// required
// />
//
// <AvField
// type={"password"}
// name={"password"}
// placeholder={"Password"}
// required
// />
// </div>
// <Button color={"primary"} variant={"outlined"} type={"submit"}>Login</Button>
// </AvForm>
// <div className={"flex"}>
// <Link to={"/account/signup"}><Typography variant={"caption"}>Signup</Typography></Link>
// <Link to={"/account/forgotpassword"}><Typography variant={"caption"}>Forgot password</Typography></Link>
// </div>
// </div>
// </div>
// </Block>
// </Col>
// </Row>
// </Col>
// </Container>
// </x-fragment>
// );
// }
// }
// Login.contextType = AlertHandlerContext;
Login.propTypes = {
// classes: PropTypes.object.isRequired
};
export default Login;
export const LoginWithRouter = withRouter(withStyles(useStyles)(Login));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment