Adding New files

This commit is contained in:
Amos Haviv
2014-03-26 01:30:58 +02:00
parent 38bffbcdbb
commit 7ba7dcfd21
5 changed files with 115 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
'use strict';
angular.module('mean.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('/');
$scope.updateUserProfile = function() {
$scope.success = $scope.error = null;
var user = new Users($scope.user);
user.$update(function(response) {
$scope.success = true;
Authentication.user = response;
}, function(response) {
$scope.error = response.data.message;
});
};
$scope.changeUserPassword = function() {
$scope.success = $scope.error = null;
$http.post('/users/password', $scope.passwordDetails).success(function(response) {
// If successful show success message and clear form
$scope.success = true;
$scope.passwordDetails = null;
}).error(function(response) {
$scope.error = response.message;
});
};
}
]);

View File

@@ -0,0 +1,5 @@
@media (min-width: 992px) {
.nav-users {
position: fixed;
}
}

View File

@@ -0,0 +1,12 @@
'use strict';
//Users service used for users REST endpoint
angular.module('mean.users').factory('Users', ['$resource',
function($resource) {
return $resource('users', {}, {
update: {
method: 'PUT'
}
});
}
]);

View File

@@ -0,0 +1,30 @@
<section class="row" data-ng-controller="SettingsController">
<h3 class="col-md-12 text-center">Change your password</h3>
<div class="col-xs-offset-2 col-xs-8 col-md-offset-5 col-md-2">
<form data-ng-submit="changeUserPassword()" class="signin form-horizontal" autocomplete="off">
<fieldset>
<div class="form-group">
<label for="currentPassword">Current Password</label>
<input type="password" id="currentPassword" name="currentPassword" class="form-control" data-ng-model="passwordDetails.currentPassword" placeholder="Current Password">
</div>
<div class="form-group">
<label for="newPassword">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">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">Save Password</button>
</div>
<div data-ng-show="success" class="text-center text-success">
<strong>Password Changed Successfully</strong>
</div>
<div data-ng-show="error" class="text-center text-danger">
<strong>{{error}}</strong>
</div>
</fieldset>
</form>
</div>
</section>

View File

@@ -0,0 +1,34 @@
<section class="row" data-ng-controller="SettingsController">
<h3 class="col-md-12 text-center">Edit your profile</h3>
<div class="col-xs-offset-2 col-xs-8 col-md-offset-5 col-md-2">
<form data-ng-submit="updateUserProfile()" class="signin form-horizontal" autocomplete="off">
<fieldset>
<div class="form-group">
<label for="firstName">First Name</label>
<input type="text" id="firstName" name="firstName" class="form-control" data-ng-model="user.firstName" placeholder="First Name">
</div>
<div class="form-group">
<label for="lastName">Last Name</label>
<input type="text" id="lastName" name="lastName" class="form-control" data-ng-model="user.lastName" placeholder="Last Name">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" id="email" name="email" class="form-control" data-ng-model="user.email" placeholder="Email">
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" class="form-control" data-ng-model="user.username" placeholder="Username">
</div>
<div class="text-center form-group">
<button type="submit" class="btn btn-large btn-primary">Save Profile</button>
</div>
<div data-ng-show="success" class="text-center text-success">
<strong>Profile Saved Successfully</strong>
</div>
<div data-ng-show="error" class="text-center text-danger">
<strong>{{error}}</strong>
</div>
</fieldset>
</form>
</div>
</section>