Bio added to user profile.
This commit is contained in:
1 parent
7f412f9c97
commit
5b96487665
6 files changed
+215
-222
No files matched your search
@@ -113,7 +113,7 @@ class UserList extends Component {
|
||||
{user.alias}
|
||||
</Typography>
|
||||
<Typography component="p">
|
||||
I am a computer nerd passionate about crypto trading. I entered the crypto space in 2013 and since then I ve been participating in quite a few crypto open source projects.
|
||||
{user.bio}
|
||||
</Typography>
|
||||
</CardContent>
|
||||
</CardActionArea>
|
||||
|
||||
@@ -77,7 +77,7 @@ class UserProfile extends Component {
|
||||
<Divider />
|
||||
|
||||
<Typography className={classes.typography} component='p'>
|
||||
I am a computer nerd passionate about crypto trading. I entered the crypto space in 2013 and since then I ve been participating in quite a few crypto open source projects.
|
||||
{ user.bio }
|
||||
</Typography>
|
||||
</CardContent>
|
||||
</CardActionArea>
|
||||
|
||||
@@ -64,6 +64,7 @@ class UserUpdate extends Component {
|
||||
firstName: '',
|
||||
middleName: '',
|
||||
lastName: '',
|
||||
bio: '',
|
||||
email: '',
|
||||
emailVerified: 0,
|
||||
isDeveloper: 0,
|
||||
@@ -96,6 +97,7 @@ class UserUpdate extends Component {
|
||||
firstName: this.state.firstName,
|
||||
middleName: this.state.middleName,
|
||||
lastName: this.state.lastName,
|
||||
bio: this.state.bio,
|
||||
isDeveloper: this.state.isDeveloper,
|
||||
isTrader: this.state.isTrader,
|
||||
isDataAnalyst: this.state.isDataAnalyst,
|
||||
@@ -111,7 +113,7 @@ class UserUpdate extends Component {
|
||||
user.firstName = this.state.firstName
|
||||
user.middleName = this.state.middleName
|
||||
user.lastName = this.state.lastName
|
||||
user.firstName = this.state.firstName
|
||||
user.bio = this.state.bio
|
||||
user.isDeveloper = this.state.isDeveloper
|
||||
user.isTrader = this.state.isTrader
|
||||
user.isDataAnalyst = this.state.isDataAnalyst
|
||||
@@ -199,6 +201,7 @@ class UserUpdate extends Component {
|
||||
firstName: user.firstName,
|
||||
middleName: user.middleName,
|
||||
lastName: user.lastName,
|
||||
bio: user.bio,
|
||||
isDeveloper: user.isDeveloper,
|
||||
isTrader: user.isTrader,
|
||||
isDataAnalyst: user.isDataAnalyst,
|
||||
@@ -279,6 +282,19 @@ class UserUpdate extends Component {
|
||||
onChange={(e) => this.setState({lastName: e.target.value})}
|
||||
/>
|
||||
|
||||
<Typography className={classes.typography} variant='body1' gutterBottom align='left'>
|
||||
If you wish, you can add a short paragraph with your Bio or anything you would like to communicate to whoever finds your user profile.
|
||||
</Typography>
|
||||
|
||||
<TextField
|
||||
id='bio'
|
||||
type='text'
|
||||
value={this.state.bio}
|
||||
label='Bio'
|
||||
className={classes.inputField}
|
||||
onChange={(e) => this.setState({bio: e.target.value})}
|
||||
/>
|
||||
|
||||
<Typography className={classes.typography} variant='body1' gutterBottom align='left'>
|
||||
Check the following options to enable specialized tools designed for each role. You can allways come back and change these settings later.
|
||||
</Typography>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import gql from 'graphql-tag';
|
||||
import gql from 'graphql-tag'
|
||||
|
||||
const getUsersQuery = gql`
|
||||
{
|
||||
@@ -8,6 +8,7 @@ const getUsersQuery = gql`
|
||||
firstName
|
||||
middleName
|
||||
lastName
|
||||
bio
|
||||
role {
|
||||
id
|
||||
name
|
||||
@@ -24,6 +25,7 @@ query($id: ID){
|
||||
firstName
|
||||
middleName
|
||||
lastName
|
||||
bio
|
||||
email
|
||||
emailVerified
|
||||
role {
|
||||
@@ -42,6 +44,7 @@ query($authId: String){
|
||||
firstName
|
||||
middleName
|
||||
lastName
|
||||
bio
|
||||
email
|
||||
emailVerified
|
||||
isDeveloper
|
||||
@@ -69,6 +72,7 @@ mutation(
|
||||
$firstName:String,
|
||||
$middleName:String,
|
||||
$lastName:String,
|
||||
$bio:String,
|
||||
$isDeveloper:Int,
|
||||
$isTrader:Int,
|
||||
$isDataAnalyst:Int,
|
||||
@@ -80,6 +84,7 @@ mutation(
|
||||
firstName:$firstName,
|
||||
middleName: $middleName,
|
||||
lastName: $lastName,
|
||||
bio: $bio,
|
||||
isDeveloper: $isDeveloper,
|
||||
isTrader: $isTrader,
|
||||
isDataAnalyst: $isDataAnalyst,
|
||||
|
||||
+16
-15
@@ -1,19 +1,20 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
const mongoose = require('mongoose')
|
||||
const Schema = mongoose.Schema
|
||||
|
||||
const userSchema = new Schema({
|
||||
authId: String,
|
||||
alias: String,
|
||||
firstName:String,
|
||||
middleName:String,
|
||||
lastName: String,
|
||||
email: String,
|
||||
emailVerified: Boolean,
|
||||
isDeveloper: Boolean,
|
||||
isTrader: Boolean,
|
||||
isDataAnalyst: Boolean,
|
||||
roleId: String
|
||||
authId: String,
|
||||
alias: String,
|
||||
firstName: String,
|
||||
middleName: String,
|
||||
lastName: String,
|
||||
email: String,
|
||||
emailVerified: Boolean,
|
||||
bio: String,
|
||||
isDeveloper: Boolean,
|
||||
isTrader: Boolean,
|
||||
isDataAnalyst: Boolean,
|
||||
roleId: String
|
||||
})
|
||||
|
||||
global.UserSchema = global.UserSchema || mongoose.model('User', userSchema);
|
||||
module.exports = global.UserSchema;
|
||||
global.UserSchema = global.UserSchema || mongoose.model('User', userSchema)
|
||||
module.exports = global.UserSchema
|
||||
+174
-203
@@ -1,10 +1,10 @@
|
||||
const MODULE_NAME = "schema";
|
||||
const MODULE_NAME = 'schema'
|
||||
|
||||
const graphql = require('graphql');
|
||||
const _ = require('lodash');
|
||||
const User = require('../models/user');
|
||||
const graphql = require('graphql')
|
||||
const _ = require('lodash')
|
||||
const User = require('../models/user')
|
||||
|
||||
const tokenDecoder = require('../auth/token-decoder');
|
||||
const tokenDecoder = require('../auth/token-decoder')
|
||||
|
||||
const {
|
||||
GraphQLObjectType,
|
||||
@@ -14,14 +14,14 @@ const {
|
||||
GraphQLInt,
|
||||
GraphQLList,
|
||||
GraphQLNonNull
|
||||
} = graphql; // Destructuring this variables from inside the package.
|
||||
} = graphql // Destructuring this variables from inside the package.
|
||||
|
||||
let roles = [
|
||||
{id: '1', name: 'Not Defined'},
|
||||
{id: '2', name: 'Developer'},
|
||||
{id: '3', name: 'Trader'},
|
||||
{id: '4', name: 'Data Analyst'}
|
||||
];
|
||||
]
|
||||
|
||||
// Types
|
||||
|
||||
@@ -34,6 +34,7 @@ const UserType = new GraphQLObjectType({
|
||||
firstName: {type: GraphQLString},
|
||||
middleName: {type: GraphQLString},
|
||||
lastName: {type: GraphQLString},
|
||||
bio: {type: GraphQLString},
|
||||
email: {type: GraphQLString},
|
||||
emailVerified: {type: GraphQLInt},
|
||||
isDeveloper: {type: GraphQLInt},
|
||||
@@ -41,12 +42,12 @@ const UserType = new GraphQLObjectType({
|
||||
isDataAnalyst: {type: GraphQLInt},
|
||||
role: {
|
||||
type: RoleType,
|
||||
resolve(parent, args) {
|
||||
return _.find(roles, {id: parent.roleId});
|
||||
resolve (parent, args) {
|
||||
return _.find(roles, {id: parent.roleId})
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
const RoleType = new GraphQLObjectType({
|
||||
name: 'Role',
|
||||
@@ -55,81 +56,78 @@ const RoleType = new GraphQLObjectType({
|
||||
name: {type: GraphQLString},
|
||||
users: {
|
||||
type: new GraphQLList(UserType),
|
||||
resolve(parent, args) {
|
||||
return User.find({roleId: parent.id});
|
||||
resolve (parent, args) {
|
||||
return User.find({roleId: parent.id})
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
// RootQueries
|
||||
|
||||
const RootQuery = new GraphQLObjectType({
|
||||
name: 'RootQueryType',
|
||||
fields: {
|
||||
user: {
|
||||
type: UserType,
|
||||
args: {id: {type: GraphQLID}},
|
||||
resolve(parent,args) {
|
||||
user: {
|
||||
type: UserType,
|
||||
args: {id: {type: GraphQLID}},
|
||||
resolve (parent, args) {
|
||||
// Code to get data from data source.
|
||||
return User.findById(args.id);
|
||||
}
|
||||
},
|
||||
userByAuthId: {
|
||||
type: UserType,
|
||||
args: {authId: {type: GraphQLString}},
|
||||
resolve(parent,args) {
|
||||
return User.findById(args.id)
|
||||
}
|
||||
},
|
||||
userByAuthId: {
|
||||
type: UserType,
|
||||
args: {authId: {type: GraphQLString}},
|
||||
resolve (parent, args) {
|
||||
// Code to get data from data source.
|
||||
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Entering function."); }
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Entering function.') }
|
||||
|
||||
/* In order to be able to wait for asyc calls to the database, we need to return a promise to GraphQL. */
|
||||
|
||||
const promiseToGraphQL = new Promise((resolve, reject) => {
|
||||
const promiseToGraphQL = new Promise((resolve, reject) => {
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> Entering function.') }
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> args.authId = ' + args.authId) }
|
||||
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> Entering function."); }
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> args.authId = " + args.authId); }
|
||||
findUserByAuthId(args.authId, onUserFound)
|
||||
|
||||
findUserByAuthId(args.authId, onUserFound);
|
||||
function onUserFound (err, responseToGraphQL) {
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> Entering function.') }
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> responseToGraphQL = ' + JSON.stringify(responseToGraphQL)) }
|
||||
|
||||
function onUserFound(err, responseToGraphQL) {
|
||||
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> Entering function."); }
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> responseToGraphQL = " + JSON.stringify(responseToGraphQL)); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> err.message = " + err.message); }
|
||||
reject (responseToGraphQL);
|
||||
} else {
|
||||
resolve (responseToGraphQL);
|
||||
}
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> err.message = ' + err.message) }
|
||||
reject(responseToGraphQL)
|
||||
} else {
|
||||
resolve(responseToGraphQL)
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
return promiseToGraphQL;
|
||||
|
||||
}
|
||||
},
|
||||
role: {
|
||||
type: RoleType,
|
||||
args: {id: {type: GraphQLID}},
|
||||
resolve(parent,args) {
|
||||
// Code to get data from data source.
|
||||
return _.find(roles, {id: args.id});
|
||||
}
|
||||
},
|
||||
users: {
|
||||
type: new GraphQLList(UserType),
|
||||
resolve(parent, args){
|
||||
return User.find({});
|
||||
}
|
||||
},
|
||||
roles: {
|
||||
type: new GraphQLList(RoleType),
|
||||
resolve(parent, args){
|
||||
return roles;
|
||||
}
|
||||
return promiseToGraphQL
|
||||
}
|
||||
},
|
||||
role: {
|
||||
type: RoleType,
|
||||
args: {id: {type: GraphQLID}},
|
||||
resolve (parent, args) {
|
||||
// Code to get data from data source.
|
||||
return _.find(roles, {id: args.id})
|
||||
}
|
||||
},
|
||||
users: {
|
||||
type: new GraphQLList(UserType),
|
||||
resolve (parent, args) {
|
||||
return User.find({})
|
||||
}
|
||||
},
|
||||
roles: {
|
||||
type: new GraphQLList(RoleType),
|
||||
resolve (parent, args) {
|
||||
return roles
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -143,160 +141,140 @@ const Mutation = new GraphQLObjectType({
|
||||
args: {
|
||||
idToken: {type: new GraphQLNonNull(GraphQLString)}
|
||||
},
|
||||
resolve(parent, args) {
|
||||
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> Mutation -> authenticate -> resolve -> Entering function."); }
|
||||
resolve (parent, args) {
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Entering function.') }
|
||||
|
||||
/* In order to be able to wait for asyc calls to the database, and authorization authority, we need to return a promise to GraphQL. */
|
||||
|
||||
const promiseToGraphQL = new Promise((resolve, reject) => {
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Promise -> Entering function.') }
|
||||
authenticate(args.idToken, onAuthenticated)
|
||||
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> Mutation -> authenticate -> resolve -> Promise -> Entering function."); }
|
||||
authenticate(args.idToken, onAuthenticated);
|
||||
|
||||
function onAuthenticated(err, responseToGraphQL) {
|
||||
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> Entering function."); }
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> responseToGraphQL = " + JSON.stringify(responseToGraphQL)); }
|
||||
function onAuthenticated (err, responseToGraphQL) {
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> Entering function.') }
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> responseToGraphQL = ' + JSON.stringify(responseToGraphQL)) }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> err.message = " + err.message); }
|
||||
reject (responseToGraphQL);
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> err.message = ' + err.message) }
|
||||
reject(responseToGraphQL)
|
||||
} else {
|
||||
resolve (responseToGraphQL);
|
||||
resolve(responseToGraphQL)
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
return promiseToGraphQL;
|
||||
return promiseToGraphQL
|
||||
}
|
||||
},
|
||||
updateUser:{
|
||||
updateUser: {
|
||||
type: UserType,
|
||||
args: {
|
||||
id: {type: new GraphQLNonNull(GraphQLID)},
|
||||
firstName: {type: GraphQLString},
|
||||
middleName: {type: GraphQLString},
|
||||
lastName: {type: GraphQLString},
|
||||
bio: {type: GraphQLString},
|
||||
isDeveloper: {type: GraphQLInt},
|
||||
isTrader: {type: GraphQLInt},
|
||||
isDataAnalyst: {type: GraphQLInt},
|
||||
roleId: {type: new GraphQLNonNull(GraphQLString)}
|
||||
},
|
||||
resolve(parent, args) {
|
||||
|
||||
resolve (parent, args) {
|
||||
let key = {
|
||||
_id: args.id
|
||||
};
|
||||
}
|
||||
|
||||
let updatedUser = {
|
||||
firstName: args.firstName,
|
||||
middleName: args.middleName,
|
||||
lastName: args.lastName,
|
||||
bio: args.bio,
|
||||
isDeveloper: args.isDeveloper,
|
||||
isTrader: args.isTrader,
|
||||
isDataAnalyst: args.isDataAnalyst,
|
||||
roleId: args.roleId
|
||||
};
|
||||
}
|
||||
|
||||
return User.update(key, updatedUser);
|
||||
return User.update(key, updatedUser)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
function findUserByAuthId(authId, callBackFunction) {
|
||||
|
||||
function findUserByAuthId (authId, callBackFunction) {
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> Entering function."); }
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> authId = " + authId); }
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> Entering function.') }
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> authId = ' + authId) }
|
||||
|
||||
if (authId === null || authId === undefined) {
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> User requested not specified.') }
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> args.authId = ' + authId) }
|
||||
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> User requested not specified."); }
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> args.authId = " + authId); }
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: "Bad Request" });
|
||||
return;
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: 'Bad Request' })
|
||||
return
|
||||
}
|
||||
|
||||
User.findOne({authId: authId}, onUserReceived)
|
||||
|
||||
function onUserReceived(err, user) {
|
||||
|
||||
if(err) {
|
||||
if (ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> Database Error."); }
|
||||
if (ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> err = " + err); }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err });
|
||||
}
|
||||
else{
|
||||
|
||||
function onUserReceived (err, user) {
|
||||
if (err) {
|
||||
if (ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> Database Error.') }
|
||||
if (ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> err = ' + err) }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err })
|
||||
} else {
|
||||
if (user === null) {
|
||||
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> User not found at Database."); }
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> args.authId = " + authId); }
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> User not found at Database.') }
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> args.authId = ' + authId) }
|
||||
|
||||
let customResponse = {
|
||||
result: global.CUSTOM_OK_RESPONSE.result,
|
||||
message: "User Not Found"
|
||||
};
|
||||
result: global.CUSTOM_OK_RESPONSE.result,
|
||||
message: 'User Not Found'
|
||||
}
|
||||
|
||||
callBackFunction(customResponse, { error: customResponse.message });
|
||||
return;
|
||||
callBackFunction(customResponse, { error: customResponse.message })
|
||||
return
|
||||
}
|
||||
|
||||
if (user.authId === authId && user.authId !== undefined) {
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> User found at Database.') }
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> args.authId = ' + authId) }
|
||||
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> User found at Database."); }
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> args.authId = " + authId); }
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, user);
|
||||
return;
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, user)
|
||||
return
|
||||
} else {
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> User found at Database is not the user requested.') }
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> args.authId = ' + authId) }
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> findUserByAuthId -> onUserReceived -> user.authId = ' + user.authId) }
|
||||
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> User found at Database is not the user requested."); }
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> args.authId = " + authId); }
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> user.authId = " + user.authId); }
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err });
|
||||
return;
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err })
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(err) {
|
||||
|
||||
if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> findUserByAuthId -> err.message = " + err.message); }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err });
|
||||
|
||||
} catch (err) {
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> findUserByAuthId -> err.message = ' + err.message) }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err })
|
||||
}
|
||||
}
|
||||
|
||||
function authenticate (encodedToken, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> authenticate -> Entering function.') }
|
||||
|
||||
let authId = ''
|
||||
let alias = ''
|
||||
let email = ''
|
||||
let emailVerified = false
|
||||
|
||||
function authenticate(encodedToken, callBackFunction) {
|
||||
tokenDecoder(encodedToken, onValidated)
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> Entering function."); }
|
||||
|
||||
let authId = "";
|
||||
let alias = "";
|
||||
let email = "";
|
||||
let emailVerified = false;
|
||||
|
||||
tokenDecoder(encodedToken, onValidated);
|
||||
|
||||
function onValidated(err, decodedToken) {
|
||||
|
||||
if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> Entering function."); }
|
||||
function onValidated (err, decodedToken) {
|
||||
if (global.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> Entering function.') }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> authenticate -> onValidated -> err.message = " + err.message); }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err });
|
||||
return;
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> err.message = ' + err.message) }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err })
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -306,27 +284,26 @@ try {
|
||||
|
||||
*/
|
||||
|
||||
authId = decodedToken.sub;
|
||||
alias = decodedToken.nickname;
|
||||
email = decodedToken.email;
|
||||
emailVerified = decodedToken.email_verified;
|
||||
authId = decodedToken.sub
|
||||
alias = decodedToken.nickname
|
||||
email = decodedToken.email
|
||||
emailVerified = decodedToken.email_verified
|
||||
|
||||
findUserByAuthId(authId, onUserFound);
|
||||
findUserByAuthId(authId, onUserFound)
|
||||
|
||||
function onUserFound(err, user){
|
||||
|
||||
if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> Entering function."); }
|
||||
function onUserFound (err, user) {
|
||||
if (global.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> Entering function.') }
|
||||
|
||||
if (err.result === global.DEFAULT_FAIL_RESPONSE.result) {
|
||||
if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> err.message = " + err.message); }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err });
|
||||
return;
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> err.message = ' + err.message) }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err })
|
||||
return
|
||||
}
|
||||
|
||||
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
|
||||
if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> User already exists at database"); }
|
||||
if (global.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> User already exists at database') }
|
||||
|
||||
if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> Existing User: " + JSON.stringify(user)); }
|
||||
if (global.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> Existing User: ' + JSON.stringify(user)) }
|
||||
|
||||
/*
|
||||
|
||||
@@ -335,18 +312,17 @@ try {
|
||||
|
||||
*/
|
||||
|
||||
global.Sessions.set(encodedToken, user.id);
|
||||
global.Sessions.set(encodedToken, user.id)
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, { authId: authId, alias: user.alias });
|
||||
return;
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, { authId: authId, alias: user.alias })
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
err.result === global.CUSTOM_OK_RESPONSE.result &&
|
||||
err.message === "User Not Found"
|
||||
err.message === 'User Not Found'
|
||||
) {
|
||||
|
||||
if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> User does not exist at database"); }
|
||||
if (global.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> User does not exist at database') }
|
||||
|
||||
/*
|
||||
|
||||
@@ -358,41 +334,39 @@ try {
|
||||
|
||||
/* The user can sign up with many different possible social accounts. Currently this module only supports Github only. */
|
||||
|
||||
let authArray = authId.split("|");
|
||||
let socialAccountProvider = authArray[0];
|
||||
let authArray = authId.split('|')
|
||||
let socialAccountProvider = authArray[0]
|
||||
|
||||
if(socialAccountProvider !== 'github') {
|
||||
if (socialAccountProvider !== 'github') {
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> Social Account Provider not Supoorted. ') }
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> socialAccountProvider = ' + socialAccountProvider) }
|
||||
|
||||
if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> Social Account Provider not Supoorted. "); }
|
||||
if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> socialAccountProvider = " + socialAccountProvider); }
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err });
|
||||
return;
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err })
|
||||
return
|
||||
}
|
||||
|
||||
let newUser = new User({
|
||||
alias: alias,
|
||||
authId: authId,
|
||||
email: email,
|
||||
emailVerified: emailVerified,
|
||||
roleId: "1"
|
||||
});
|
||||
let newUser = new User({
|
||||
alias: alias,
|
||||
authId: authId,
|
||||
email: email,
|
||||
emailVerified: emailVerified,
|
||||
roleId: '1'
|
||||
})
|
||||
|
||||
if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> " + alias + " being added to the database"); }
|
||||
if (global.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> ' + alias + ' being added to the database') }
|
||||
|
||||
newUser.save(onSaved);
|
||||
newUser.save(onSaved)
|
||||
|
||||
function onSaved(err, savedUser) {
|
||||
function onSaved (err, savedUser) {
|
||||
if (global.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> onSaved -> Entering function.') }
|
||||
|
||||
if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> onSaved -> Entering function."); }
|
||||
if (err) {
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> onSaved -> err = ' + err) }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err })
|
||||
return
|
||||
}
|
||||
|
||||
if (err) {
|
||||
if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> onSaved -> err = " + err); }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err });
|
||||
return;
|
||||
}
|
||||
|
||||
if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> onSaved -> Saved User: " + JSON.stringify(savedUser)); }
|
||||
if (global.INFO_LOG === true) { console.log('[INFO] ' + MODULE_NAME + ' -> authenticate -> onValidated -> onUserFound -> onSaved -> Saved User: ' + JSON.stringify(savedUser)) }
|
||||
|
||||
/*
|
||||
|
||||
@@ -401,23 +375,20 @@ try {
|
||||
|
||||
*/
|
||||
|
||||
global.Sessions.set(encodedToken, savedUser.id);
|
||||
global.Sessions.set(encodedToken, savedUser.id)
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, { authId, alias });
|
||||
|
||||
}
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, { authId, alias })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(err) {
|
||||
|
||||
if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> authenticate -> err.message = " + err.message); }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err });
|
||||
|
||||
} catch (err) {
|
||||
if (global.ERROR_LOG === true) { console.log('[ERROR] ' + MODULE_NAME + ' -> authenticate -> err.message = ' + err.message) }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err })
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new GraphQLSchema({
|
||||
query: RootQuery,
|
||||
mutation: Mutation
|
||||
});
|
||||
})
|
||||
Reference in new issue
Block a user