Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f48fc03

Browse files
committed
+First & Last Name on DB && Setup On Account Creation
1 parent 8c2676b commit f48fc03

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

‎src/controllers/User/Account/signup.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,31 @@ module.exports.signup = async (req, res) => {
6161

6262
if (users?.length) return res.status(403).send({ msg: "Account Already Exists." });
6363

64+
65+
// hash the password
66+
6467
const hashString = hash(req.body.password, 10, (err, hashString) => {
6568
if (err) return res.status(500).send({ msg: "Error on signup." })
6669
return hashString;
6770
});
6871

72+
// extract the first and the last name
73+
let credentials = req.body.username.split('-');
74+
75+
// first name will be the first word of the split
76+
const firstName = credentials[0];
77+
78+
// remove the first name from the array of words
79+
credentials.shift();
80+
81+
// last name will be all the remaining words combained
82+
const lastName = credentials.join('');
83+
84+
6985
const newUser = await User.create({
7086
username: req.body.username,
87+
firstName: firstName,
88+
lastName: lastName,
7189
password: hashString,
7290
email: req.body.email,
7391
profilePicture: "https://fairfield-programming.herokuapp.com/duck/10001000005000043/",

‎src/controllers/User/Helpers/queryUser.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports.queryUser = async (req, res) => {
2424
where: {
2525
id: req.params.id,
2626
},
27-
attributes: ['username', 'email', 'profilePicture', 'biography', 'createdAt'],
27+
attributes: ['username', 'email', 'firstName', 'lastName', 'profilePicture','biography'],
2828
})
2929

3030
if (!user) return res.status(404).send({ msg: 'Not Found.' });

‎src/models/User.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module.exports = (sequelize, DataTypes) => {
22
return sequelize.define('User', {
33
username: DataTypes.STRING,
4+
firstName: DataTypes.STRING,
5+
lastName: DataTypes.STRING,
46
password: DataTypes.TEXT,
57
email: DataTypes.TEXT,
68
biography: DataTypes.TEXT,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /