Skip to content

Commit ce2864d

Browse files
committed
MEAN Stack App
1 parent eadf131 commit ce2864d

File tree

3 files changed

+97
-66
lines changed

3 files changed

+97
-66
lines changed

public/app/controllers/emailCtrl.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,42 @@ angular.module('emailController', ['userServices'])
2727
})
2828

2929
// Controller: resendCtrl is used to resend an activation link to the user's e-mail
30-
.controller('resendCtrl', function(User) {
30+
.controller('resendCtrl', function(User, $scope) {
3131

3232
app = this;
3333

3434
// Custom function that check's the user's credentials against the database
35-
app.checkCredentials = function(loginData) {
36-
app.disabled = true; // Disable the form when user submits to prevent multiple requests to server
37-
app.errorMsg = false; // Clear errorMsg each time user submits
35+
app.checkCredentials = function(loginData, valid) {
36+
if (valid) {
37+
app.disabled = true; // Disable the form when user submits to prevent multiple requests to server
38+
app.errorMsg = false; // Clear errorMsg each time user submits
39+
40+
// Runs custom function that check's the user's credentials against the database
41+
User.checkCredentials(app.loginData).then(function(data) {
42+
// Check if credentials match
43+
if (data.data.success) {
44+
// Custom function that sends activation link
45+
User.resendLink(app.loginData).then(function(data) {
46+
// Check if sending of link is successful
47+
if (data.data.success) {
48+
$scope.alert = 'alert alert-success'; // Set error message ng-class
49+
app.successMsg = data.data.message; // If successful, grab message from JSON object
50+
} else {
51+
$scope.alert = 'alert alert-danger'; // Set error message ng-class
52+
app.errorMsg = data.data.message; // If not successful, grab message from JSON object
53+
}
54+
});
55+
} else {
56+
app.disabled = false; // If error occurs, remove disable lock from form
57+
$scope.alert = 'alert alert-danger'; // Set error message ng-class
58+
app.errorMsg = data.data.message; // If credentials do not match, display error from JSON object
59+
}
60+
});
61+
} else {
62+
$scope.alert = 'alert alert-danger'; // Set error message ng-class
63+
app.errorMsg = 'Please ensure form is filled out properly'; // Set form error message
64+
}
3865

39-
// Runs custom function that check's the user's credentials against the database
40-
User.checkCredentials(app.loginData).then(function(data) {
41-
// Check if credentials match
42-
if (data.data.success) {
43-
// Custom function that sends activation link
44-
User.resendLink(app.loginData).then(function(data) {
45-
// Check if sending of link is successful
46-
if (data.data.success) {
47-
app.successMsg = data.data.message; // If successful, grab message from JSON object
48-
} else {
49-
app.errorMsg = data.data.message; // If not successful, grab message from JSON object
50-
}
51-
});
52-
} else {
53-
app.disabled = false; // If error occurs, remove disable lock from form
54-
app.errorMsg = data.data.message; // If credentials do not match, display error from JSON object
55-
}
56-
});
5766
};
5867
})
5968

public/app/views/pages/users/activation/activate.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
<!-- Header -->
2-
<div class="page-header">
3-
<h1>Account Activation</h1>
1+
<!-- Heading -->
2+
<div class="row text-center">
3+
<div class="container">
4+
<h2 class="section-heading">Account activation</h2>
5+
<h3 class="section-subheading text-muted">This page allows you to activate your account.</h3>
6+
</div>
47
</div>
5-
<!-- Header -->
8+
<!-- Heading -->
69

710
<br>
811

@@ -18,4 +21,4 @@ <h1>Account Activation</h1>
1821
<div class="row show-hide-message" ng-show="email.errorMsg">
1922
<div class="alert alert-danger">{{ email.errorMsg }}</div>
2023
</div>
21-
<!-- Custom Error Message -->
24+
<!-- Custom Error Message -->
Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,64 @@
1-
<!-- Header -->
2-
<div class="page-header">
3-
<h1>Resend Activation Link</h1>
1+
<!-- Heading -->
2+
<div class="row text-center">
3+
<div class="container">
4+
<h2 class="section-heading">Resend Activation Link</h2>
5+
<h3 class="section-subheading text-muted">Please enter your username and password to request a new activation link.</h3>
6+
</div>
47
</div>
5-
<!-- Header -->
8+
<!-- Heading -->
69

7-
<!-- Start Resend Form -->
8-
<form ng-submit="resend.checkCredentials(loginData);">
9-
<!-- Username Input -->
10-
<label>Username:</label>
11-
<input ng-disabled="resend.disabled" class="form-control" type="text" name="username" placeholder="please enter username" ng-model="resend.loginData.username">
12-
<br>
13-
<!-- Password Input -->
14-
<label>Password:</label>
15-
<input ng-disabled="resend.disabled" class="form-control" type="password" name="password" placeholder="please enter password" ng-model="resend.loginData.password">
16-
<br>
17-
<!-- Submit Button-->
18-
<button ng-disabled="resend.disabled" class="btn btn-primary" type="submit">Submit</button>
19-
</form>
20-
<!-- End Resend Form -->
10+
<!-- Main Section -->
11+
<section id="contact">
12+
<!-- Start of Container -->
13+
<div class="container">
14+
<div class="row">
15+
<div class="col-lg-12">
16+
<form ng-submit="resend.checkCredentials(loginData, resetForm.$valid);" name="resetForm" id="contactForm" novalidate>
17+
<div class="row">
18+
<div class="col-md-6">
19+
<div class="form-group">
20+
<div ng-class="{ 'has-success':(resetForm.username.$valid && !resetForm.username.$pristine), 'has-error':(!resetForm.username.$valid && !resetForm.username.$pristine) || (!resetForm.username.$valid && resetForm.$submitted) }">
21+
<!-- Username Input -->
22+
<label>Username:</label>
23+
<input ng-disabled="reset.disabled" class="form-control" type="text" name="username" placeholder="Username *" ng-model="resend.loginData.username" required>
24+
<!-- Username Validation -->
25+
<p class="help-block" ng-show="(!resetForm.username.$pristine && resetForm.username.$error.required) || (resetForm.$submitted && resetForm.username.$error.required)">This field is required</p>
26+
</div>
27+
<br>
28+
<div ng-class="{ 'has-success':(resetForm.password.$valid && !resetForm.password.$pristine), 'has-error':(!resetForm.password.$valid && !resetForm.password.$pristine) || (!resetForm.password.$valid && resetForm.$submitted) }">
29+
<!-- Password Input -->
30+
<label>Password:</label>
31+
<input ng-disabled="reset.disabled" class="form-control" type="password" name="password" placeholder="Password *" ng-model="resend.loginData.password" required>
32+
<!-- Password Validation -->
33+
<p class="help-block" ng-show="(!resetForm.password.$pristine && resetForm.password.$error.required) || (resetForm.$submitted && resetForm.password.$error.required)">This field is required</p>
34+
</div>
35+
</div>
36+
<br>
37+
<!-- Submit Button -->
38+
<button ng-disabled="resend.disabled" class="btn btn-xl" type="submit">Resend Activation Link</button>
39+
<!-- Submit Button -->
40+
</div>
41+
</div>
42+
</form>
43+
</div>
44+
</div>
2145

22-
<br>
46+
<br>
2347

24-
<!-- Loading Icon -->
25-
<div class="jumbotron text-center" ng-show="resend.loading">
26-
<span class="glyphicon glyphicon-repeat spinner"></span>
27-
<p>Loading....</p>
28-
</div>
29-
<!-- Loading Icon -->
30-
31-
<br>
48+
<!-- Loading Icon (Bootstrap) -->
49+
<div class="jumbotron text-center" ng-show="resend.loading">
50+
<span class="glyphicon glyphicon-repeat spinner"></span>
51+
<p>Loading....</p>
52+
</div>
53+
<!-- Loading Icon (Bootstrap) -->
3254

33-
<!-- Custom Success Message -->
34-
<div class="row show-hide-message" ng-show="resend.successMsg">
35-
<div class="alert alert-success">{{ resend.successMsg }}</div>
36-
</div>
37-
<!-- Custom Success Message -->
55+
<!-- Custom Messages -->
56+
<div class="row show-hide-message" ng-show="resend.successMsg || resend.errorMsg">
57+
<div ng-class="alert">{{ resend.successMsg || resend.errorMsg }}</div>
58+
</div>
59+
<!-- Custom Messages -->
3860

39-
<br>
40-
41-
<!-- Custom Error Message -->
42-
<div class="row show-hide-message" ng-show="resend.errorMsg">
43-
<div class="alert alert-danger">{{ resend.errorMsg }}</div>
44-
</div>
45-
<!-- Custom Error Message -->
61+
</div>
62+
<!-- End of Container -->
63+
</section>
64+
<!-- Main Section /-->

0 commit comments

Comments
 (0)