forked from Archives/Athou_commafeed
profile page
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.commafeed.frontend.model;
|
||||
|
||||
public class ProfileModificationRequest {
|
||||
|
||||
private String email;
|
||||
private String password;
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ public class UserModel implements Serializable {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String email;
|
||||
private String password;
|
||||
private boolean enabled;
|
||||
private boolean admin;
|
||||
@@ -51,4 +52,12 @@ public class UserModel implements Serializable {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package com.commafeed.frontend.rest.resources;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.backend.model.UserRole;
|
||||
import com.commafeed.backend.model.UserRole.Role;
|
||||
import com.commafeed.frontend.model.ProfileModificationRequest;
|
||||
import com.commafeed.frontend.model.UserModel;
|
||||
|
||||
@Path("session")
|
||||
@@ -18,6 +23,7 @@ public class SessionREST extends AbstractREST {
|
||||
UserModel userModel = new UserModel();
|
||||
userModel.setId(user.getId());
|
||||
userModel.setName(user.getName());
|
||||
userModel.setEmail(user.getEmail());
|
||||
userModel.setEnabled(!user.isDisabled());
|
||||
for (UserRole role : userRoleDAO.findAll(user)) {
|
||||
if (role.getRole() == Role.ADMIN) {
|
||||
@@ -26,4 +32,18 @@ public class SessionREST extends AbstractREST {
|
||||
}
|
||||
return userModel;
|
||||
}
|
||||
|
||||
@Path("save")
|
||||
@POST
|
||||
public Response save(ProfileModificationRequest request) {
|
||||
User user = getUser();
|
||||
user.setEmail(request.getEmail());
|
||||
if (StringUtils.isNotBlank(request.getPassword())) {
|
||||
byte[] password = encryptionService.getEncryptedPassword(
|
||||
request.getPassword(), user.getSalt());
|
||||
user.setPassword(password);
|
||||
}
|
||||
userDAO.update(user);
|
||||
return Response.ok().build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,6 +261,9 @@ module.controller('ToolbarCtrl',
|
||||
$scope.toSettings = function() {
|
||||
$location.path('settings');
|
||||
};
|
||||
$scope.toProfile = function() {
|
||||
$location.path('profile');
|
||||
};
|
||||
});
|
||||
|
||||
module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
|
||||
@@ -556,6 +559,27 @@ module.controller('SettingsCtrl', function($scope, $location, SettingsService) {
|
||||
};
|
||||
});
|
||||
|
||||
module.controller('ProfileCtrl', function($scope, $location, SessionService) {
|
||||
$scope.user = SessionService.get();
|
||||
|
||||
$scope.cancel = function() {
|
||||
$location.path('/');
|
||||
};
|
||||
$scope.save = function() {
|
||||
if (!$scope.profileForm.$valid) {
|
||||
return;
|
||||
}
|
||||
var o = {
|
||||
email : $scope.user.email
|
||||
};
|
||||
if ($scope.user.password == $scope.password_c) {
|
||||
o.password = $scope.user.password;
|
||||
}
|
||||
SessionService.save(o);
|
||||
$location.path('/');
|
||||
};
|
||||
});
|
||||
|
||||
module.controller('ManageSettingsCtrl', function($scope, $location, $state,
|
||||
AdminSettingsService) {
|
||||
|
||||
|
||||
@@ -50,6 +50,12 @@ app.config(function($routeProvider, $stateProvider, $urlRouterProvider) {
|
||||
templateUrl : 'templates/settings.html',
|
||||
controller : 'SettingsCtrl'
|
||||
});
|
||||
|
||||
$stateProvider.state('profile', {
|
||||
url : '/profile',
|
||||
templateUrl : 'templates/profile.html',
|
||||
controller : 'ProfileCtrl'
|
||||
});
|
||||
|
||||
$urlRouterProvider.when('/', '/feeds/view/category/all');
|
||||
$urlRouterProvider.when('/admin', '/admin/settings');
|
||||
|
||||
@@ -1,7 +1,21 @@
|
||||
var module = angular.module('commafeed.services', [ 'ngResource' ]);
|
||||
|
||||
module.factory('SessionService', function($resource) {
|
||||
return $resource('rest/session/get');
|
||||
var actions = {
|
||||
get : {
|
||||
method : 'GET',
|
||||
params : {
|
||||
_method : 'get'
|
||||
}
|
||||
},
|
||||
save : {
|
||||
method : 'POST',
|
||||
params : {
|
||||
_method : 'save'
|
||||
}
|
||||
}
|
||||
};
|
||||
return $resource('rest/session/:_method', {}, actions);
|
||||
});
|
||||
|
||||
module.factory('SubscriptionService', function($resource, $http) {
|
||||
|
||||
@@ -17,9 +17,10 @@
|
||||
<a class="btn dropdown-toggle" data-toggle="dropdown" href="settings"><i class="icon-cog"></i> {{session.name}} <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu pull-right">
|
||||
<li><a ng-click="toSettings()"><i class="icon-wrench"></i> Settings</a></li>
|
||||
<li><a ng-click="toProfile()"><i class="icon-user"></i> Profile</a></li>
|
||||
<li ng-show="session.admin"><a ng-click="toAdmin()"><i class="icon-edit"></i> Admin</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="logout"><i class="icon-user"></i> Logout</a></li>
|
||||
<li><a href="logout"><i class="icon-off"></i> Logout</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</span>
|
||||
|
||||
36
src/main/webapp/templates/profile.html
Normal file
36
src/main/webapp/templates/profile.html
Normal file
@@ -0,0 +1,36 @@
|
||||
<div class="container profile">
|
||||
<div class="page-header">
|
||||
<h1>Profile</h1>
|
||||
</div>
|
||||
{{user}}
|
||||
{{profileForm.$valid}}
|
||||
<form name="profileForm" ng-submit="save()" class="form-horizontal">
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="email">E-mail</label>
|
||||
<div class="controls">
|
||||
<input type="email" id="email" ng-model="user.email" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="password">Change password</label>
|
||||
<div class="controls">
|
||||
<input type="password" name="password" id="password" ng-model="user.password"
|
||||
ng-minlength="6" />
|
||||
<span class="help-inline" ng-show="profileForm.password.$error.minlength">Minimum 6 characters</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="password">Confirm password</label>
|
||||
<div class="controls">
|
||||
<input type="password" name="password_c" id="password_c" ng-model="password_c"
|
||||
ui-validate="'$value==user.password'" ui-validate-watch="'user.password'">
|
||||
<span class="help-inline" ng-show="profileForm.password_c.$error.validator">Passwords do not match</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
<button type="button" class="btn" ng-click="cancel()">Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
Reference in New Issue
Block a user