Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
5.1 kB
1
Indexable
Never
import React, {useState} from 'react';
import {withStyles, Button, Text, Input, Icon} from '@ui-kitten/components';
import {
  View,
  ImageBackground,
  StyleSheet,
  Alert,
  KeyboardAvoidingView,
  ScrollView,
} from 'react-native';
import axios from 'axios';
import Constants from '../constants';
async function handleresetpassword(){
  try {
    const response = await axios.post(
      `${Constants.SERVER_URL}/users/password-reset`,
      {
        email: email
      },
    );
    // const {data} = response;
    // const success = await storeUser({
    //   access_token: data.access_token,
    // });
   
      console.log(response.data);
      if(response.status===200){
        toast.show("電子郵件已發送",{type: 'success'})
      }

  //   if (success) {
  //     // All is done
  //     toast.show('登入成功', {type: 'success'});
  //     // navigation.navigate('AuthLoadsing');
  //   } else {
  //     toast.show('發生錯誤', {type: 'danger'});
  //   }
} catch (error) {
    // toast.show('登入失敗23123'+error, {type: 'danger'});
    console.log(JSON.stringify(error));
    console.log("sadasdasdas",error.response.status);
    if(error.response.status===400){
      toast.show("郵箱不存在", {type: 'danger'})
    }
  }
}

function ForgotPasswordScreen(props){
    const {
        navigation,
        eva: {style: themedStyle},
      } = props;
    const [email, setEmail] = useState('');


    return (
        <KeyboardAvoidingView
        style={themedStyle.container}
        contentContainerStyle={{
          flexGrow: 1,
          paddingBottom: 24,
        }}>
        <ScrollView flex={1}>
          <ImageBackground
            style={themedStyle.headerContainer}
            source={require('../assets/images/vending_machine_icon.png')}>
            <View style={themedStyle.overlay}>
              <View style={themedStyle.signUpContainer}>
                <Button
                  style={themedStyle.signInButton}
                  appearance="ghost"
                  status="control"
                  size="giant"
                  accessoryLeft={style => (
                    <Icon {...style} name="corner-down-left-outline" />
                  )}
                  onPress={() => navigation.navigate('Login')}>
                  {props => (
                    <Text
                      {...props}
                      style={{
                        ...props.style,
                        paddingTop: 4,
                        fontWeight: 'normal',
                      }}>
                      登出
                    </Text>
                  )}
                </Button>
              </View>
            </View>
          </ImageBackground>         
          <Text style={themedStyle.TextLabel}   category="h4">忘記密碼了?</Text>
          <Text style={themedStyle.TextLabel} appearance='hint' >通過電子郵件發送一封更改密碼的鏈接</Text>
          <View style={themedStyle.formContainer}>
            <Input
              style={{
                marginTop: 5,
              }}
              autoCompleteType="email"
              placeholder="輸入你的信箱"
              status='danger'
              accessoryLeft={style => <Icon {...style} name="email-outline" />}
              autoCorrect={false}
              value={email}
              onChangeText={value => setEmail(value)}
            />
          </View>
          <View
            style={{
              justifyContent: 'center',
              alignItems: 'center',
              marginTop: 16,
            }}>
            <Button size='large'
               style={themedStyle.PasswordRestIconStyle}
              onPress={handleresetpassword}>
             重設密碼
            </Button>
          </View>
        </ScrollView>
      </KeyboardAvoidingView>
    );
  }
  export default ForgotPasswordScreen = withStyles(ForgotPasswordScreen, theme => ({
    container: {
      flex: 1,
      backgroundColor: theme['background-basic-color-1'],
    },
   
    formContainer: {
      marginTop: 32,
      paddingHorizontal: 16,
    },
    headerContainer: {
      minHeight: 150,
      paddingHorizontal: 16,
      paddingTop: 24,
      paddingBottom: 44,    
    },
    PasswordRestIconStyle: {
        marginHorizontal: 16,
        marginTop: 16,
        backgroundColor: '#4267B2',
        borderWidth: 0,
      },
    signUpContainer: {
      flexDirection: 'row',
      justifyContent: 'space-between',
      alignItems: 'center',
      marginTop: 64,
      marginHorizontal: 24,
    },
 
    overlay: {
      backgroundColor: 'rgba(0, 0, 0, 0.55)',
      ...StyleSheet.absoluteFillObject,
    },
    orContainer: {
      flexDirection: 'row',
      alignItems: 'center',
      marginHorizontal: 16,
      marginTop: 24,
    },
    TextLabel: {
      alignSelf: 'center',
      fontWeight: 'bold',
      marginTop: 36,
      
    },
  }));