Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from "react";
- var AWS=require('aws-sdk/dist/aws-sdk-react-native');
- var creds=require('../Components/UserCredentials')
- import {GoogleSignin} from 'react-native-google-signin'
- import CognitoIdentityServiceProvider from 'aws-sdk/clients/cognitoidentityserviceprovider';
- import {
- Modal,
- ImageBackground,
- Image,
- ToastAndroid,
- View,
- BackAndroid,
- BackHandler,
- StatusBar,
- Dimensions,
- TextInput,
- TouchableHighlight,
- WebView,
- ActivityIndicator,
- AsyncStorage} from "react-native";
- import { LoginButton,LoginManager,AccessToken,GraphRequest,GraphRequestManager } from 'react-native-fbsdk'
- import LoadingScreen from './LoadingScreen'
- import SESCreds from './SESCreds'
- import {
- Container,
- Button,
- Spinner,
- Text,
- Form,
- Input,
- Item,
- Icon,
- Label,
- Header,
- Title,
- Body,
- Left,
- Right,
- CheckBox} from "native-base";
- import {
- CognitoUserPool,
- CognitoUserAttribute,
- CognitoUser,
- AuthenticationDetails
- } from 'react-native-aws-cognito-js';
- import CognitoCreds from './CognitoCreds'
- import { moderateScale } from "react-native-size-matters/lib/scalingUtils";
- class Login extends Component {
- constructor(){
- super();
- this.state={
- check:true,
- isLoading:false,
- username:'',
- password:'',
- verificationcode:'',
- newPass:'',
- fbdata:{},
- googleData:{},
- icon:'eye'
- }
- }
- sendMail(to)
- {
- var creds=new AWS.Credentials(SESCreds)
- AWS.config.update({credentials:creds})
- AWS.config.update({region:'us-east-1'})
- var params = {
- Destination: {
- ToAddresses: [
- to//'ayushmankd@live.com',
- ],
- },
- Message: {
- Body: {
- Html: {
- Charset: "UTF-8",
- Data:
- '<div style="background-color:lightgrey">'+
- '<table style="margin:2%">'+
- '<tr>'+
- '<td><img height="50" width="100" src="https://s3.amazonaws.com/imagesgiftalife/unnamed.jpg"/></td>'+
- '<td style="vertical-align:bottom;padding-left:5em"><i><u><b style="color:green">'+
- 'Welcome to the family</b></u></i></td>'+
- '</tr>'+
- '</table>'+
- '<div style="background-color:white;padding:2em">'+
- '<b>'+
- 'Thank you for using gift a life app. We are happy to welcome you as our ' +
- 'newest family member. With giftalife, you get nothing less than excellent '+
- 'and unparalleled service at the most reasonable rates ever! We aim at ' +
- 'giving people a chance to go green in an innovative way by giving gifts '+
- 'in the form of well-designed pots and samplings to their loved ones.'+
- '</b>'+
- '<p>'+
- 'What we basically are trying to implement is that why not start gifting ' +
- 'plants to each other on special occasions such as birthdays, anniversaries '+
- 'etc rather than those bedsheets,decorative etc we do every now and then ' +
- 'which are basically repacked and sent to someone else '+
- '</p>'+
- '<p>'+
- 'We have some other amazing features as well such as plant a tree in which '+
- 'team comes to your neighbourhood and help you plant a tree because generally '+
- 'people don\'t have the time to do so. One feature or item which I personally '+
- 'love is naturally air purifiers I.e we have certain plants which are absorb ' +
- 'the pollutants from the air and clean the air around our home,office etc.' +
- '</p>'+
- '<p style="margin-top:4em">'+
- 'To know more about our services and amenities, just refer to the app or ' +
- 'check out our Facebook page the link has been provided at the end of this '+
- 'email.' +
- '</p>'+
- '<p>'+
- '<b style="color:green">HAPPY PLANTING!!!</b>'+
- '</p>'+
- '</div>'+
- '<div style="margin:2em" align="center">'+
- '<a href="https://www.facebook.com/giftalifeindia/?ref=aymt_homepage_panel"><img style="border-radius:3em;padding:10pt" src="http://pre00.deviantart.net/8119/th/pre/i/2012/088/c/6/facebook_logo_by_oguzburaksipsak-d4ubonk.png" height="40" width="40"/></a>'+
- '<a href="https://twitter.com/Giftalifeindia?lang=en"><img style="border-radius:3em;padding:10pt" src="http://www.nta.ng/wp-content/uploads/2016/10/twitter-image-service.png" height="40" width="40"/></a>'+
- '<a href="https://www.instagram.com/giftalife/"><img style="border-radius:3em;padding:10pt" src="https://www.philosopher.eu/wp-content/uploads/2013/10/Instagram-logo.png" height="40" width="40"/></a>'+
- '</div>'+
- '</div>'
- },
- },
- Subject: {
- Charset: 'UTF-8',
- Data: 'Welcome to the Family!!'
- }
- },
- Source: 'info@giftalife.in',//'ayushmankd@gmail.com',
- };
- }
- _responseInfoCallback(error, result) {
- if (error) {
- alert('Error fetching data: ' + error.toString());
- } else {
- this.setState({fbdata:result})
- this.sendMail(result.email.toString())
- AsyncStorage.setItem('user',result.first_name.toString())
- this.props.navigation.navigate('Drawer')
- this.signUpFb()
- }
- }
- signUpGoogle(){
- var credsCognito=new AWS.Credentials(CognitoCreds)
- var client=new CognitoIdentityServiceProvider({
- region:'us-east-1',
- credentials:credsCognito
- });
- var params = {
- UserPoolId: creds.UserPoolId, /* required */
- Username: this.state.googleData.id, /* required */
- DesiredDeliveryMediums: [
- "EMAIL",
- ],
- MessageAction:'SUPPRESS',
- //TemporaryPassword: 'STRING_VALUE',
- UserAttributes: [
- {
- Name: 'email', /* required */
- Value: this.state.googleData.email
- },
- {
- Name:'email_verified',
- Value:"True"
- }
- ],
- };
- client.adminCreateUser(params, function(err, data) {
- if (err) console.log(err); // an error occurred
- else console.log(data); // successful response
- });
- }
- signUpFb(){
- var credsCognito=new AWS.Credentials(CognitoCreds)
- var client=new CognitoIdentityServiceProvider({
- region:'us-east-1',
- credentials:credsCognito
- });
- var params = {
- UserPoolId: creds.UserPoolId, /* required */
- Username: this.state.fbdata.id, /* required */
- DesiredDeliveryMediums: [
- "EMAIL",
- /* more items */
- ],
- MessageAction:'SUPPRESS',
- //TemporaryPassword: 'STRING_VALUE',
- UserAttributes: [
- {
- Name: 'email', /* required */
- Value: this.state.fbdata.email
- },
- {
- Name:'email_verified',
- Value:"True"
- }
- ],
- };
- client.adminCreateUser(params, function(err, data) {
- if (err)
- console.log(err); // an error occurred
- else
- console.log(data); // successful response
- });
- }
- googleAuth() {
- GoogleSignin.signIn().then((user) => {
- //console.log(user);
- AsyncStorage.setItem('token',user.accessToken)
- AsyncStorage.setItem('user',user.name)
- this.setState({googleData:user})
- this.signUpGoogle();
- this.sendMail(user.email.toString())
- this.props.navigation.navigate('Drawer');
- })
- .catch((err) => {
- alert(err);
- })
- .done();
- }
- async setupGoogleSignin() {
- try {
- await GoogleSignin.hasPlayServices({ autoResolve: true });
- await GoogleSignin.configure({
- //iosClientId: settings.iOSClientId,
- //webClientId: settings.webClientId,
- //offlineAccess: false
- });
- const user = await GoogleSignin.currentUserAsync();
- AsyncStorage.setItem('token',user.accessToken)
- AsyncStorage.setItem('user',user.name)
- this.props.navigation.navigate('Drawer');
- }
- catch (err) {
- console.log(err);
- }
- }
- Check(){
- if(this.state.username===''||this.state.password==='')
- {
- ToastAndroid.show('Username/Password cannot be left Blank!!',ToastAndroid.SHORT)
- }
- else
- {
- this.SignIn()
- }
- }
- handleFB(superThis){
- LoginManager.logInWithReadPermissions(['public_profile','email']).then(
- function(result) {
- if (result.isCancelled) {
- console.log('Login cancelled');
- }
- else{
- AccessToken.getCurrentAccessToken().then(
- (data) => {
- const infoRequest = new GraphRequest(
- '/me',
- {
- parameters: {
- fields: {
- string: 'email,name,first_name,middle_name,last_name' // what you want to get
- },
- access_token: {
- string: data.accessToken.toString() // put your accessToken here
- }
- }
- },
- superThis._responseInfoCallback.bind(superThis),
- );
- new GraphRequestManager().addRequest(infoRequest).start();
- AsyncStorage.setItem('token',data.accessToken.toString());
- }
- )
- //superThis.props.navigation.navigate('Drawer')
- }
- },
- function(error){
- alert('Login fail with error: ' + error)
- },
- )
- }
- SignIn(){
- this.setState({isLoading:true})
- var userpool=new CognitoUserPool(creds)
- const authenticationDetails = new AuthenticationDetails({
- Username: this.state.username,
- Password: this.state.password
- });
- const cognitoUser = new CognitoUser({
- Username: this.state.username,
- Pool: userpool
- });
- cognitoUser.authenticateUser(authenticationDetails, {
- onSuccess: (result) => {
- AsyncStorage.setItem('token',result.getAccessToken().getJwtToken().toString())
- AsyncStorage.setItem('user',this.state.username)
- this.props.navigation.navigate('Drawer')
- },
- onFailure: (err) => {
- this.setState({isLoading:false})
- alert(err.toString())
- },
- mfaRequired: (codeDeliveryDetails) => {
- this.setState({isLoading:false})
- alert('mfaRequired', codeDeliveryDetails)
- }
- });
- }
- componentDidMount(){
- this.setupGoogleSignin();
- }
- async componentWillMount(){
- this.setState({isLoading:true})
- let token=await AsyncStorage.getItem('token')
- if(token!=null)
- this.props.navigation.navigate('Drawer')
- else
- this.setState({isLoading:false})
- }
- render() {
- if(this.state.isLoading)
- {
- return(
- <LoadingScreen />)
- }
- else{
- return (
- <Container>
- <StatusBar hidden={true} />
- <ImageBackground source={require('../../images/login-back.png')}
- style={{flex:1}}>
- <View style={{justifyContent:'center'}}>
- <View>
- <Image source={require('../../images/logo.png')} style={{
- alignSelf:'center',
- height:Dimensions.get('window').height*(85/592),
- width:Dimensions.get('window').width*(90/384),
- marginTop:'16%',
- margin:10,
- resizeMode:'stretch',
- borderRadius:20}}/>
- </View>
- <View style={{
- marginVertical:10,
- marginTop:'13%'
- }}>
- <Form>
- <Item style={{borderBottomWidth:0.5,borderBottomColor:'#fff',borderRadius:10,backgroundColor:'rgba(255,255,255,0.35)',marginRight:35,marginLeft:35}}>
- <Icon name='person' style={{marginLeft:10,color:'#fff'}}/>
- <Input
- placeholder="Username"
- placeholderTextColor={'rgba(255,255,255,0.5)'}
- style={{fontSize:moderateScale(20),color:'#fff'}}
- onChangeText={
- inputValue => this.setState({username:inputValue})
- }/>
- </Item>
- <Item style={{marginTop:10,borderRadius:10,backgroundColor:'rgba(255,255,255,0.35)',marginRight:35,marginLeft:35}}>
- <Icon name='key' style={{marginLeft:10,color:'#fff'}}/>
- <Input
- placeholder="Password"
- placeholderTextColor={'rgba(255,255,255,0.5)'}
- style={{fontSize:moderateScale(20),color:'#fff'}}
- secureTextEntry={this.state.icon=='eye'?true:false}
- onChangeText={inputValue => this.setState({password:inputValue})}/>
- <View style={{paddingRight:5}}>
- <Icon
- style={{color:'#fff'}}
- name={this.state.icon}
- onPress={()=>{
- if(this.state.icon=='eye')
- this.setState({icon:'eye-off'})
- else
- this.setState({icon:'eye'})
- }}/>
- </View>
- </Item>
- </Form>
- <TouchableHighlight style={{
- marginHorizontal:35,
- marginTop:10,
- backgroundColor:'#2daae1',
- paddingVertical:10,
- borderRadius:10}}
- onPress={()=>{this.Check()}}
- >
- <Text style={{alignSelf:'center',color:'#fff',fontSize:moderateScale(20)}}>Sign In</Text>
- </TouchableHighlight>
- <View style={{marginVertical:30,height:1,width:'50%',borderBottomWidth:0.5,borderBottomColor:'#fff',marginHorizontal:'25%'}}></View>
- <TouchableHighlight onPress={()=>this.handleFB(this)} style={{borderRadius:10,alignItems:'center',height:40,backgroundColor:'#43609C',width:'80%',marginHorizontal:'10%'}}>
- <View style={{flexDirection:'row'}}>
- <Icon name='logo-facebook' style={{paddingVertical:'3%',color:'#fff'}}/>
- <Text style={{color:'#fff',fontSize:moderateScale(16),paddingLeft:20,paddingVertical:'3%'}}>Sign in with Facebook</Text>
- </View>
- </TouchableHighlight>
- <TouchableHighlight onPress={this.googleAuth.bind(this)} style={{marginVertical:10,borderRadius:10,alignItems:'center',height:40,backgroundColor:'#d84b37',width:'80%',marginHorizontal:'10%'}}>
- <View style={{flexDirection:'row'}}>
- <Icon name='logo-google' style={{paddingVertical:'3%',color:'#fff'}}/>
- <Text style={{color:'#fff',paddingLeft:20,paddingVertical:'3%',fontSize:moderateScale(16)}}>Sign in with Google</Text>
- </View>
- </TouchableHighlight>
- </View>
- <View style={{flexDirection:'row',marginTop:'5%',justifyContent:'space-between',marginHorizontal:'10%'}}>
- <Text onPress={()=>{this.props.navigation.navigate('ForgotPassword')}}
- style={{fontSize:moderateScale(16),color:'#fff'}}>
- Forgot Password?
- </Text>
- <Text style={{color:'#fff',fontSize:moderateScale(16)}} onPress={()=>this.props.navigation.navigate('SignUp')}>
- New here?Sign Up
- </Text>
- </View>
- </View>
- </ImageBackground>
- </Container>
- );
- }
- }
- }
- export default Login;
Add Comment
Please, Sign In to add comment