Update login and register mocked users
This commit is contained in:
parent
89716c89ad
commit
beb7b3eee3
3 changed files with 33 additions and 11 deletions
|
@ -35,10 +35,9 @@ function AuthProvider(props) {
|
||||||
|
|
||||||
const login = (email, password) => {
|
const login = (email, password) => {
|
||||||
setState({ ...state, status: 'pending' });
|
setState({ ...state, status: 'pending' });
|
||||||
let shouldFail = email !== 'teste@teste.com' || password !== '#teste1234';
|
|
||||||
|
|
||||||
return getUser(shouldFail).then(data => {
|
return getUser(email, password).then(data => {
|
||||||
if (shouldFail) {
|
if (data.message) {
|
||||||
return setState({ status: 'error', user: null, error: data });
|
return setState({ status: 'error', user: null, error: data });
|
||||||
} else {
|
} else {
|
||||||
return setState({ status: 'success', user: data, error: null });
|
return setState({ status: 'success', user: data, error: null });
|
||||||
|
|
|
@ -534,7 +534,7 @@ const allPeople = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const user = {
|
const studentUser = {
|
||||||
id: '123',
|
id: '123',
|
||||||
ra: '0021123',
|
ra: '0021123',
|
||||||
username: 'ronaldosilva',
|
username: 'ronaldosilva',
|
||||||
|
@ -551,6 +551,23 @@ const user = {
|
||||||
role: 'STUDENT',
|
role: 'STUDENT',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const professorUser = {
|
||||||
|
id: '321',
|
||||||
|
ra: '0021123',
|
||||||
|
username: 'cazalbe',
|
||||||
|
email: 'carlos.junior@ifmg.edu.br',
|
||||||
|
password: '#carlos1234', // TODO: Remove this!
|
||||||
|
firstName: 'Carlos',
|
||||||
|
lastName: 'Severiano',
|
||||||
|
token: 'xkhfb9458hnsdfsi9q8345bsdf9b834yr',
|
||||||
|
phone: '31111111111',
|
||||||
|
avatar: 'https://i.pravatar.cc/300?img=61',
|
||||||
|
course: 0,
|
||||||
|
termsAgreed: true,
|
||||||
|
year: 2018,
|
||||||
|
role: 'PROFESSOR',
|
||||||
|
};
|
||||||
|
|
||||||
const authFailure = {
|
const authFailure = {
|
||||||
message: 'Falha na autenticação',
|
message: 'Falha na autenticação',
|
||||||
};
|
};
|
||||||
|
@ -561,7 +578,8 @@ export {
|
||||||
allClassroomAnnouncements,
|
allClassroomAnnouncements,
|
||||||
allPeople,
|
allPeople,
|
||||||
faq,
|
faq,
|
||||||
user,
|
studentUser,
|
||||||
|
professorUser,
|
||||||
authFailure,
|
authFailure,
|
||||||
allUpcomingAssignments,
|
allUpcomingAssignments,
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,8 @@ import {
|
||||||
allClassrooms,
|
allClassrooms,
|
||||||
allAssignments,
|
allAssignments,
|
||||||
faq,
|
faq,
|
||||||
user,
|
studentUser,
|
||||||
|
professorUser,
|
||||||
authFailure,
|
authFailure,
|
||||||
allClassroomAnnouncements,
|
allClassroomAnnouncements,
|
||||||
allUpcomingAssignments,
|
allUpcomingAssignments,
|
||||||
|
@ -84,14 +85,18 @@ const getFaq = () =>
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const getUser = shouldFail =>
|
const getUser = (email, password) =>
|
||||||
sleep(300).then(() => {
|
sleep(300).then(() => {
|
||||||
if (shouldFail) {
|
let user;
|
||||||
return authFailure;
|
if (email === 'p@test.com' && password === 'p123') {
|
||||||
|
user = professorUser;
|
||||||
|
} else if (email === 's@test.com' && password === 's123') {
|
||||||
|
user = studentUser;
|
||||||
} else {
|
} else {
|
||||||
window.localStorage.setItem('$USER', JSON.stringify(user));
|
return authFailure;
|
||||||
return user;
|
|
||||||
}
|
}
|
||||||
|
window.localStorage.setItem('$USER', JSON.stringify(user));
|
||||||
|
return user;
|
||||||
});
|
});
|
||||||
|
|
||||||
const registerUser = (data, shouldFail) =>
|
const registerUser = (data, shouldFail) =>
|
||||||
|
|
Loading…
Reference in a new issue