-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature-[167573212]: implement login feature
- added login route - tested login route - created user model, migration and seeds file - added a findUser helper function - added a password helper function that compares password [finishes #167573212]
- Loading branch information
Showing
22 changed files
with
561 additions
and
15 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import helpers from '../helpers'; | ||
|
||
const { | ||
comparePassword, findUser, serverResponse, serverError | ||
} = helpers; | ||
// const { | ||
// comparePassword, findUser, generateToken, serverResponse, serverError | ||
// } = helpers; | ||
/** | ||
* | ||
* | ||
* @class User | ||
*/ | ||
class User { | ||
/** | ||
* | ||
* | ||
* @static | ||
* @param {object} req - request object | ||
* @param {object} res - response object | ||
* @memberof User | ||
* @returns {json} object | ||
*/ | ||
static async login(req, res) { | ||
try { | ||
const { userLogin, password } = req.body; | ||
if (!/\D/.test(userLogin)) { | ||
return serverResponse(res, 400, { | ||
message: 'user login must be a string' | ||
}); | ||
} | ||
const user = await findUser(userLogin); | ||
let verifyPassword; | ||
if (user) verifyPassword = await comparePassword(password, user.password); | ||
if (!user || !verifyPassword) { | ||
return serverResponse(res, 403, { | ||
message: 'incorrect username or password' | ||
}); | ||
} | ||
const { dataValues } = user; | ||
// const token = generateToken(id); | ||
delete dataValues.password; | ||
return serverResponse(res, 200, { user: { ...dataValues } }); | ||
} catch (error) { | ||
serverError(res); | ||
} | ||
} | ||
} | ||
|
||
export default User; |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('Users', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
firstName: { | ||
allowNull: false, | ||
type: Sequelize.STRING | ||
}, | ||
lastName: { | ||
allowNull: false, | ||
type: Sequelize.STRING | ||
}, | ||
userName: { | ||
allowNull: false, | ||
unique: true, | ||
type: Sequelize.STRING | ||
}, | ||
email: { | ||
allowNull: false, | ||
unique: true, | ||
type: Sequelize.STRING | ||
}, | ||
password: { | ||
allowNull: false, | ||
type: Sequelize.STRING | ||
}, | ||
avatarUrl: { | ||
allowNull: false, | ||
type: Sequelize.STRING | ||
}, | ||
facebookId: { | ||
type: Sequelize.BIGINT | ||
}, | ||
googleId: { | ||
type: Sequelize.BIGINT | ||
}, | ||
twitterId: { | ||
type: Sequelize.BIGINT | ||
}, | ||
verified: { | ||
allowNull: false, | ||
type: Sequelize.BOOLEAN, | ||
defaultValue: false | ||
}, | ||
status: { | ||
allowNull: false, | ||
type: Sequelize.STRING, | ||
defaultValue: 'active' | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: queryInterface => queryInterface.dropTable('Users') | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = (sequelize, DataTypes) => { | ||
const User = sequelize.define( | ||
'User', | ||
{ | ||
firstName: DataTypes.STRING, | ||
lastName: DataTypes.STRING, | ||
userName: DataTypes.STRING, | ||
email: DataTypes.STRING, | ||
password: DataTypes.STRING, | ||
avatarUrl: DataTypes.STRING, | ||
facebookId: DataTypes.BIGINT, | ||
googleId: DataTypes.BIGINT, | ||
twitterId: DataTypes.BIGINT, | ||
verified: DataTypes.BOOLEAN, | ||
status: DataTypes.STRING | ||
}, | ||
{} | ||
); | ||
User.associate = (models) => { | ||
// associations can be defined here | ||
}; | ||
return User; | ||
}; |
Oops, something went wrong.