Skip to content

Commit

Permalink
Final changes! Made changes to User completely remote.
Browse files Browse the repository at this point in the history
  • Loading branch information
colelewis committed Apr 1, 2022
1 parent d736ec7 commit c29b042
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
30 changes: 12 additions & 18 deletions ScreenGenerator.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useState } from 'react'
import { Alert, Text, TextInput, View, Image, TouchableOpacity, SafeAreaView } from 'react-native'
import { PAGES, styles, setScreen, getUser, setUser, getFocus, storeData, removeValue } from './Utility'
import { dataOccupied, makeAcc, deleteCurrUser, lru, getRememberMe, checkLogin } from './User'
import { dataOccupied, makeAcc, deleteCurrUser, lru, getRememberMe, checkLogin, usernameValidation } from './User'
import { renderPost, savePost } from './Post'
import { changeUserBiographyInDatabase, changeUserDisplayNameInDatabase, pullPostFromDatabase } from './firebaseConfig'
import { changeUserBiographyInDatabase, changeUserDisplayNameInDatabase, changeUserPasswordInDatabase, pullPostFromDatabase } from './firebaseConfig'

import AsyncStorage from '@react-native-async-storage/async-storage'
import { sha224 } from 'js-sha256'
Expand Down Expand Up @@ -332,14 +332,12 @@ export class ScreenGenerator {
<TouchableOpacity
style={styles.loginBtn}
onPress={() => {
// if (usernameValidation(String(newUsername$.get()))) {
// alert('This username already exists, please choose a different one.')
// return
// }
changeUserDisplayNameInDatabase(u.MiD, String(newUsername$.get()))
u.setRealName(String(newUsername$.get()))
AsyncStorage.getItem(u.MiD).then(data => {
data = JSON.parse(data)
data.realName = String(newUsername$.get())
AsyncStorage.setItem(u.MiD, JSON.stringify(data))
})

setScreen(PAGES.SETTINGS)
}}
>
Expand Down Expand Up @@ -374,11 +372,7 @@ export class ScreenGenerator {
style={styles.loginBtn}
onPress={() => {
u.setNewPassword(String(sha224(String(newPassword$.get()))))
AsyncStorage.getItem(u.MiD).then(data => {
data = JSON.parse(data)
data.password = String(sha224(String(newPassword$.get())))
AsyncStorage.setItem(u.MiD, JSON.stringify(data))
})
changeUserPasswordInDatabase(u.MiD, String(sha224(String(newPassword$.get()))))
setScreen(PAGES.SETTINGS)
}}
>
Expand Down Expand Up @@ -415,11 +409,11 @@ export class ScreenGenerator {
onPress={() => {
changeUserBiographyInDatabase(u.MiD, String(newBiography$.get()))
u.setNewBiography(String(newBiography$.get()))
AsyncStorage.getItem(u.MiD).then(data => {
data = JSON.parse(data)
data.biography = String(newBiography$.get())
AsyncStorage.setItem(u.MiD, JSON.stringify(data))
})
// AsyncStorage.getItem(u.MiD).then(data => {
// data = JSON.parse(data)
// data.biography = String(newBiography$.get())
// AsyncStorage.setItem(u.MiD, JSON.stringify(data))
// })
setScreen(PAGES.SETTINGS)
}}
>
Expand Down
9 changes: 8 additions & 1 deletion User.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export async function makeAcc (username, password, realName, bio) {
return
}
const u = new User(username, String(sha224(String(password))), realName, bio, 'new', 'new', 'new', 'new')
// await storeData(u.getMiD(), u)
pushAccountToDatabase(u)
pushUsernameToDatabase(username)
setUser(u)
Expand Down Expand Up @@ -182,4 +181,12 @@ export async function lru () {
})
}

export async function usernameValidation (username) {
if (await doesUsernameExist(username) === true) {
return true
} else {
return false
}
}

export default User
6 changes: 6 additions & 0 deletions firebaseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ export async function changeUserDisplayNameInDatabase (mesosphereID, newDisplayN
})
}

export async function changeUserPasswordInDatabase (mesosphereID, newPassword) {
await updateDoc(doc(database, 'accounts', mesosphereID), {
password: newPassword
})
}

// testing and validation methods

export async function doesAccountExist (mesosphereID) {
Expand Down

0 comments on commit c29b042

Please sign in to comment.