Skip to content

Commit

Permalink
Login Screen Final Push: Mind the IP
Browse files Browse the repository at this point in the history
  • Loading branch information
EurobeatStrider committed Nov 29, 2022
1 parent 4d31891 commit 3629230
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 36 deletions.
12 changes: 3 additions & 9 deletions backend/src/handlers/user_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,8 @@ function getUserHandler(UserController)
console.log("Attempting routing")
try {
const userData = req.body
if (true){

const data = await UserController.createUser(userData)
res.json(data)
} else {
res.status(400)
res.send("Check request parameters/body")
}
const data = await UserController.createUser(userData)
res.send(data)
}catch(err) {
const errMessage = "Error while creating user: " + err.message
res.status(404)
Expand All @@ -98,7 +92,7 @@ function getUserHandler(UserController)
if (true){

const data = await UserController.signInUser(username, password)
res.json(data)
res.send(data)
} else {
res.status(400)
res.send("Check request parameters/body")
Expand Down
22 changes: 10 additions & 12 deletions backend/src/repository/user_repository.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword, signOut } = require("firebase/auth");
const {collection, doc, getDocs, addDoc, deleteDoc, query, where, updateDoc} = require("firebase/firestore")
const {collection, doc, getDocs, addDoc, deleteDoc, query, where, updateDoc, setDoc} = require("firebase/firestore")


class UserRepository {
Expand Down Expand Up @@ -42,29 +42,27 @@ class UserRepository {
var user
var username = userData.username
var password = userData.password
createUserWithEmailAndPassword(auth, username, password)
return createUserWithEmailAndPassword(auth, username, password)
.then((userCredential) => {
console.log("Logged In")
user = userCredential
console.log(userCredential.user.uid)
user = userCredential.user.uid
setDoc(doc(this._dbz, "Users", userCredential.user.uid), userData)
console.log("returning user: ", user)
return user
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
})
let newUser = await addDoc(
collection(this._dbz, "Users"),
userData
)
return user
}

async signInUser(username, password) {
const auth = getAuth()
var user
signInWithEmailAndPassword(auth, username, password)
return signInWithEmailAndPassword(auth, username, password)
.then((userCredential) => {
console.log("Signing in as " + userCredential.user)
user = userCredential.user
console.log("Signing in as " + userCredential.user.uid)
user = userCredential.user.uid
console.log("Signed in as user " + user)
return user
})
Expand Down
22 changes: 15 additions & 7 deletions mobile-app/Screens/LoginScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,24 @@ export const Login_Splash = ({navigation, route }) => {
const [user, setUser] = useState(null);


const signInUser = () => {
const signInUser = async() => {
console.log("Frontend Attempting Sign In")
Api.SignInUserFrontend(username, password).then((localUser)=>{
if(localUser)
await Api.SignInUserFrontend(username, password).then((uid)=>{
console.log("Returned user id is " + uid)
Api.GetUserByID(uid).then((localUser) =>
{
setUser(localUser)
navigation.navigate(localUser["type"], {
"region": route.params.region
})
}})
console.log(localUser, "from nav attempt")
const userData = localUser[uid]
console.log(userData);
navigation.navigate(userData["type"], {
"region": route.params.region
})
})
}).catch(err => {
console.log(err)
return false
})
}

const signUpUser = () => {
Expand Down
23 changes: 18 additions & 5 deletions mobile-app/Screens/SignUpScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,27 @@ export const SignUp_Splash = ({navigation, route }) => {



const signUpUser = (type) => {
const signUpUser = async (type) => {
/*username = username.trim()
if(username.substring(-8) != "@ttu.edu")
return false; //do nothing; invalid email.
password = password.trim()
fname = fname.trim()
lname = lname.trim()
phone = phone.trim()*/
console.log("Frontend Attempting Sign Up, values are %s %s %s %s %s", username, password, fname, lname, phone)
Api.CreateUserFrontend(username, password, fname, lname, phone, type).then((localUser)=>{
setUser(localUser)
console.log(localUser, "from nav attempt")
navigation.navigate(localUser["type"], {
await Api.CreateUserFrontend(username, password, fname, lname, phone, type).then((uid)=>{
console.log("Returned user id is " + uid)
Api.GetUserByID(uid).then((localUser) =>
{
setUser(localUser)
console.log(localUser, "from nav attempt")
const userData = localUser[uid]
console.log(userData);
navigation.navigate(userData["type"], {
"region": route.params.region
})
})
}).catch(err => {
console.log(err)
return false
Expand Down
14 changes: 11 additions & 3 deletions mobile-app/api/api_Calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios from 'axios'
import {API_BASE_URL} from '@env';
import { addTextAndPropsToStrings } from 'native-base';

const URL = "http://10.161.5.127:9001"
const URL = "http://172.20.10.2:9001"

export const GetAllUsers = () => {
console.info("Getting all users...")
Expand Down Expand Up @@ -187,8 +187,6 @@ export const CreateUserFrontend = (username, password, fname, lname, phone, type
})
}

//export const updateUserFrontend = ()

export const SignInUserFrontend = (username, password) => {
console.info("Attempting sign in from API call"+username+"/"+password)
return axios.get(URL + "/api/users/signin/"+username+"/"+password).then((res) => {
Expand All @@ -198,3 +196,13 @@ export const SignInUserFrontend = (username, password) => {
}) //todo, awaiting conversion to body from api call
}

export const GetUserByID = (userID) => {
console.info("Getting user info...");
return axios.get(URL + "/api/users/id/"+userID).then((res) => {
return (res.data && !Object.keys(res.data).length == 0) ? res.data : false;
return false;
}).catch(err => {
console.log(err)
return false;
})
}

0 comments on commit 3629230

Please sign in to comment.