Commit 87d29ef1 authored by TJHeeringa's avatar TJHeeringa

Minor bugfixes

parent 23f24384
NODE_PATH=src/
REACT_APP_API_URL='https://api.sun.utwente.nl'
REACT_APP_SERVER_URL='https://sun.utwente.nl'
REACT_APP_PRODUCTION_ENV=true
\ No newline at end of file
......@@ -9,7 +9,7 @@ import { Osiris } from 'App/Components/Forms/Osiris'
import { Info } from "App/Components/Info/Info";
import { v4 as uuidv4 } from 'uuid';
import {AlertHandlerContext} from "../../Contexts/AlertHandler";
import { useGet } from "restful-react";
export class Profile extends Component {
constructor(props) {
......@@ -23,37 +23,51 @@ export class Profile extends Component {
componentDidMount() {
if (this.props.update) {
Helper.api_call(
process.env.REACT_APP_API_URL + '/studies',
"GET",
undefined,
'json',
(data)=>{
this.setState({studies:data.results});
}
)
Helper.api_callv2({
url: process.env.REACT_APP_API_URL + '/studies',
method: "GET",
on_succes:(data)=>{this.setState({studies:data.results})}
})
}
}
handleProfileChange = (field, value) => {
this.setState(prevState => {
let profile = prevState.profile;
profile[field] = value;
if (field === 'iban' && value.length >= 15 && value.length < 35){
Helper.api_call(
"https://openiban.com/validate/" + value + "?getBIC=true",
"GET",
undefined,
'json',
(data)=>{
if (data['valid'] === true) {
profile['bic_code'] = data['bankData']['bic']
if (field === 'iban') {
if (value.length >14 && value.length < 35 ) {
Helper.api_callv2({
url: "https://openiban.com/validate/" +value + "?getBIC=true&validateBankCode=true",
method: "GET",
on_succes: (ibanData) => {
if (ibanData.valid === true) {
this.context.handleAlertHandler('green', 'IBAN valid');
this.setState(prevState => {
let profile = prevState.profile;
profile[field] = value;
profile['bic_code'] = ibanData['bankData']['bic'];
return {...prevState, profile: profile}
});
} else {
this.setState(prevState => {
let profile = prevState.profile;
profile[field] = value;
profile['bic_code'] = '';
return {...prevState, profile: profile}
});
}
}
)
},
on_failure: () => {
this.context.handleAlertHandler('red', 'openiban.com check of your IBAN failed')
},
external: true
})
}
return {profile: profile}
});
} else {
this.setState(prevState => {
let profile = prevState.profile;
profile[field] = value;
return {...prevState, profile: profile}
});
}
};
render() {
......@@ -79,6 +93,7 @@ export class Profile extends Component {
}
}
Profile.contextType = AlertHandlerContext;
export class ProfileInfo extends Component {
morphProfileToData = (profile) => {
......@@ -278,16 +293,16 @@ class ProfileFormWithoutContainer extends Component {
disabled={this.props.disabled}
required
/>
<FormGroup>
<label>Country</label>
<CountryDropdown
classes={'form-control'}
value={this.props.profile.country}
onChange={(country) => this.props.handleProfileChange('country', country)}
disabled={this.props.disabled}
required
/>
</FormGroup>
{/*<FormGroup>*/}
{/*<label>Country</label>*/}
{/*<CountryDropdown*/}
{/*classes={'form-control'}*/}
{/*value={this.props.profile.country}*/}
{/*onChange={(country) => this.props.handleProfileChange('country', country)}*/}
{/*disabled={this.props.disabled}*/}
{/*required*/}
{/*/>*/}
{/*</FormGroup>*/}
{/*<FormGroup>*/}
{/*<label>Region</label>*/}
{/*<RegionDropdown*/}
......@@ -309,6 +324,7 @@ class ProfileFormWithoutContainer extends Component {
label="IBAN"
value={this.props.profile.iban}
onChange={(event) => this.props.handleProfileChange('iban', event.target.value)}
helpMessage={'Enter the IBAN without spaces, e.g. NL12RABO0123456789'}
disabled={this.props.disabled}
required
/>
......@@ -318,6 +334,7 @@ class ProfileFormWithoutContainer extends Component {
label="BIC"
value={this.props.profile.bic_code}
// onChange={(event) => this.props.handleProfileChange('bic_code', event.target.value)}
helpMessage={'This will be derived from your IBAN automatically'}
disabled
required
/>
......
export class Helper {
static api_call(url, method, object = undefined, json_or_form_data = 'json', on_succes = undefined, on_failure = undefined) {
static api_call(url, method, object = undefined, json_or_form_data = 'json', on_succes = undefined, on_failure = undefined, include = true) {
console.log('API object:', object);
// make body
// -----------------
......@@ -33,7 +34,7 @@ export class Helper {
method: method,
redirect: 'follow'
};
if (localStorage.getItem("SUN_backend") === "OIDC"){
if (localStorage.getItem("SUN_backend") === "OIDC" && include === true){
fetch_parameters.credentials = "include";
headers["X-CSRFToken"] = decodeURIComponent(document.cookie.split('=')[1]);
}
......@@ -72,6 +73,10 @@ export class Helper {
})
}
static api_callv2({url, method, object = undefined, json_or_form_data = 'json', on_succes = undefined, on_failure = undefined, external = false}={}) {
this.api_call(url, method, object, json_or_form_data, on_succes, on_failure, !external);
}
static authenticate(cbCorrect, cbIncorrect, username, password) {
console.log('login');
Helper.api_call(
......@@ -88,11 +93,9 @@ export class Helper {
localStorage.setItem('authenticated', 'true');
console.log(localStorage);
cbCorrect()
} else {
cbIncorrect()
}
},
(resp)=>{console.log(resp)}
(resp)=>{cbIncorrect()}
);
}
......
......@@ -19,7 +19,7 @@ class Login extends Component {
()=>{
this.props.history.push('/protected/v/home')
},
()=>this.context.handleAlertHandler('red', 'login failed'),
()=>this.context.handleAlertHandler('red', 'Login failed; invalid username/password combination'),
username,
password
)
......@@ -76,8 +76,8 @@ class Login extends Component {
<Button color="primary" outline block type="submit">Login</Button>
</AvForm>
<div className="flex">
<FormText><Link to={"/signup"}>Signup</Link></FormText>
<FormText><Link to={"/forgotpassword"}>Forgot password</Link></FormText>
<FormText><Link to={"/account/signup"}>Signup</Link></FormText>
<FormText><Link to={"/account/forgotpassword"}>Forgot password</Link></FormText>
</div>
</div>
</div>
......
......@@ -3,6 +3,7 @@ import { Button, Col, Container, Row } from 'reactstrap'
import { AvForm, AvField } from 'availity-reactstrap-validation'
import {Redirect, withRouter} from 'react-router-dom'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { Helper } from "App/Helper";
class Signup extends Component {
......@@ -23,28 +24,18 @@ class Signup extends Component {
}
signup = (username, email, password, passwordconfirmation, agree) => {
const signupUrl = process.env.REACT_APP_API_URL + "/account/register/";
let status;
return fetch(signupUrl, {
Helper.api_callv2({
url: process.env.REACT_APP_API_URL + "/account/register/",
method: "POST",
headers: {
// "Authorization": localStorage.getItem("token"),
"Content-Type": "application/json"
},
body:JSON.stringify({
object: {
"username": username,
"email": email,
"password": password,
"password_confirm": passwordconfirmation,
"tos": agree,
})
}).then(resp => {
console.log(resp);
status = resp.status;
return resp.json();
}).then(resp => {
console.log(status);
if (status === 400) {
},
on_succes: ()=>this.setState({redirect: true}),
on_failure: (resp)=> {
for (const [key, value] of Object.entries(resp)) {
switch(key) {
case 'username':
......@@ -57,12 +48,8 @@ class Signup extends Component {
console.log(key, value);
}
}
} else if (status === 201) {
this.setState({redirect: true});
}
}).then(error => {
console.log(error);
})
});
};
handleValidSubmit = (event, values) => {
......
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