Permalink
Browse files

basic user setup is finished.

  • Loading branch information...
1 parent c18312e commit 5228f6fcba71149eec8bb1bd0812a75edd8703bd @joshlong committed Dec 23, 2012
@@ -25,7 +25,7 @@
/**
* Root URL template for all modifications to a {@link User}
*/
- static public final String USER_COLLECTION_URL = "/api/users/";
+ static public final String USER_COLLECTION_URL = "/api/users";
static public final String USER_COLLECTION_ENTRY_URL = USER_COLLECTION_URL + "/{userId}";
private Logger log = Logger.getLogger(getClass());
@@ -53,11 +53,13 @@ public User updateUserById(@PathVariable("userId") Long userId,
return this.userService.updateUser(userId, username, password, fn, ln, existingUser.isImportedFromServiceProvider());
}
- // more convenient
- @RequestMapping(value = USER_COLLECTION_URL + "/photo", method = RequestMethod.POST)
+ @RequestMapping(value = USER_COLLECTION_URL, method = RequestMethod.POST)
@ResponseBody
- public Callable<Long> uploadBasedOnRequestParameter(@RequestParam("userId") long userId, @RequestParam("file") MultipartFile file) {
- return this.uploadBasedOnPathVariable(userId, file);
+ public User registerUser(@RequestParam("username") String username,
+ @RequestParam("password") String password,
+ @RequestParam("firstname") String fn,
+ @RequestParam("lastname") String ln) {
+ return this.userService.createOrGet(username, password, fn, ln, false);
}
// more correct
@@ -64,11 +64,12 @@
<http pattern="/api/crm/search**" create-session="never" xmlns="http://www.springframework.org/schema/security" security="none"/>
- <http pattern="/api/**" create-session="never" entry-point-ref="oauthAuthenticationEntryPoint"
- access-decision-manager-ref="accessDecisionManager" xmlns="http://www.springframework.org/schema/security">
+ <http pattern="/api/**" create-session="never" entry-point-ref="oauthAuthenticationEntryPoint" access-decision-manager-ref="accessDecisionManager" xmlns="http://www.springframework.org/schema/security">
<anonymous enabled="true"/>
<intercept-url pattern="/api/users/**/photo" method="GET" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<intercept-url pattern="/api/users/**/photo" method="POST" access="ROLE_USER,SCOPE_READ"/>
+ <!-- you should be allowed to create a new user without being logged in, obviously -->
+ <intercept-url pattern="/api/users" method="POST" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<intercept-url pattern="/api/**" access="ROLE_USER,SCOPE_READ"/>
<custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER"/>
<access-denied-handler ref="oauthAccessDeniedHandler"/>
@@ -5,7 +5,7 @@
<div ng-controller="SignUpController">
<tiles:insertTemplate template="/WEB-INF/layouts/components/box.jsp">
<tiles:putAttribute name="content">
- <form class="form-horizontal" ng-submit="saveProfileData()">
+ <form class="form-horizontal" >
<div class="panel">
<fieldset>
@@ -51,7 +51,8 @@
<div class="form-actions">
- <button type="submit" class="btn btn-primary" ng-model-instant> Create Profile</button>
+ <a ng-click="saveProfileData()" href="javascript:void(0);">Sign Up </a>
+ <%-- <button type="submit" ng-click="saveProfileData()" onclick="javascript:void(0);" class="btn btn-primary" ng-model-instant> Create Profile</button>--%>
or
<span>
<a ng-click="signinWithFacebook()" href="javascript:void(0);">Sign Up with
@@ -63,20 +63,33 @@ module.factory('ajaxUtils', function () {
var argFunc = argsProcessor || function (a) {
return a;
};
- var isPost = (_method || '').toLowerCase() == 'post'; // dont specify the '_method' attribute if the request's a POST. Redundant
- if (!isPost) d['_method'] = _method;
- ajaxFunction(argFunc({
+ var isPost = (_method || '').toLowerCase() == 'post';
+
+ if (!isPost) {
+ d['_method'] = _method;
+ }
+
+ var arg = {
type:'POST',
url:url,
- headers:(isPost ? {} : {'_method':_method}),
data:d,
cache:false,
dataType:dataType,
success:cb,
error:errorCallback
- })
- );
+ };
+
+ if (!isPost) {
+ arg['headers'] = {'_method':_method};
+ }
+ ajaxFunction(argFunc(arg));
+ };
+
+
+ var noopArgsProcessor = function (e) {
+ return e;
};
+ var oauthArgsProcessor = this.enrichRequestArguments;
return {
accessToken:function () {
@@ -93,11 +106,16 @@ module.factory('ajaxUtils', function () {
return a;
},
put:function (url, data, cb) {
- sendDataFunction($.ajax, function () {
- }, url, 'PUT', data, cb);
+ sendDataFunction($.ajax, noopArgsProcessor, url, 'PUT', data, cb);
+ },
+ post:function (url, data, cb) {
+ sendDataFunction($.ajax, noopArgsProcessor, url, 'POST', data, cb);
},
oauthPut:function (url, data, cb) {
- sendDataFunction($.oajax, this.enrichRequestArguments, url, 'PUT', data, cb);
+ sendDataFunction($.oajax, oauthArgsProcessor, url, 'PUT', data, cb);
+ },
+ oauthPost:function (url, data, cb) {
+ sendDataFunction($.oajax, oauthArgsProcessor, url, 'POST', data, cb);
},
oauthGet:function (url, data, cb) {
$.oajax(this.enrichRequestArguments({
@@ -127,18 +145,22 @@ module.factory('ajaxUtils', function () {
});
module.factory('userService', function (ajaxUtils) {
- var usersCollectionEntryUrl = '/api/users/';
+ var usersCollectionEntryUrl = '/api/users';
return {
buildBaseUserApiUrl:function (userId) {
- return ajaxUtils.url(usersCollectionEntryUrl + userId);
+ return ajaxUtils.url(usersCollectionEntryUrl + '/' + userId);
},
updateUserById:function (userId, username, pw, fn, ln, callback) {
- var updateUrl = this.buildBaseUserApiUrl(userId);
var user = {username:username, password:pw, firstname:fn, lastname:ln, id:userId };
- ajaxUtils.oauthPut(updateUrl, user, callback);
+ ajaxUtils.oauthPut(this.buildBaseUserApiUrl(userId), user, callback);
},
getUserById:function (userId, callback) {
ajaxUtils.oauthGet(ajaxUtils.url(usersCollectionEntryUrl + userId), {}, callback);
+ },
+ registerNewUser:function (username, pw, fn, ln, callback) {
+ var user = {username:username, password:pw, firstname:fn, lastname:ln };
+ var url = ajaxUtils.url(usersCollectionEntryUrl);
+ ajaxUtils.post(url, user, callback);
}
};
})
@@ -163,12 +185,6 @@ function ProfileController($rootScope, $scope, ajaxUtils, userService) {
console.log('using request URL ' + photoUrl + ', which should require OAuth credentials to work.');
- // todo do we even need to transmit this? it seems to work with just the HTTP Session Cookie
- //
- //
- //
- //console.log('the oauth header is ' + authHeaderForOauth + '.');
-
profilePhotoNode.filedrop({
dataType:'json',
maxfilesize:20, /* in MB */
@@ -349,13 +365,19 @@ function SignUpController($rootScope, $scope, ajaxUtils, userService) {
$scope.loadUser = function () {
- console.log('loading user is not an option');
}; // noop
- $scope.saveProfileData = function(){
- console.log('registering a new user') ;
+ $scope.saveProfileData = function () {
+ userService.registerNewUser($scope.user.username, $scope.user.password, $scope.user.firstName, $scope.user.lastName, function (u) {
+ console.log('registering the new user.');
+ });
+
+
}; // posts to a different endpoint for the user
ProfileController($rootScope, $scope, ajaxUtils, userService);
SignInController($scope, ajaxUtils);
+
+ $scope.user = { username:'joshlong', password:'password', firstName:'Joshua', lastName:'Long'};
+
}

0 comments on commit 5228f6f

Please sign in to comment.