Skip to content

Commit

Permalink
#22 #16 #15 User's newsletter subscription
Browse files Browse the repository at this point in the history
- Possibility to subscribe at sign up
- Change subscription at settings page
  • Loading branch information
simison committed Oct 13, 2014
1 parent 918a6ca commit b356d1d
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 32 deletions.
4 changes: 4 additions & 0 deletions app/models/user.server.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ var UserSchema = new Schema({
}],
default: ['gravatar']
},
newsletter: {
type: Boolean,
default: false
},
/* For reset password */
resetPasswordToken: {
type: String
Expand Down
26 changes: 19 additions & 7 deletions public/modules/users/controllers/settings.client.controller.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
'use strict';

angular.module('users').controller('SettingsController', ['$scope', '$http', '$location', 'Users',
function($scope, $http, $location, Users) {
angular.module('users').controller('SettingsController', ['$scope', '$http', '$location', 'Users', 'Authentication',
function($scope, $http, $location, Users, Authentication) {

$scope.user = Authentication.user;

// If user is not signed in then redirect back home
if (!$scope.user) $location.path('/');

// Change user email subscriptions
$scope.updateUserSubscriptions = function() {
$scope.subscriptionsSuccess = $scope.subscriptionsError = null;
var user = new Users($scope.user);

user.$update(function(response) {
$scope.subscriptionsSuccess = 'Subscriptions updated.';
Authentication.user = response;
}, function(response) {
$scope.subscriptionsError = response.data.message;
});
};

// Change user password
$scope.changeUserPassword = function() {
$scope.success = $scope.error = null;
$scope.passwordSuccess = $scope.passwordError = null;

$http.post('/users/password', $scope.passwordDetails).success(function(response) {
// If successful show success message and clear form
$scope.success = true;
$scope.passwordSuccess = true;
$scope.passwordDetails = null;
}).error(function(response) {
$scope.error = response.message;
$scope.passwordError = response.message;
});
};



// Remove user permanently
$scope.removalConfirm = false;
$scope.removeUser = function() {
Expand Down
14 changes: 11 additions & 3 deletions public/modules/users/views/authentication/signup.client.view.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ <h3 class="col-md-12 text-center">Or with your email</h3>
<input type="email" id="email" name="email" class="form-control input-lg" data-ng-model="credentials.email" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-4 control-label">Password</label>
<div class="form-group">
<label for="password" class="col-sm-4 control-label">Password</label>
<div class="col-sm-8">
<input type="password" id="password" name="password" class="form-control input-lg" data-ng-model="credentials.password" placeholder="Password" popover="At least 8 characters long." popover-trigger="focus" popover-placement="right" popover-append-to-body="true">
<input type="password" id="password" name="password" class="form-control input-lg" data-ng-model="credentials.password" placeholder="Password" popover="At least 8 characters long." popover-trigger="focus" popover-placement="right" popover-append-to-body="true">
</div>
</div>
<div class="checkbox">
<div class="col-sm-offset-4 col-sm-8">
<label for="newsletter">
<input type="checkbox" id="newsletter" name="newsletter" data-ng-model="credentials.newsletter">
Subscribe to community news
</label>
</div>
</div>
<div class="text-center form-group">
Expand Down
76 changes: 54 additions & 22 deletions public/modules/users/views/profile/edit-settings.client.view.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,65 @@ <h2>Account Settings</h2>
</div>
</div>

<!-- Profile settings -->
<div class="row text-center">

<div class="col-xs-offset-2 col-xs-8 col-md-offset-4 col-md-4">
<h3>Email subscriptions</h3>
<form data-ng-submit="updateUserSubscriptions()" class="form-horizontal" autocomplete="off">
<fieldset>
<div class="form-group">
<div class="checkbox">
<label for="newsletter">
<input type="checkbox" id="newsletter" name="newsletter" data-ng-model="user.newsletter">
Subscribe to community news
</label>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-large btn-primary">Update email subscriptions</button>
</div>
<div data-ng-show="subscriptionsError" class="text-center text-danger">
<strong>{{subscriptionsError}}</strong>
</div>
<div data-ng-show="subscriptionsSuccess" class="text-center text-success">
<strong>{{subscriptionsSuccess}}</strong>
</div>
</fieldset>
</form>
<br><br>
</div>

</div>
<!-- /Profile settings -->

<!-- Password -->
<div class="row text-center" data-ng-show="user.provider === 'local'" data-ng-controller="PasswordController">

<h3 class="col-xs-12">Change your password</h3>
<div class="col-xs-offset-2 col-xs-8 col-md-offset-5 col-md-2">
<form data-ng-submit="resetUserPassword()" class="signin form-horizontal" autocomplete="off">
<fieldset>
<div class="form-group">
<label for="newPassword" class="sr-only">New Password</label>
<input type="password" id="newPassword" name="newPassword" class="form-control" data-ng-model="passwordDetails.newPassword" placeholder="New Password">
</div>
<div class="form-group">
<label for="verifyPassword" class="sr-only">Verify Password</label>
<input type="password" id="verifyPassword" name="verifyPassword" class="form-control" data-ng-model="passwordDetails.verifyPassword" placeholder="Verify Password">
</div>
<div class="text-center form-group">
<button type="submit" class="btn btn-large btn-primary">Update Password</button>
</div>
<div data-ng-show="error" class="text-center text-danger">
<strong>{{error}}</strong>
</div>
<div data-ng-show="success" class="text-center text-success">
<strong>{{success}}</strong>
</div>
</fieldset>
</form>
<br><br>
<form data-ng-submit="resetUserPassword()" class="form-horizontal" autocomplete="off">
<fieldset>
<div class="form-group">
<label for="newPassword" class="sr-only">New Password</label>
<input type="password" id="newPassword" name="newPassword" class="form-control" data-ng-model="passwordDetails.newPassword" placeholder="New Password">
</div>
<div class="form-group">
<label for="verifyPassword" class="sr-only">Verify Password</label>
<input type="password" id="verifyPassword" name="verifyPassword" class="form-control" data-ng-model="passwordDetails.verifyPassword" placeholder="Verify Password">
</div>
<div class="text-center form-group">
<button type="submit" class="btn btn-large btn-primary">Update Password</button>
</div>
<div data-ng-show="passwordError" class="text-center text-danger">
<strong>{{passwordError}}</strong>
</div>
<div data-ng-show="passwordSuccess" class="text-center text-success">
<strong>{{passwordSuccess}}</strong>
</div>
</fieldset>
</form>
<br><br>
</div>

</div>
Expand Down

0 comments on commit b356d1d

Please sign in to comment.