Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ $ use lizardboard
```
MONGODB_URI=mongodb://localhost/lizardboard
SECRET='Put Your Secret Here'
FRONTEND_SERVER='http://localhost:3000'
```
###### Install all the things
```
Expand Down
19 changes: 12 additions & 7 deletions models/users.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
const mongoose = require( 'mongoose' )
const Schema = mongoose.Schema
const bcrypt = require( 'bcrypt-nodejs' )
const randtoken = require('rand-token')

const UserSchema = new Schema({
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
token: { type: String },
token_expires: { type: Date },
created_at: Date,
updated_at: Date
})
name: { type: String, required: true},
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
phone_number: { type: String },
newsletter_subscribed: { type: Boolean, default: false },
API_key: { type: String, default: () => { return randtoken.generate(32) }},
company: { type: String },
dragonboard_bar: { type: Boolean, default: true },
active: { type: Boolean, default: true }
},
{ timestamps: true })

UserSchema.pre( 'save', function( next ) {
const user = this
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"passport-jwt": "^2.2.1",
"passport-local": "^1.0.0",
"pug": "^2.0.0-beta6",
"rand-token": "^0.3.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell me about the need for adding this dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we used it in the UserSchema to generate a random API key for users when a new one is created.

"react": "^15.3.2",
"react-dom": "^15.3.2",
"react-router": "^2.6.1"
Expand Down
2 changes: 1 addition & 1 deletion src/authentication/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const generateToken = user => {

const userInfo = user => ({
email: user.email,
_id: user._id
password: user.password
})

const tokenInfo = user => {
Expand Down
13 changes: 8 additions & 5 deletions src/authentication/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const { generateToken, userInfo, tokenInfo } = require( './authentication' )
const ERROR_MESSAGE = 'Cannot authenticate request'

exports.register = ( request, response, next ) => {
const { email, password } = request.body
const {
name, email, password, phone_number, newsletter_subscribed, company
} = request.body

if( !email ) {
return response.status( 422 ).send({ error: ERROR_MESSAGE })
Expand All @@ -21,14 +23,15 @@ exports.register = ( request, response, next ) => {
return response.status( 422 ).send({ error: ERROR_MESSAGE })
}

const user = new User({ email, password })
const user = new User({
name, email, password, phone_number, newsletter_subscribed, company
})

user.save(( err, user ) => {
if( err ) {
return next( err )
}

return response.status( 201 ).json( tokenInfo( user ))
response.redirect( process.env.FRONTEND_SERVER + '/dashboard' )
})
})
}
}