-
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.
- Loading branch information
Showing
23 changed files
with
562 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
javascript: | ||
enabled: false | ||
eslint: | ||
enabled: true | ||
config_file: .eslintrc | ||
config_file: .eslintrc.json | ||
ignore_file: .eslintignore |
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.