Browse Source

basic user update functionality

v0.1.8
Georg Hopp 12 years ago
parent
commit
06c15c2b3c
  1. 1
      Makefile.am
  2. 1
      assets/html/_menu.html
  3. 27
      assets/html/_myaccount.html
  4. 21
      assets/html/layout.html
  5. 12
      assets/js/application.js
  6. 13
      assets/js/init.js
  7. 28
      assets/js/menu.js
  8. 11
      assets/style/common.css
  9. 10
      assets/style/taskrambler.css
  10. 1
      include/application/application.h
  11. 7
      src/application/Makefile.am
  12. 63
      src/application/controller/_get_credential_from_args.c
  13. 54
      src/application/controller/_get_user_from_args.c
  14. 42
      src/application/controller/_process_user_create_args.c
  15. 60
      src/application/controller/_update_user_from_args.c
  16. 56
      src/application/controller/user/update.c
  17. 67
      src/application/update_user.c
  18. 4
      src/http/worker/process.c
  19. 1
      src/router/route.c

1
Makefile.am

@ -24,6 +24,7 @@ nobase_trdata_DATA = assets/html/example.html \
assets/html/layout.html \ assets/html/layout.html \
assets/html/_documentation.html \ assets/html/_documentation.html \
assets/html/_download.html \ assets/html/_download.html \
assets/html/_myaccount.html \
assets/image/waldschrat.jpg \ assets/image/waldschrat.jpg \
assets/image/fav128.png \ assets/image/fav128.png \
assets/image/fav16.png \ assets/image/fav16.png \

1
assets/html/_menu.html

@ -5,6 +5,7 @@
<li><a href="/download.html">download</a></li> <li><a href="/download.html">download</a></li>
<li class="signup"><span>signup</span></li> <li class="signup"><span>signup</span></li>
<li class="login"><span>login</span></li> <li class="login"><span>login</span></li>
<li class="my_account hide"><span>my account</span></li>
<li class="logout hide"><span>logout</span></li> <li class="logout hide"><span>logout</span></li>
<li class="menuedge"></li> <li class="menuedge"></li>
<div></div> <div></div>

27
assets/html/_myaccount.html

@ -0,0 +1,27 @@
<h4>My account</h4><div id="myaccount-close" class="link right">(close)</div>
<hr />
<form>
<div class="firstname">
<label for="firstname">firstname</label>
<input type="text" name="firstname" /><br />
</div>
<div class="surname">
<label for="surname">surname</label>
<input type="text" name="surname" /><br />
</div>
<div class="email">
<label for="mail">email</label>
<input type="text" name="email" /><br />
</div>
<div style="height: 10px;" />
<div>
<hr />
<hr />
</div>
<div style="height: 10px;" />
<div>
<input type="submit" value="update account" />
</div>
</form>
<!-- vim: set ts=4 sw=4: -->

21
assets/html/layout.html

@ -63,6 +63,27 @@
</table> </table>
</div> </div>
<div id="myaccount-container" class="ui-widget-content border hide">
<table>
<tr>
<td class="tl"></td>
<td class="t"></td>
<td class="tr"></td>
</tr>
<td class="l"></td>
<td id ="myaccount">
</td>
<td class="r"></td>
<tr>
</tr>
<tr>
<td class="bl"></td>
<td class="b"></td>
<td class="br"></td>
</tr>
</table>
</div>
<div id="page"> <div id="page">
<div id="statusline"> <div id="statusline">
</div> </div>

12
assets/js/application.js

@ -25,20 +25,24 @@ Application.prototype.logout = function() {
} }
Application.prototype.login = function(ev) { Application.prototype.login = function(ev) {
this._sendForm("#login", "/authenticate/", ev);
this._sendForm("#login", "/authenticate/", "POST", ev);
} }
Application.prototype.signup = function(ev) { Application.prototype.signup = function(ev) {
this._sendForm("#signup", "/signup/", ev);
this._sendForm("#signup", "/signup/", "POST", ev);
}
Application.prototype.userupdate = function(ev) {
this._sendForm("#myaccount", "/user/", "PUT", ev);
} }
Application.prototype._sendForm = function(id, url, ev) {
Application.prototype._sendForm = function(id, url, method, ev) {
ev.preventDefault(); ev.preventDefault();
$.ajax({ $.ajax({
dataType : "json", dataType : "json",
url : url, url : url,
type : "POST",
type : method,
data : $(id + " form").serialize(), data : $(id + " form").serialize(),
success : $.proxy(this._formSuccess, this, id), success : $.proxy(this._formSuccess, this, id),
complete : $.proxy(this.session.update, this.session) complete : $.proxy(this.session.update, this.session)

13
assets/js/init.js

@ -55,6 +55,19 @@ $(document).ready(function() {
$("#signup form").submit($.proxy(application.signup, application)); $("#signup form").submit($.proxy(application.signup, application));
}); });
$("#myaccount").load("/_myaccount.html", function (){
$(function() {
$("#myaccount-container").draggable();
});
$("#myaccount-close").click(function (e) {
$("#myaccount-container").addClass("hide");
});
$("#myaccount form").submit(
$.proxy(application.userupdate, application));
});
$("#footer").load("/_footer.html", function (){ $("#footer").load("/_footer.html", function (){
$.getJSON( $.getJSON(
"/loc/", "/loc/",

28
assets/js/menu.js

@ -1,10 +1,11 @@
function Menu(menuSelector, application, user)
function Menu(menuSelector, application)
{ {
this.application = application;
this.application = application;
this.signupSelector = menuSelector + " ul li.signup";
this.loginSelector = menuSelector + " ul li.login";
this.logoutSelector = menuSelector + " ul li.logout";
this.signupSelector = menuSelector + " ul li.signup";
this.loginSelector = menuSelector + " ul li.login";
this.logoutSelector = menuSelector + " ul li.logout";
this.myaccountSelector = menuSelector + " ul li.my_account";
this.menuElement = $(menuSelector); this.menuElement = $(menuSelector);
} }
@ -14,14 +15,20 @@ Menu.prototype.init = function() {
} }
Menu.prototype.update = function() { Menu.prototype.update = function() {
$("#myaccount div.firstname input").val(this.application.user.firstname);
$("#myaccount div.surname input").val(this.application.user.surname);
$("#myaccount div.email input").val(this.application.user.email);
if (this.application.user.isEmpty()) { if (this.application.user.isEmpty()) {
$(this.signupSelector).removeClass("hide"); $(this.signupSelector).removeClass("hide");
$(this.loginSelector).removeClass("hide"); $(this.loginSelector).removeClass("hide");
$(this.logoutSelector).addClass("hide"); $(this.logoutSelector).addClass("hide");
$(this.myaccountSelector).addClass("hide");
} else { } else {
$(this.signupSelector).addClass("hide"); $(this.signupSelector).addClass("hide");
$(this.loginSelector).addClass("hide"); $(this.loginSelector).addClass("hide");
$(this.logoutSelector).removeClass("hide"); $(this.logoutSelector).removeClass("hide");
$(this.myaccountSelector).removeClass("hide");
} }
} }
@ -51,6 +58,17 @@ Menu.prototype._menuActions = function() {
$(this.logoutSelector) $(this.logoutSelector)
.click($.proxy(this.application.logout, this.application)); .click($.proxy(this.application.logout, this.application));
$(this.myaccountSelector).click(function(ev) {
if ($("#myaccount-container").hasClass("hide")) {
$("#myaccount-container").css("top", ev.pageY + 20);
$("#myaccount-container").css("left", ev.pageX - 100);
$("#myaccount-container").removeClass("hide");
} else {
$("#myaccount-container").addClass("hide");
}
});
} }
// vim: set ts=4 sw=4: // vim: set ts=4 sw=4:

11
assets/style/common.css

@ -12,6 +12,17 @@ div#randval {
z-index: 20; z-index: 20;
} }
div#myaccount-container {
-moz-box-shadow: 0 4px 8px rgba(0,0,0,0.5);
-webkit-box-shadow: 0 4px 8px rgba(0,0,0,0.5);
box-shadow: 0 4px 8px rgba(0,0,0,0.5);
padding: 0px;
position: fixed;
background-image: url(/image/rambler-bg.jpg);
border-radius: 5px;
z-index: 20;
}
div#signup-container { div#signup-container {
-moz-box-shadow: 0 4px 8px rgba(0,0,0,0.5); -moz-box-shadow: 0 4px 8px rgba(0,0,0,0.5);
-webkit-box-shadow: 0 4px 8px rgba(0,0,0,0.5); -webkit-box-shadow: 0 4px 8px rgba(0,0,0,0.5);

10
assets/style/taskrambler.css

@ -261,7 +261,7 @@ div.border .br {
vertical-align: center; vertical-align: center;
} }
#login label, #signup label {
#login label, #signup label, #myaccount label {
font-family: old_newspaper; font-family: old_newspaper;
font-size: 15px; font-size: 15px;
font-weight: bold; font-weight: bold;
@ -269,19 +269,19 @@ div.border .br {
display: table-cell; display: table-cell;
} }
#login input, #signup input {
#login input, #signup input, #myaccount input {
display: table-cell; display: table-cell;
} }
#login div, #signup div {
#login div, #signup div, #myaccount div {
display: table-row; display: table-row;
} }
#login form, #signup form {
#login form, #signup form, #myaccount form {
display: table; display: table;
} }
#login form hr, #signup form hr {
#login form hr, #signup form hr, #myaccount form hr {
display: table-cell; display: table-cell;
} }

1
include/application/application.h

@ -66,6 +66,7 @@ CLASS(Application) {
int applicationLogin(Application, Credential, Session); int applicationLogin(Application, Credential, Session);
void applicationLogout(Application, Session); void applicationLogout(Application, Session);
Uuid applicationCreateUser(Application, Credential, User); Uuid applicationCreateUser(Application, Credential, User);
Uuid applicationUpdateUser(Application, User);
User applicationGetUser(Application, Uuid); User applicationGetUser(Application, Uuid);
int applicationUpdatePassword(Application, Credential, User); int applicationUpdatePassword(Application, Credential, User);

7
src/application/Makefile.am

@ -6,6 +6,7 @@ APPLICATION = application.c \
logout.c \ logout.c \
get_user.c \ get_user.c \
create_user.c \ create_user.c \
update_user.c \
update_password.c \ update_password.c \
session_start.c \ session_start.c \
session_stop.c \ session_stop.c \
@ -21,12 +22,16 @@ CONTROLLER = controller/authenticate/create.c \
controller/randval/read.c \ controller/randval/read.c \
controller/sessinfo/read.c \ controller/sessinfo/read.c \
controller/user/create.c \ controller/user/create.c \
controller/user/update.c \
controller/user/read.c \ controller/user/read.c \
controller/signup/create.c \ controller/signup/create.c \
controller/version/read.c \ controller/version/read.c \
controller/loc/read.c \ controller/loc/read.c \
controller/_validate_password_repeat.c \ controller/_validate_password_repeat.c \
controller/_process_user_create_args.c
controller/_process_user_create_args.c \
controller/_get_user_from_args.c \
controller/_update_user_from_args.c \
controller/_get_credential_from_args.c
AM_CFLAGS += -I../../include/ AM_CFLAGS += -I../../include/

63
src/application/controller/_get_credential_from_args.c

@ -0,0 +1,63 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include "hash.h"
#include "auth/credential.h"
#include "utils/memory.h"
#include "commons.h"
int _controllerValidatePasswordRepeat(char *, size_t, char *, size_t);
Credential
_controllerGetCredentialFromArgs(Hash args)
{
HashValue email = hashGet(args, CSTRA("email"));
HashValue password = hashGet(args, CSTRA("password"));
HashValue pwrepeat = hashGet(args, CSTRA("pwrepeat"));
if (
NULL == email ||
NULL == password ||
NULL == pwrepeat)
{
return FALSE;
}
if (! _controllerValidatePasswordRepeat(
password->value,
password->nvalue,
pwrepeat->value,
pwrepeat->nvalue))
{
return FALSE;
}
return new(Credential,
CRED_PASSWORD,
(char *)(email->value), email->nvalue,
(char *)(password->value), password->nvalue);
}
// vim: set ts=4 sw=4:

54
src/application/controller/_get_user_from_args.c

@ -0,0 +1,54 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include "hash.h"
#include "user.h"
#include "utils/memory.h"
#include "commons.h"
User
_controllerGetUserFromArgs(Hash args)
{
HashValue email = hashGet(args, CSTRA("email"));
HashValue firstname = hashGet(args, CSTRA("firstname"));
HashValue surname = hashGet(args, CSTRA("surname"));
if (
NULL == email ||
NULL == firstname ||
NULL == surname)
{
return FALSE;
}
return new(User,
(char *)(email->value), email->nvalue,
(char *)(email->value), email->nvalue,
(char *)(firstname->value), firstname->nvalue,
(char *)(surname->value), surname->nvalue);
}
// vim: set ts=4 sw=4:

42
src/application/controller/_process_user_create_args.c

@ -29,48 +29,22 @@
#include "utils/memory.h" #include "utils/memory.h"
#include "commons.h" #include "commons.h"
int _controllerValidatePasswordRepeat(char *, size_t, char *, size_t);
User _controllerGetUserFromArgs(Hash args);
Credential _controllerGetCredentialFromArgs(Hash args);
int int
_controllerProcessUserCreateArgs(Hash args, User * user, Credential * cred) _controllerProcessUserCreateArgs(Hash args, User * user, Credential * cred)
{ {
HashValue email = hashGet(args, CSTRA("email"));
HashValue password = hashGet(args, CSTRA("password"));
HashValue pwrepeat = hashGet(args, CSTRA("pwrepeat"));
HashValue firstname = hashGet(args, CSTRA("firstname"));
HashValue surname = hashGet(args, CSTRA("surname"));
if (
NULL == email ||
NULL == password ||
NULL == pwrepeat ||
NULL == firstname ||
NULL == surname)
{
return FALSE;
}
*user = _controllerGetUserFromArgs(args);
*cred = _controllerGetCredentialFromArgs(args);
if (NULL == *user || NULL == *cred) {
delete(*user);
delete(*cred);
if (! _controllerValidatePasswordRepeat(
password->value,
password->nvalue,
pwrepeat->value,
pwrepeat->nvalue))
{
return FALSE; return FALSE;
} }
*cred = new(Credential,
CRED_PASSWORD,
(char *)(email->value), email->nvalue,
(char *)(password->value), password->nvalue);
*user = new(User,
(char *)(email->value), email->nvalue,
(char *)(email->value), email->nvalue,
(char *)(firstname->value), firstname->nvalue,
(char *)(surname->value), surname->nvalue);
return TRUE; return TRUE;
} }

60
src/application/controller/_update_user_from_args.c

@ -0,0 +1,60 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include "hash.h"
#include "user.h"
#include "utils/memory.h"
#include "commons.h"
int
_controllerUpdateUserFromArgs(Hash args, User * user)
{
HashValue email = hashGet(args, CSTRA("email"));
HashValue firstname = hashGet(args, CSTRA("firstname"));
HashValue surname = hashGet(args, CSTRA("surname"));
User new_user;
if (
NULL == email ||
NULL == firstname ||
NULL == surname)
{
return FALSE;
}
new_user = new(User,
(char *)((*user)->username), *(*user)->nusername,
(char *)(email->value), email->nvalue,
(char *)(firstname->value), firstname->nvalue,
(char *)(surname->value), surname->nvalue);
delete(*user);
*user = new_user;
return TRUE;
}
// vim: set ts=4 sw=4:

56
src/application/controller/user/update.c

@ -0,0 +1,56 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include "application/application.h"
#include "session.h"
#include "hash.h"
#include "user.h"
#include "utils/memory.h"
#include "commons.h"
char * controllerCurrentuserRead(Application, Session, Hash);
int _controllerUpdateUserFromArgs(Hash, User *);
char *
controllerUserUpdate(
Application application,
Session session,
Hash args)
{
if (! _controllerUpdateUserFromArgs(args, &(session->user))) {
return NULL;
}
if (0 == uuidCompare(
uuidZero,
applicationUpdateUser(application, session->user)))
{
return NULL;
}
return controllerCurrentuserRead(application, session, NULL);
}
// vim: set ts=4 sw=4:

67
src/application/update_user.c

@ -0,0 +1,67 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
#include "auth.h"
#include "user.h"
#include "uuid.h"
#include "storage/storage.h"
#include "application/application.h"
#include "interface/serializable.h"
#include "interface/indexable.h"
#include "utils/memory.h"
#include "commons.h"
Uuid
applicationUpdateUser(
Application this,
User user)
{
char * user_serialized;
size_t nuser_serialized;
Uuid index;
index = indexUuid(user, this->user_namespace);
serialize(user, (unsigned char **)&user_serialized, &nuser_serialized);
if (SPR_OK != storageUpdate(
this->users,
(char *)(index->uuid).value,
sizeof((index->uuid).value),
user_serialized,
nuser_serialized))
{
return uuidZero;
}
return index;
}
// vim: set ts=4 sw=4:

4
src/http/worker/process.c

@ -77,7 +77,9 @@ httpWorkerProcess(HttpWorker this, Stream st)
subjectNotify(this); subjectNotify(this);
if (NULL == this->current_response) { if (NULL == this->current_response) {
if (0 == strcmp("POST", this->current_request->method)) {
if (0 == strcmp("POST", this->current_request->method) ||
0 == strcmp("PUT", this->current_request->method))
{
/* /*
* we can't do post requests on our own... * we can't do post requests on our own...
*/ */

1
src/router/route.c

@ -112,6 +112,7 @@ routerRoute(
break; break;
case HTTP_PUT: case HTTP_PUT:
args = request->post;
strcpy(&(functionName[this->nprefix + ncommand]), "Update"); strcpy(&(functionName[this->nprefix + ncommand]), "Update");
break; break;

Loading…
Cancel
Save