Compare commits
4 commits
5bf1e7586b
...
5aa3afd383
| Author | SHA1 | Date | |
|---|---|---|---|
| 5aa3afd383 | |||
| 0b19915a62 | |||
| 6b336cfd03 | |||
| e3b3657e6e |
7 changed files with 417 additions and 73 deletions
|
|
@ -1,15 +1,143 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ConnectionManager, {ERROR_TYPE} from "../../managers/ConnectionManager";
|
import ConnectionManager, {ERROR_TYPE} from "../../managers/ConnectionManager";
|
||||||
|
import * as SecureStore from 'expo-secure-store';
|
||||||
|
|
||||||
|
let fetch = require('isomorphic-fetch'); // fetch is not implemented in nodeJS but in react-native
|
||||||
|
|
||||||
const fetch = require('isomorphic-fetch'); // fetch is not implemented in nodeJS but in react-native
|
|
||||||
const c = ConnectionManager.getInstance();
|
const c = ConnectionManager.getInstance();
|
||||||
|
|
||||||
test("connect bad credentials", () => {
|
test("connect bad credentials", () => {
|
||||||
return expect(c.connect('truc', 'chose'))
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||||
|
return Promise.resolve({
|
||||||
|
json: () => {
|
||||||
|
return {
|
||||||
|
state: false,
|
||||||
|
message: 'Adresse mail ou mot de passe incorrect',
|
||||||
|
token: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
});
|
||||||
|
return expect(c.connect('email', 'password'))
|
||||||
.rejects.toBe(ERROR_TYPE.BAD_CREDENTIALS);
|
.rejects.toBe(ERROR_TYPE.BAD_CREDENTIALS);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("connect good credentials", () => {
|
test("connect good credentials", () => {
|
||||||
return expect(c.connect('vergnet@etud.insa-toulouse.fr', 'Coucoù512'))
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||||
.resolves.toBe('test');
|
return Promise.resolve({
|
||||||
|
json: () => {
|
||||||
|
return {
|
||||||
|
state: true,
|
||||||
|
message: 'Connexion confirmée',
|
||||||
|
token: 'token'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
});
|
||||||
|
jest.spyOn(SecureStore, 'setItemAsync').mockImplementationOnce(() => {
|
||||||
|
return Promise.resolve(true);
|
||||||
|
});
|
||||||
|
return expect(c.connect('email', 'password')).resolves.toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("connect good credentials, fail save token", () => {
|
||||||
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||||
|
return Promise.resolve({
|
||||||
|
json: () => {
|
||||||
|
return {
|
||||||
|
state: true,
|
||||||
|
message: 'Connexion confirmée',
|
||||||
|
token: 'token'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
});
|
||||||
|
jest.spyOn(SecureStore, 'setItemAsync').mockImplementationOnce(() => {
|
||||||
|
return Promise.reject(false);
|
||||||
|
});
|
||||||
|
return expect(c.connect('email', 'password')).rejects.toBe(ERROR_TYPE.SAVE_TOKEN);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("connect connection error", () => {
|
||||||
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||||
|
return Promise.reject();
|
||||||
|
});
|
||||||
|
return expect(c.connect('email', 'password'))
|
||||||
|
.rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("connect bogus response 1", () => {
|
||||||
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||||
|
return Promise.resolve({
|
||||||
|
json: () => {
|
||||||
|
return {
|
||||||
|
thing: true,
|
||||||
|
wrong: '',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
});
|
||||||
|
return expect(c.connect('email', 'password'))
|
||||||
|
.rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("connect bogus response 2", () => {
|
||||||
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||||
|
return Promise.resolve({
|
||||||
|
json: () => {
|
||||||
|
return {
|
||||||
|
state: true,
|
||||||
|
message: '',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
});
|
||||||
|
return expect(c.connect('email', 'password'))
|
||||||
|
.rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("connect bogus response 3", () => {
|
||||||
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||||
|
return Promise.resolve({
|
||||||
|
json: () => {
|
||||||
|
return {
|
||||||
|
state: false,
|
||||||
|
message: '',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
});
|
||||||
|
return expect(c.connect('email', 'password'))
|
||||||
|
.rejects.toBe(ERROR_TYPE.BAD_CREDENTIALS);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("connect bogus response 4", () => {
|
||||||
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||||
|
return Promise.resolve({
|
||||||
|
json: () => {
|
||||||
|
return {
|
||||||
|
message: '',
|
||||||
|
token: '',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
});
|
||||||
|
return expect(c.connect('email', 'password'))
|
||||||
|
.rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("connect bogus response 5", () => {
|
||||||
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||||
|
return Promise.resolve({
|
||||||
|
json: () => {
|
||||||
|
return {
|
||||||
|
state: true,
|
||||||
|
message: 'Connexion confirmée',
|
||||||
|
token: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
});
|
||||||
|
return expect(c.connect('email', 'password'))
|
||||||
|
.rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,17 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {Dimensions, FlatList, Image, Platform, StyleSheet, View} from 'react-native';
|
import {Dimensions, FlatList, Image, Platform, StyleSheet, View} from 'react-native';
|
||||||
import i18n from "i18n-js";
|
import i18n from "i18n-js";
|
||||||
import * as WebBrowser from 'expo-web-browser';
|
import {openBrowser} from "../utils/WebBrowser";
|
||||||
import SidebarDivider from "./SidebarDivider";
|
import SidebarDivider from "./SidebarDivider";
|
||||||
import SidebarItem from "./SidebarItem";
|
import SidebarItem from "./SidebarItem";
|
||||||
import {TouchableRipple} from "react-native-paper";
|
import {TouchableRipple, withTheme} from "react-native-paper";
|
||||||
|
|
||||||
const deviceWidth = Dimensions.get("window").width;
|
const deviceWidth = Dimensions.get("window").width;
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
navigation: Object,
|
navigation: Object,
|
||||||
state: Object,
|
state: Object,
|
||||||
|
theme: Object,
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
|
|
@ -22,7 +23,7 @@ type State = {
|
||||||
/**
|
/**
|
||||||
* Component used to render the drawer menu content
|
* Component used to render the drawer menu content
|
||||||
*/
|
*/
|
||||||
export default class SideBar extends React.PureComponent<Props, State> {
|
class SideBar extends React.PureComponent<Props, State> {
|
||||||
|
|
||||||
dataSet: Array<Object>;
|
dataSet: Array<Object>;
|
||||||
|
|
||||||
|
|
@ -31,6 +32,7 @@ export default class SideBar extends React.PureComponent<Props, State> {
|
||||||
};
|
};
|
||||||
|
|
||||||
getRenderItem: Function;
|
getRenderItem: Function;
|
||||||
|
colors: Object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the dataset
|
* Generate the dataset
|
||||||
|
|
@ -126,6 +128,7 @@ export default class SideBar extends React.PureComponent<Props, State> {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
this.getRenderItem = this.getRenderItem.bind(this);
|
this.getRenderItem = this.getRenderItem.bind(this);
|
||||||
|
this.colors = props.theme.colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -138,7 +141,7 @@ export default class SideBar extends React.PureComponent<Props, State> {
|
||||||
if (item.link === undefined)
|
if (item.link === undefined)
|
||||||
this.props.navigation.navigate(item.route);
|
this.props.navigation.navigate(item.route);
|
||||||
else
|
else
|
||||||
WebBrowser.openBrowserAsync(item.link);
|
openBrowser(item.link, this.colors.primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -218,3 +221,5 @@ const styles = StyleSheet.create({
|
||||||
marginTop: Platform.OS === "android" ? -3 : undefined
|
marginTop: Platform.OS === "android" ? -3 : undefined
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export default withTheme(SideBar);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
|
import * as SecureStore from 'expo-secure-store';
|
||||||
|
|
||||||
export const ERROR_TYPE = {
|
export const ERROR_TYPE = {
|
||||||
BAD_CREDENTIALS: 0,
|
BAD_CREDENTIALS: 0,
|
||||||
CONNECTION_ERROR: 1
|
CONNECTION_ERROR: 1,
|
||||||
|
SAVE_TOKEN: 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
const AUTH_URL = "https://www.amicale-insat.fr/api/password";
|
const AUTH_URL = "https://www.amicale-insat.fr/api/password";
|
||||||
|
|
@ -27,6 +30,20 @@ export default class ConnectionManager {
|
||||||
ConnectionManager.instance;
|
ConnectionManager.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async saveLogin(email: string, token: string) {
|
||||||
|
this.#token = token;
|
||||||
|
this.#email = email;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
SecureStore.setItemAsync('token', token)
|
||||||
|
.then(() => {
|
||||||
|
resolve(true);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
reject(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async connect(email: string, password: string) {
|
async connect(email: string, password: string) {
|
||||||
let data = {
|
let data = {
|
||||||
email: email,
|
email: email,
|
||||||
|
|
@ -42,24 +59,31 @@ export default class ConnectionManager {
|
||||||
body: JSON.stringify(data)
|
body: JSON.stringify(data)
|
||||||
}).then(async (response) => response.json())
|
}).then(async (response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.log(data);
|
if (this.isResponseValid(data)) {
|
||||||
if (this.isResponseValid(data))
|
if (data.state) {
|
||||||
resolve({success: data.success, token: data.token});
|
this.saveLogin(email, data.token)
|
||||||
else
|
.then(() => {
|
||||||
reject(ERROR_TYPE.BAD_CREDENTIALS);
|
resolve(true);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
reject(ERROR_TYPE.SAVE_TOKEN);
|
||||||
|
});
|
||||||
|
} else
|
||||||
|
reject(ERROR_TYPE.BAD_CREDENTIALS);
|
||||||
|
} else
|
||||||
|
reject(ERROR_TYPE.CONNECTION_ERROR);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error);
|
|
||||||
reject(ERROR_TYPE.CONNECTION_ERROR);
|
reject(ERROR_TYPE.CONNECTION_ERROR);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
isResponseValid(response: Object) {
|
isResponseValid(response: Object) {
|
||||||
return response !== undefined
|
let valid = response !== undefined && response.state !== undefined;
|
||||||
&& response.success !== undefined
|
if (valid && response.state)
|
||||||
&& response.success
|
valid = valid && response.token !== undefined && response.token !== '';
|
||||||
&& response.token !== undefined;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,9 @@
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"preset": "react-native",
|
"preset": "react-native",
|
||||||
|
"transformIgnorePatterns": [
|
||||||
|
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base)"
|
||||||
|
],
|
||||||
"setupFilesAfterEnv": [
|
"setupFilesAfterEnv": [
|
||||||
"jest-extended"
|
"jest-extended"
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,18 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {Keyboard, KeyboardAvoidingView, StyleSheet, TouchableWithoutFeedback, View} from "react-native";
|
import {
|
||||||
import {Button, Text, TextInput, Title} from 'react-native-paper';
|
Alert,
|
||||||
|
Keyboard,
|
||||||
|
KeyboardAvoidingView,
|
||||||
|
ScrollView,
|
||||||
|
StyleSheet,
|
||||||
|
TouchableWithoutFeedback,
|
||||||
|
View
|
||||||
|
} from "react-native";
|
||||||
|
import {Avatar, Button, Card, HelperText, Text, TextInput, withTheme} from 'react-native-paper';
|
||||||
import ConnectionManager from "../../managers/ConnectionManager";
|
import ConnectionManager from "../../managers/ConnectionManager";
|
||||||
|
import {openBrowser} from "../../utils/WebBrowser";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
navigation: Object,
|
navigation: Object,
|
||||||
|
|
@ -12,79 +21,239 @@ type Props = {
|
||||||
type State = {
|
type State = {
|
||||||
email: string,
|
email: string,
|
||||||
password: string,
|
password: string,
|
||||||
|
isEmailValidated: boolean,
|
||||||
|
isPasswordValidated: boolean,
|
||||||
|
loading: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ICON_AMICALE = require('../../assets/amicale.png');
|
||||||
|
|
||||||
export default class LoginScreen extends React.Component<Props, State> {
|
const RESET_PASSWORD_LINK = "https://www.amicale-insat.fr/password/reset";
|
||||||
|
|
||||||
|
const emailRegex = /^.+@.+\..+$/;
|
||||||
|
|
||||||
|
class LoginScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
email: '',
|
email: '',
|
||||||
password: '',
|
password: '',
|
||||||
|
isEmailValidated: false,
|
||||||
|
isPasswordValidated: false,
|
||||||
|
loading: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
colors: Object;
|
||||||
|
|
||||||
onEmailChange: Function;
|
onEmailChange: Function;
|
||||||
onPasswordChange: Function;
|
onPasswordChange: Function;
|
||||||
|
validateEmail: Function;
|
||||||
|
validatePassword: Function;
|
||||||
|
onSubmit: Function;
|
||||||
|
onEmailSubmit: Function;
|
||||||
|
onResetPasswordClick: Function;
|
||||||
|
|
||||||
constructor() {
|
passwordInputRef: Object;
|
||||||
super();
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
this.onEmailChange = this.onInputChange.bind(this, true);
|
this.onEmailChange = this.onInputChange.bind(this, true);
|
||||||
this.onPasswordChange = this.onInputChange.bind(this, false);
|
this.onPasswordChange = this.onInputChange.bind(this, false);
|
||||||
|
this.validateEmail = this.validateEmail.bind(this);
|
||||||
|
this.validatePassword = this.validatePassword.bind(this);
|
||||||
|
this.onSubmit = this.onSubmit.bind(this);
|
||||||
|
this.onEmailSubmit = this.onEmailSubmit.bind(this);
|
||||||
|
this.onResetPasswordClick = this.onResetPasswordClick.bind(this);
|
||||||
|
this.colors = props.theme.colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
onResetPasswordClick() {
|
||||||
|
openBrowser(RESET_PASSWORD_LINK, this.colors.primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
validateEmail() {
|
||||||
|
this.setState({isEmailValidated: true});
|
||||||
|
}
|
||||||
|
|
||||||
|
isEmailValid() {
|
||||||
|
return emailRegex.test(this.state.email);
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldShowEmailError() {
|
||||||
|
return this.state.isEmailValidated && !this.isEmailValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
validatePassword() {
|
||||||
|
this.setState({isPasswordValidated: true});
|
||||||
|
}
|
||||||
|
|
||||||
|
isPasswordValid() {
|
||||||
|
return this.state.password !== '';
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldShowPasswordError() {
|
||||||
|
return this.state.isPasswordValidated && !this.isPasswordValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldEnableLogin() {
|
||||||
|
return this.isEmailValid() && this.isPasswordValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
onInputChange(isEmail: boolean, value: string) {
|
onInputChange(isEmail: boolean, value: string) {
|
||||||
if (isEmail)
|
if (isEmail) {
|
||||||
this.setState({email: value});
|
this.setState({
|
||||||
else
|
email: value,
|
||||||
this.setState({password: value});
|
isEmailValidated: false,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
password: value,
|
||||||
|
isPasswordValidated: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onEmailSubmit() {
|
||||||
|
this.passwordInputRef.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
console.log('pressed');
|
if (this.shouldEnableLogin()) {
|
||||||
ConnectionManager.getInstance().connect(this.state.email, this.state.password)
|
this.setState({loading: true});
|
||||||
.then((data) => {
|
ConnectionManager.getInstance().connect(this.state.email, this.state.password)
|
||||||
console.log(data);
|
.then((data) => {
|
||||||
})
|
console.log(data);
|
||||||
.catch((error) => {
|
Alert.alert('COOL', 'ÇA MARCHE');
|
||||||
console.log(error);
|
})
|
||||||
});
|
.catch((error) => {
|
||||||
|
console.log(error);
|
||||||
|
Alert.alert('ERREUR', 'MDP OU MAIL INVALIDE');
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.setState({loading: false});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getFormInput() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<TextInput
|
||||||
|
label='Email'
|
||||||
|
mode='outlined'
|
||||||
|
value={this.state.email}
|
||||||
|
onChangeText={this.onEmailChange}
|
||||||
|
onBlur={this.validateEmail}
|
||||||
|
onSubmitEditing={this.onEmailSubmit}
|
||||||
|
error={this.shouldShowEmailError()}
|
||||||
|
textContentType={'emailAddress'}
|
||||||
|
autoCapitalize={'none'}
|
||||||
|
autoCompleteType={'email'}
|
||||||
|
autoCorrect={false}
|
||||||
|
keyboardType={'email-address'}
|
||||||
|
returnKeyType={'next'}
|
||||||
|
secureTextEntry={false}
|
||||||
|
/>
|
||||||
|
<HelperText
|
||||||
|
type="error"
|
||||||
|
visible={this.shouldShowEmailError()}
|
||||||
|
>
|
||||||
|
EMAIL INVALID
|
||||||
|
</HelperText>
|
||||||
|
<TextInput
|
||||||
|
ref={(ref) => {
|
||||||
|
this.passwordInputRef = ref;
|
||||||
|
}}
|
||||||
|
label='Password'
|
||||||
|
mode='outlined'
|
||||||
|
value={this.state.password}
|
||||||
|
onChangeText={this.onPasswordChange}
|
||||||
|
onBlur={this.validatePassword}
|
||||||
|
onSubmitEditing={this.onSubmit}
|
||||||
|
error={this.shouldShowPasswordError()}
|
||||||
|
textContentType={'password'}
|
||||||
|
autoCapitalize={'none'}
|
||||||
|
autoCompleteType={'password'}
|
||||||
|
autoCorrect={false}
|
||||||
|
keyboardType={'default'}
|
||||||
|
returnKeyType={'done'}
|
||||||
|
secureTextEntry={true}
|
||||||
|
/>
|
||||||
|
<HelperText
|
||||||
|
type="error"
|
||||||
|
visible={this.shouldShowPasswordError()}
|
||||||
|
>
|
||||||
|
PLS ENTER PASSWORD
|
||||||
|
</HelperText>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getMainCard() {
|
||||||
|
return (
|
||||||
|
<Card style={styles.card}>
|
||||||
|
<Card.Title
|
||||||
|
title="COUCOU"
|
||||||
|
subtitle="ENTREZ VOS IDENTIFIANTS"
|
||||||
|
left={(props) => <Avatar.Image
|
||||||
|
{...props}
|
||||||
|
source={ICON_AMICALE}
|
||||||
|
style={{backgroundColor: 'transparent'}}/>}
|
||||||
|
/>
|
||||||
|
<Card.Content>
|
||||||
|
{this.getFormInput()}
|
||||||
|
<Card.Actions>
|
||||||
|
<Button
|
||||||
|
icon="send"
|
||||||
|
mode="contained"
|
||||||
|
disabled={!this.shouldEnableLogin()}
|
||||||
|
loading={this.state.loading}
|
||||||
|
onPress={this.onSubmit}
|
||||||
|
style={{marginLeft: 'auto'}}>
|
||||||
|
LOGIN
|
||||||
|
</Button>
|
||||||
|
</Card.Actions>
|
||||||
|
</Card.Content>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getSecondaryCard() {
|
||||||
|
return (
|
||||||
|
<Card style={styles.card}>
|
||||||
|
<Card.Content>
|
||||||
|
<Text>MDP OUBLIÉ ? t'es pas doué</Text>
|
||||||
|
<View style={styles.btnContainer}>
|
||||||
|
<Button
|
||||||
|
icon="reload"
|
||||||
|
mode="contained"
|
||||||
|
onPress={this.onResetPasswordClick}
|
||||||
|
style={{marginLeft: 'auto'}}>
|
||||||
|
RESET MDP
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
|
<Text>PAS DE COMPTE ? DOMMAGE PASSE À L'AMICALE</Text>
|
||||||
|
</Card.Content>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<KeyboardAvoidingView
|
<KeyboardAvoidingView
|
||||||
behavior={"padding"}
|
behavior={"height"}
|
||||||
contentContainerStyle={styles.container}
|
contentContainerStyle={styles.container}
|
||||||
style={styles.container}
|
style={styles.container}
|
||||||
|
enabled
|
||||||
|
keyboardVerticalOffset={100}
|
||||||
>
|
>
|
||||||
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
|
<ScrollView>
|
||||||
<View style={styles.inner}>
|
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
|
||||||
<Title>COUCOU</Title>
|
<View>
|
||||||
<Text>entrez vos identifiants</Text>
|
{this.getMainCard()}
|
||||||
<TextInput
|
{this.getSecondaryCard()}
|
||||||
label='Email'
|
|
||||||
mode='outlined'
|
|
||||||
value={this.state.email}
|
|
||||||
onChangeText={this.onEmailChange}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
label='Password'
|
|
||||||
mode='outlined'
|
|
||||||
value={this.state.password}
|
|
||||||
onChangeText={this.onPasswordChange}
|
|
||||||
/>
|
|
||||||
<View style={styles.btnContainer}>
|
|
||||||
<Button icon="send" onPress={() => this.onSubmit()}>
|
|
||||||
LOGIN
|
|
||||||
</Button>
|
|
||||||
</View>
|
</View>
|
||||||
<Text>Pas de compte, dommage !</Text>
|
</TouchableWithoutFeedback>
|
||||||
<View style={styles.btnContainer}>
|
</ScrollView>
|
||||||
<Button icon="send" onPress={() => console.log('Pressed')}>
|
|
||||||
Créer un compte
|
|
||||||
</Button>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
</TouchableWithoutFeedback>
|
|
||||||
</KeyboardAvoidingView>
|
</KeyboardAvoidingView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -92,11 +261,12 @@ export default class LoginScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
flex: 1
|
|
||||||
},
|
|
||||||
inner: {
|
|
||||||
padding: 24,
|
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
flexDirection: 'column',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
card: {
|
||||||
|
margin: 10,
|
||||||
},
|
},
|
||||||
header: {
|
header: {
|
||||||
fontSize: 36,
|
fontSize: 36,
|
||||||
|
|
@ -104,6 +274,9 @@ const styles = StyleSheet.create({
|
||||||
},
|
},
|
||||||
textInput: {},
|
textInput: {},
|
||||||
btnContainer: {
|
btnContainer: {
|
||||||
marginTop: 12
|
marginTop: 5,
|
||||||
|
marginBottom: 10,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export default withTheme(LoginScreen);
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ import * as React from 'react';
|
||||||
import {View} from 'react-native';
|
import {View} from 'react-native';
|
||||||
import i18n from "i18n-js";
|
import i18n from "i18n-js";
|
||||||
import DashboardItem from "../components/EventDashboardItem";
|
import DashboardItem from "../components/EventDashboardItem";
|
||||||
import * as WebBrowser from 'expo-web-browser';
|
|
||||||
import WebSectionList from "../components/WebSectionList";
|
import WebSectionList from "../components/WebSectionList";
|
||||||
import {Text, withTheme} from 'react-native-paper';
|
import {Text, withTheme} from 'react-native-paper';
|
||||||
import FeedItem from "../components/FeedItem";
|
import FeedItem from "../components/FeedItem";
|
||||||
import SquareDashboardItem from "../components/SquareDashboardItem";
|
import SquareDashboardItem from "../components/SquareDashboardItem";
|
||||||
import PreviewEventDashboardItem from "../components/PreviewEventDashboardItem";
|
import PreviewEventDashboardItem from "../components/PreviewEventDashboardItem";
|
||||||
import {stringToDate} from "../utils/Planning";
|
import {stringToDate} from "../utils/Planning";
|
||||||
|
import {openBrowser} from "../utils/WebBrowser";
|
||||||
// import DATA from "../dashboard_data.json";
|
// import DATA from "../dashboard_data.json";
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -70,7 +70,7 @@ class HomeScreen extends React.Component<Props> {
|
||||||
}
|
}
|
||||||
|
|
||||||
onTutorInsaClick() {
|
onTutorInsaClick() {
|
||||||
WebBrowser.openBrowserAsync("https://www.etud.insa-toulouse.fr/~tutorinsa/");
|
openBrowser("https://www.etud.insa-toulouse.fr/~tutorinsa/", this.colors.primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
onProximoClick() {
|
onProximoClick() {
|
||||||
|
|
@ -402,7 +402,7 @@ class HomeScreen extends React.Component<Props> {
|
||||||
}
|
}
|
||||||
|
|
||||||
openLink(link: string) {
|
openLink(link: string) {
|
||||||
WebBrowser.openBrowserAsync(link);
|
openBrowser(link, this.colors.primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
11
utils/WebBrowser.js
Normal file
11
utils/WebBrowser.js
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
// @flow
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as WebBrowser from 'expo-web-browser';
|
||||||
|
|
||||||
|
export function openBrowser(url: string, color: string) {
|
||||||
|
WebBrowser.openBrowserAsync(url, {
|
||||||
|
toolbarColor: color,
|
||||||
|
enableBarCollapsing: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue