-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add working account creation functionality.
1 parent
98eaf5e
commit ec63772
Showing
6 changed files
with
179 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,51 @@ | ||
import { StudyBuddyDB } from './Database.js'; | ||
import t from 'tcomb-form-native'; | ||
|
||
export default class Auth { | ||
|
||
} | ||
const Majors = t.enums({ | ||
CS: 'Computer Science', | ||
CM: 'Computational Media', | ||
O: 'Other', | ||
}); | ||
|
||
const Years = t.enums({ | ||
0: 'Freshman', | ||
1: 'Sophomore', | ||
2: 'Junior', | ||
3: 'Senior', | ||
4: '5th Year+', | ||
}); | ||
|
||
const Email = t.subtype(t.Str, (email) => { | ||
const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
return reg.test(email); | ||
}); | ||
|
||
|
||
export const User = t.struct({ | ||
email: Email, | ||
name: t.String, | ||
lastName: t.String, | ||
password: t.String, | ||
passwordAgain: t.String, | ||
major: Majors, | ||
year: Years, | ||
}); | ||
|
||
class Auth { | ||
/** | ||
* Wrapper for the DB getUser class. | ||
*/ | ||
async getUser(email) { | ||
user = await StudyBuddyDB.getUser(email); | ||
return user; | ||
} | ||
|
||
/** | ||
* Takes in a user object and creates a new account for that user. | ||
*/ | ||
createAccount(user) { | ||
StudyBuddyDB.addUser(user); | ||
} | ||
} | ||
|
||
export const AuthObject = new Auth(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
import { SQLite } from 'expo'; | ||
import { AsyncStorage } from 'react-native'; | ||
|
||
class Database { | ||
static users_table = 'users'; | ||
constructor(name) { | ||
this.db = SQLite.openDatabase(name); | ||
// TEMPORARY: drop users table before creating. | ||
this.db.transaction(tx => { | ||
tx.executeSql('drop table ?', [this.users_table]); | ||
}); | ||
this.db.transaction(tx => { | ||
tx.executeSql('create table if not exists ? (id integer primary key not null, ' | ||
+ 'firstName text, lastName text, password text, username text, major text, year text);', [this.users_table]); | ||
}); | ||
} | ||
|
||
/** | ||
* This method adds a new user to the database. | ||
*/ | ||
addUser(lastName, firstName, email, year, major, password) { | ||
this.db.transaction(tx => { | ||
tx.executeSql('insert into ? (firstName, lastName, password, username, major, year) VALUES (?, ?, ?, ?, ?, ?)', | ||
[this.users_table, firstName, lastName, password, email, major, year]); | ||
}); | ||
addUser(user) { | ||
console.log(user); | ||
AsyncStorage.setItem(user.email, JSON.stringify(user)); | ||
console.log(user); | ||
} | ||
|
||
/** | ||
* Returns the user associated with the given email address. | ||
* Returns null if no user or multiple users were found. | ||
*/ | ||
async getUser(email) { | ||
user = await AsyncStorage.getItem(email); | ||
user = await JSON.parse(user) || null; | ||
return user; | ||
} | ||
|
||
} | ||
|
||
export const StudyBuddyDB = new Database('studybuddy.db'); | ||
export const StudyBuddyDB = new Database(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3035,6 +3035,17 @@ [email protected]: | |
dependencies: | ||
prop-types "^15.5.10" | ||
|
||
react-native-iphone-x-helper@^1.0.1: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/react-native-iphone-x-helper/-/react-native-iphone-x-helper-1.0.2.tgz#7dbca530930f7c1ce8633cc8fd13ba94102992e1" | ||
|
||
react-native-keyboard-aware-scroll-view@^0.4.3: | ||
version "0.4.3" | ||
resolved "https://registry.yarnpkg.com/react-native-keyboard-aware-scroll-view/-/react-native-keyboard-aware-scroll-view-0.4.3.tgz#206e197730902ce01d026910ff8409a2a363e1ac" | ||
dependencies: | ||
prop-types "^15.6.0" | ||
react-native-iphone-x-helper "^1.0.1" | ||
|
||
[email protected]: | ||
version "0.17.1" | ||
resolved "https://registry.yarnpkg.com/react-native-maps/-/react-native-maps-0.17.1.tgz#ab2236341fd984dac8864202ae55331bc262f60c" | ||
|
@@ -3686,6 +3697,22 @@ tar@^2.2.1: | |
fstream "^1.0.2" | ||
inherits "2" | ||
|
||
tcomb-form-native@^0.6.11: | ||
version "0.6.11" | ||
resolved "https://registry.yarnpkg.com/tcomb-form-native/-/tcomb-form-native-0.6.11.tgz#1fda9d8fc4ed9e954e60f08d4d976ec85e04697e" | ||
dependencies: | ||
tcomb-validation "^3.0.0" | ||
|
||
tcomb-validation@^3.0.0: | ||
version "3.4.1" | ||
resolved "https://registry.yarnpkg.com/tcomb-validation/-/tcomb-validation-3.4.1.tgz#a7696ec176ce56a081d9e019f8b732a5a8894b65" | ||
dependencies: | ||
tcomb "^3.0.0" | ||
|
||
tcomb@^3.0.0: | ||
version "3.2.24" | ||
resolved "https://registry.yarnpkg.com/tcomb/-/tcomb-3.2.24.tgz#7f427053cc393b5997c4c3d859ca20411180887b" | ||
|
||
[email protected]: | ||
version "0.8.3" | ||
resolved "https://registry.yarnpkg.com/temp/-/temp-0.8.3.tgz#e0c6bc4d26b903124410e4fed81103014dfc1f59" | ||
|