Skip to content
Snippets Groups Projects
Commit ddac8d34 authored by Taneli Riihimäki's avatar Taneli Riihimäki
Browse files

Basic functionalities almost working, some little bugs

parent 15439f53
No related branches found
No related tags found
No related merge requests found
REACT_APP_URL = "http://localhost:5000" REACT_APP_URL = "http://172.20.2.110:5000"
\ No newline at end of file \ No newline at end of file
import React, { Component } from "react"; import React, { Component } from "react";
import { StyleSheet, Text, View, Button } from "react-native"; import { StyleSheet, Text, View, Button, AsyncStorage } from "react-native";
import FetchLocation from "./components/FetchLocation"; import FetchLocation from "./components/FetchLocation";
import Login from "./components/Login"; import Login from "./components/Login";
......
...@@ -80,9 +80,9 @@ class Login extends Component { ...@@ -80,9 +80,9 @@ class Login extends Component {
/> />
)} )}
{this.state.username && ( {this.state.username && (
<button <Button
id="logoutButton" id="logoutButton"
onPress={this.handleLogout} onPress={this.handleLogout.bind(this)}
title="Logout" title="Logout"
/> />
)} )}
...@@ -90,15 +90,15 @@ class Login extends Component { ...@@ -90,15 +90,15 @@ class Login extends Component {
{this.state.form === "register" && ( {this.state.form === "register" && (
<RegisterForm <RegisterForm
view="" view=""
handleState={this.handleState} handleState={this.handleState.bind(this)}
toggleView={this.toggleView} toggleView={this.toggleView.bind(this)}
/> />
)} )}
{this.state.form === "login" && ( {this.state.form === "login" && (
<LoginForm <LoginForm
view="" view=""
handleState={this.handleState} handleState={this.handleState.bind(this)}
toggleView={this.toggleView} toggleView={this.toggleView.bind(this)}
/> />
)} )}
</View> </View>
......
...@@ -34,7 +34,7 @@ export class LoginForm extends React.Component { ...@@ -34,7 +34,7 @@ export class LoginForm extends React.Component {
e.preventDefault(); e.preventDefault();
// Send login info to the server // Send login info to the server
fetch(`${process.env.REACT_APP_URL}/user/login`, { fetch(`http://172.20.2.110:5000/user/login`, {
method: "POST", method: "POST",
headers: { headers: {
Accept: "application/json", Accept: "application/json",
......
...@@ -9,8 +9,11 @@ export class RegisterForm extends React.Component { ...@@ -9,8 +9,11 @@ export class RegisterForm extends React.Component {
errorMsg: "", errorMsg: "",
username: "", username: "",
password: "", password: "",
password2: "" password2: "",
registered: false
}; };
//this.handleRegister = this.handleRegister.bind(this);
} }
// shows error messages associated with registering // shows error messages associated with registering
...@@ -32,13 +35,14 @@ export class RegisterForm extends React.Component { ...@@ -32,13 +35,14 @@ export class RegisterForm extends React.Component {
handleRegister = e => { handleRegister = e => {
const name = this.state.username; const name = this.state.username;
const password = this.state.password; const password = this.state.password;
e.preventDefault(); console.log("PÄÄSTII TÄNNE");
this.setState({ registered: true });
console.log("Registered: " + this.state.registered);
if (this.state.password !== this.state.password2) { if (this.state.password !== this.state.password2) {
this.handleError("Passwords do not match"); this.handleError("Passwords do not match");
} else { } else {
// Send register info to the server // Send register info to the server
fetch("http://localhost:5000/user/register", { fetch(`http://172.20.2.110:5000/user/register`, {
method: "POST", method: "POST",
headers: { headers: {
Accept: "application/json", Accept: "application/json",
...@@ -56,7 +60,7 @@ export class RegisterForm extends React.Component { ...@@ -56,7 +60,7 @@ export class RegisterForm extends React.Component {
this.props.handleState(result); this.props.handleState(result);
this.handleView(); this.handleView();
} else { } else {
this.handleError(result.errorResponse.message); this.handleError(result.message);
} }
}, },
// Note: it's important to handle errors here // Note: it's important to handle errors here
...@@ -73,6 +77,7 @@ export class RegisterForm extends React.Component { ...@@ -73,6 +77,7 @@ export class RegisterForm extends React.Component {
return ( return (
<View className="fade-main"> <View className="fade-main">
<View className="sticky"> <View className="sticky">
{this.state.registered && <Text>REKISTERÖIDÄÄN</Text>}
<Text className="close" onPress={this.handleView}> <Text className="close" onPress={this.handleView}>
× ×
</Text> </Text>
...@@ -100,7 +105,7 @@ export class RegisterForm extends React.Component { ...@@ -100,7 +105,7 @@ export class RegisterForm extends React.Component {
onChangeText={password2 => this.setState({ password2 })} onChangeText={password2 => this.setState({ password2 })}
required required
/> />
<Button type="submit" title="Submit" onPress={this.handleRegister} /> <Button title="Submit" onPress={this.handleRegister} />
<Text>{this.state.errorMsg}</Text> <Text>{this.state.errorMsg}</Text>
</View> </View>
</View> </View>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment