Skip to content

Commit cbc2cd1

Browse files
committed
MEAN Stack App
1 parent 161df4b commit cbc2cd1

File tree

8 files changed

+226
-136
lines changed

8 files changed

+226
-136
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,31 @@ passport.use(new GoogleStrategy({
6060
}
6161
```
6262

63+
- You must enter your own sendgrid e-mail information (found in api.js file):
64+
65+
```
66+
var options = {
67+
auth: {
68+
api_user: '', // Enter yourSendgrid username
69+
api_key: '' // Enter your Sendgrid password
70+
}
71+
};
72+
var client = nodemailer.createTransport(sgTransport(options));
73+
```
74+
75+
- You must also update all e-mail callbacks (links that users click for e-mail activation/password reset, etc.) found in the api.js file:
76+
77+
```
78+
var email = {
79+
from: 'MEAN Stack Staff, staff@localhost.com',
80+
to: user.email,
81+
subject: 'Reset Password Request',
82+
text: 'Hello ' + user.name + ', You recently request a password reset link. Please click on the link below to reset your password:<br><br><a href="https://immense-dusk-71112.herokuapp.com/reset/' + user.resettoken,
83+
html: 'Hello<strong> ' + user.name + '</strong>,<br><br>You recently request a password reset link. Please click on the link below to reset your password:<br><br><a href="https://immense-dusk-71112.herokuapp.com/reset/' + user.resettoken + '">https://immense-dusk-71112.herokuapp.com/reset/</a>'
84+
};
85+
86+
```
87+
6388
- Installation is complete. Navigate to folder where server.js file is located and enter the following into command prompt:
6489

6590
```

app/passport/passport.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ module.exports = function(app, passport) {
3333

3434
// Facebook Strategy
3535
passport.use(new FacebookStrategy({
36-
clientID: '', // Replace with your Facebook Developer App client ID
37-
clientSecret: '', // Replace with your Facebook Developer client secret
36+
clientID: '310132302703073', // Replace with your Facebook Developer App client ID
37+
clientSecret: '2e94e77add384b6e2b2029947c3861b4', // Replace with your Facebook Developer client secret
3838
callbackURL: "https://immense-dusk-71112.herokuapp.com/auth/facebook/callback", // Replace with your Facebook Developer App callback URL
3939
profileFields: ['id', 'displayName', 'photos', 'email']
4040
},
@@ -53,8 +53,8 @@ module.exports = function(app, passport) {
5353

5454
// Twitter Strategy
5555
passport.use(new TwitterStrategy({
56-
consumerKey: '', // Replace with your Twitter Developer App consumer key
57-
consumerSecret: '', // Replace with your Twitter Developer App consumer secret
56+
consumerKey: 'nAsRdF40TX5fQ7QivmuJGWWSj', // Replace with your Twitter Developer App consumer key
57+
consumerSecret: 'WH4MaKulaiPzrBttgS5KlQzanXmZIKZ4hmAlflfwX8jk3WNTwA', // Replace with your Twitter Developer App consumer secret
5858
callbackURL: "https://immense-dusk-71112.herokuapp.com/auth/twitter/callback", // Replace with your Twitter Developer App callback URL
5959
userProfileURL: "https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true"
6060
},
@@ -73,8 +73,8 @@ module.exports = function(app, passport) {
7373

7474
// Google Strategy
7575
passport.use(new GoogleStrategy({
76-
clientID: '', // Replace with your Google Developer App client ID
77-
clientSecret: '', // Replace with your Google Developer App client ID
76+
clientID: '852222686887-ld3cnfu1g76lpi0bgrmpbr37css6c3o0.apps.googleusercontent.com', // Replace with your Google Developer App client ID
77+
clientSecret: 'j-k8frTBw-6u-De6vPqk3uSI', // Replace with your Google Developer App client ID
7878
callbackURL: "https://immense-dusk-71112.herokuapp.com/auth/google/callback" // Replace with your Google Developer App callback URL
7979
},
8080
function(accessToken, refreshToken, profile, done) {

app/routes/api.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function(router) {
1010
// Enter your info here, as my account would have likely expired
1111
var options = {
1212
auth: {
13-
api_user: 'dbrian332', // Sendgrid username
13+
api_user: 'meanstackbrock', // Sendgrid username
1414
api_key: 'PAssword123!@#' // Sendgrid password
1515
}
1616
};
@@ -251,7 +251,11 @@ module.exports = function(router) {
251251

252252
// Function to send e-mail to user
253253
client.sendMail(email, function(err, info) {
254-
if (err) console.log(err); // If error in sending e-mail, log to console/terminal
254+
if (err) {
255+
console.log(err); // If error in sending e-mail, log to console/terminal
256+
} else {
257+
console.log(info); // Log confirmation to console
258+
}
255259
});
256260
res.json({ success: true, message: 'Username has been sent to e-mail! ' }); // Return success message once e-mail has been sent
257261
}
@@ -284,7 +288,12 @@ module.exports = function(router) {
284288
};
285289
// Function to send e-mail to the user
286290
client.sendMail(email, function(err, info) {
287-
if (err) console.log(err); // If error with sending e-mail, log to console/terminal
291+
if (err) {
292+
console.log(err); // If error with sending e-mail, log to console/terminal
293+
} else {
294+
console.log(info); // Log success message to console
295+
console.log('sent to: ' + user.email); // Log e-mail
296+
}
288297
});
289298
res.json({ success: true, message: 'Please check your e-mail for password reset link' }); // Return success message
290299
}

public/app/controllers/emailCtrl.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ angular.module('emailController', ['userServices'])
5858
})
5959

6060
// Controller: usernameCtrl is used to send the user his/her username to e-mail if forgotten
61-
.controller('usernameCtrl', function(User) {
61+
.controller('usernameCtrl', function(User, $scope) {
6262

6363
app = this;
6464

@@ -75,22 +75,25 @@ angular.module('emailController', ['userServices'])
7575
app.loading = false; // Stop loading icon
7676
// Check if username was sent successfully to e-mail
7777
if (data.data.success) {
78+
$scope.alert = 'alert alert-success'; // Set success message class
7879
app.successMsg = data.data.message; // If success, grab message from JSON object
7980
} else {
8081
app.disabled = false; // Enable form to allow user to retry
82+
$scope.alert = 'alert alert-danger'; // Set alert class
8183
app.errorMsg = data.data.message; // If error, grab message from JSON object
8284
}
8385
});
8486
} else {
8587
app.disabled = false; // Enable form to allow user to retry
8688
app.loading = false; // Stop loading icon
89+
$scope.alert = 'alert alert-danger'; // Set alert class
8790
app.errorMsg = 'Please enter a valid e-mail'; // Let user know form is not valid
8891
}
8992
};
9093
})
9194

9295
// Controller: passwordCtrl is used to send a password reset link to the user
93-
.controller('passwordCtrl', function(User) {
96+
.controller('passwordCtrl', function(User, $scope) {
9497

9598
app = this;
9699

@@ -107,15 +110,18 @@ angular.module('emailController', ['userServices'])
107110
app.loading = false; // Stop loading icon
108111
// Check if reset link was sent
109112
if (data.data.success) {
113+
$scope.alert = 'alert alert-success'; // Set success message class
110114
app.successMsg = data.data.message; // Grab success message from JSON object
111115
} else {
116+
$scope.alert = 'alert alert-danger'; // Set success message class
112117
app.disabled = false; // Enable form to allow user to resubmit
113118
app.errorMsg = data.data.message; // Grab error message from JSON object
114119
}
115120
});
116121
} else {
117122
app.disabled = false; // Enable form to allow user to resubmit
118123
app.loading = false; // Stop loading icon
124+
$scope.alert = 'alert alert-danger'; // Set success message class
119125
app.errorMsg = 'Please enter a valid username'; // Let user know form is not valid
120126
}
121127
};
@@ -132,16 +138,19 @@ angular.module('emailController', ['userServices'])
132138
// Check if user was retrieved
133139
if (data.data.success) {
134140
app.hide = false; // Show form
141+
$scope.alert = 'alert alert-success'; // Set success message class
135142
app.successMsg = 'Please enter a new password'; // Let user know they can enter new password
136143
$scope.username = data.data.user.username; // Save username in scope for use in savePassword() function
137144
} else {
145+
$scope.alert = 'alert alert-danger'; // Set success message class
138146
app.errorMsg = data.data.message; // Grab error message from JSON object
139147
}
140148
});
141149

142150
// Function to save user's new password to database
143151
app.savePassword = function(regData, valid, confirmed) {
144152
app.errorMsg = false; // Clear errorMsg when user submits
153+
app.successMsg = false;
145154
app.disabled = true; // Disable form while processing
146155
app.loading = true; // Enable loading icon
147156

@@ -154,17 +163,20 @@ angular.module('emailController', ['userServices'])
154163
app.loading = false; // Stop loading icon
155164
// Check if password was saved to database
156165
if (data.data.success) {
166+
$scope.alert = 'alert alert-success'; // Set success message class
157167
app.successMsg = data.data.message + '...Redirecting'; // Grab success message from JSON object and redirect
158168
// Redirect to login page after 2000 milliseconds (2 seconds)
159169
$timeout(function() {
160170
$location.path('/login');
161171
}, 2000);
162172
} else {
173+
$scope.alert = 'alert alert-danger'; // Set success message class
163174
app.disabled = false; // Enable form to allow user to resubmit
164175
app.errorMsg = data.data.message; // Grab error message from JSON object
165176
}
166177
});
167178
} else {
179+
$scope.alert = 'alert alert-danger'; // Set success message class
168180
app.loading = false; // Stop loading icon
169181
app.disabled = false; // Enable form to allow user to resubmit
170182
app.errorMsg = 'Please ensure form is filled out properly'; // Let user know form is not valid

public/app/views/pages/users/login.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ <h3 class="section-subheading text-muted">Please enter your login information.</
3737
</div>
3838
<div class="clearfix"></div>
3939
<div class="col-lg-12 text-left">
40+
<div>
41+
<a href="/resetpassword">
42+
<button ng-disabled="main.disabled || facebook.disabled || twitter.disabled || google.disabled" type="button" class="btn btn-danger">Forgot Password</button>
43+
</a>
44+
<a href="/resetusername">
45+
<button ng-disabled="main.disabled || facebook.disabled || twitter.disabled || google.disabled" type="button" class="btn btn-info">Forgot Username</button>
46+
</a>
47+
</div>
48+
<br>
4049
<div id="success"></div>
4150
<!-- Login Button -->
4251
<button type="submit" class="btn btn-xl">Login</button>

0 commit comments

Comments
 (0)