Kawai Wiki

Compare Revisions

Ignore whitespace Rev 148 → Rev 149

/trunk/src/main/java/org/kawai/model/Group.java
33,7 → 33,7
}
public static ListData getListData() {
SimpleListData list = new SimpleListData("Groups");
SimpleListData list = new SimpleListData("groups");
for(Group g : Group.values()) {
list.add(g.getId(), g.getName());
}
/trunk/src/main/java/org/kawai/AppManager.java
30,6 → 30,7
import org.mentawai.filter.AuthorizationFilter;
import org.mentawai.filter.ExceptionFilter;
import org.mentawai.filter.FileUploadFilter;
import org.mentawai.filter.FlashScopeFilter;
import org.mentawai.filter.MentaContainerFilter;
import org.mentawai.filter.TransactionFilter;
import org.mentawai.filter.ValidationFilter;
172,6 → 173,8
filter(new MentaContainerFilter());
filter(new FlashScopeFilter());
//////////////////////////////////////////////////////////
// AUTHENTICATION: ALL ACTIONS THAT DO NOT IMPLEMENT
// THE AuthenticationFree INTERFACE WILL REQUIRE
219,8 → 222,8
action("/User", UserAction.class, "add")
.filter(adminFilter)
.on(ERROR, fwd("/jsp/user/add.jsp"))
.on(CREATED, fwd("/frontpage.jsp"));
.on(ERROR, chain(mainAction))
.on(CREATED, redir(mainAction));
action("/User", UserAction.class, "check")
.filter(adminFilter)
/trunk/src/main/java/org/kawai/action/UserAction.java
4,17 → 4,14
import org.kawai.model.User;
import org.mentawai.core.BaseAction;
import org.mentawai.filter.AuthenticationFree;
import org.mentawai.mail.Letter;
import org.mentawai.mail.SimpleEmail;
import org.mentawai.mail.TextLetter;
import org.mentawai.rule.EmailRule;
import org.mentawai.rule.EqualRule;
import org.mentawai.rule.MethodRule;
import org.mentawai.rule.RegexRule;
import org.mentawai.validation.Validatable;
import org.mentawai.validation.ValidationInterceptor;
import org.mentawai.validation.Validator;
 
public class UserAction extends BaseAction implements Validatable, AuthenticationFree {
public class UserAction extends BaseAction implements Validatable, AuthenticationFree, ValidationInterceptor {
private final UserDAO userDAO;
42,18 → 39,31
if (method != null && method.equals("add") && isPost()) {
val.requiredFields("required_field", "username", "password", "email", "groupId", "languageId");
val.requiredFields("Required Field", "username", "password", "groupId");
val.requiredLists("required_field", "groupId", "languageId");
val.requiredLists("Required Field", "groupId");
val.add("username", RegexRule.getInstance(username_regex), "bad_username");
val.add("username", RegexRule.getInstance(username_regex), "Invalid Username");
val.add("username", MethodRule.getInstance(this, "checkUsernameAdd"), "username_already_exists");
val.add("username", MethodRule.getInstance(this, "checkUsernameAdd"), "Username already exists!");
val.add("email", EmailRule.getInstance(), "bad_email");
val.add("password", EqualRule.getInstance("password", "passconf"), "Passwords do not match!");
}
}
@Override
public boolean beforeValidation(String method) {
return true; // go ahead with validation...
}
@Override
public void afterValidation(String method, boolean wasOk) {
if (method == null) return;
if (method.equals("add") && !wasOk) {
val.add("password", EqualRule.getInstance("password", "passconf"), "pass_no_match");
output.setValue("showForm", "addNewUser");
}
}
99,7 → 109,7
setSessionGroup(u.getGroup());
addMessage("registration_ok");
addMessage("User " + u.getUsername() + " added!", true);
return CREATED;
}
/trunk/src/main/webapp/images/loading.gif
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/src/main/webapp/images/chk.gif
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+ application/octet-stream
/trunk/src/main/webapp/WEB-INF/db/kawai.sql
141,7 → 141,7
--
 
 
INSERT INTO `Users` VALUES (1,'admin','abc123',1),(2,'saoj','abc123',1),(3,'soliveira','abc123',2),(4,'fernando','abc123',1),(5,'helio','abc123',1),(6,'ricardo','abc123',1),(7,'robert','abc123',1);
INSERT INTO `Users` VALUES (1,'admin','abc123',1),(2,'saoj','abc123',1),(3,'soliveira','abc123',2),(4,'fernando','abc123',1),(5,'helio','abc123',1),(6,'ricardo','abc123',1),(7,'robert','abc123',1),(8,'pela1','abc123',1),(9,'pela2','abc123',1),(10,'pela3','abc123',1);
 
 
 
153,4 → 153,4
 
 
 
-- Dump completed on 2011-11-05 13:09:37
-- Dump completed on 2011-11-05 16:26:19
/trunk/src/main/webapp/show_page.jsp
63,11 → 63,19
<mtw:if test="showForm" value="login">
showLoginDialog();
</mtw:if>
 
<mtw:if test="showForm" value="addNewUser">
showAddNewUserDialog(false);
</mtw:if>
<mtw:if test="showForm" value="add">
showCreateNewPageDialog();
</mtw:if>
</mtw:if>
 
<mtw:outMessage>
alert('<mtw:out />');
</mtw:outMessage>
 
$('#loginDialog').keyup(function(e) {
if (e.keyCode == 13) {
$('#loginForm').submit();
93,7 → 101,32
}
}
});
 
// ajax add new user:
 
$('#usernameLoading').hide();
$('#addNewUserUsername').blur( function() {
$('#usernameMessage').hide();
if ($('#addNewUserUsername').val().trim() != '') {
 
$('#usernameLoading').show();
$.post("<mtw:contextPath />/User.check.mtw", {
username : $('#addNewUserUsername').val()
}, function(response) {
$('#usernameMessage').fadeOut();
setTimeout("usernameResult('"
+ escape(response) + "')", 400);
});
}
return false;
});
 
});
function prepareEditPageDialog(myDialog, theTitle) {
684,6 → 717,15
 
return false;
}
 
function showAddNewUserDialog(hideUsernameMessage) {
 
myDialog = $('#addNewUserDialog');
myDialog = prepareAddNewUserDialog(myDialog, hideUsernameMessage);
myDialog.dialog('open');
 
return false;
}
function clearLoginForm() {
$('#loginUsername').val('');
691,6 → 733,17
$('#loginUsernameError').text('');
$('#loginPasswordError').text('');
}
 
function clearAddNewUserForm() {
$('#addNewUserUsername').val('');
$('#addNewUserPassword').val('');
$('#addNewUserPassconf').val('');
$('#addNewUserGroup').val('');
$('#usernameMessage').text('');
$('#addNewUserPasswordError').text('');
$('#addNewUserPassconfError').text('');
$('#addNewUserGroupError').text('');
}
function clearCreateNewPageForm() {
$('#createNewPageName').val('');
727,6 → 780,34
 
return myDialog;
}
 
function prepareAddNewUserDialog(myDialog, hideUsernameMessage) {
 
$('#usernameLoading').hide();
if (hideUsernameMessage) $('#usernameMessage').text('');
 
options = {
close: function() { clearAddNewUserForm(); },
autoOpen: false,
width: 550,
modal: true,
title: "Add New User:",
buttons: [
{
text: "Add",
click: function() { $('#addNewUserForm').submit(); }
},
{
text: "Cancel",
click: function() { $(this).dialog("close"); }
}
]
};
 
myDialog.dialog(options);
 
return myDialog;
}
function prepareConfirmDialog(myDialog) {
 
761,12 → 842,110
return false;
}
</script>
function usernameResult(response) {
$('#usernameLoading').hide();
var res = unescape(response);
if (res == "error") {
$('#usernameMessage')
.html(
'<font color="red"><b>Error!</b></font>');
$('#usernameMessage').fadeIn();
} else if (res == "success") {
$('#usernameMessage').html(
'<img src="<mtw:contextPath />/images/chk.gif" />');
$('#usernameMessage').fadeIn();
} else if (res == "already") {
$('#usernameMessage')
.html(
'<font color="red"><b>Username already exists!</b></font>');
$('#usernameMessage').fadeIn();
}
}
</script>
 
</head>
 
<body class="composite">
 
<!-- For adding username -->
<div id="addNewUserDialog" style="display: none;">
<form action="<mtw:contextPath />/User.add.mtw" method="post" id="addNewUserForm">
<table>
<tr>
<td width="10%">
Username:
</td>
<td>
<mtw:input name="username" id="addNewUserUsername" size="20" maxlength="30" />
<span id="usernameLoading">
<img src="<mtw:contextPath />/images/loading.gif" />
</span>
<span id="usernameMessage">
<mtw:outError field="username">
<font color="red">
<b><mtw:out /></b>
</font>
</mtw:outError>
</span>
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<mtw:input name="password" type="password" size="20" maxlength="20" id="addNewUserPassword" />
<span id="addNewUserPasswordError">
<mtw:outError field="password">
<font color="red">
<b><mtw:out /></b>
</font>
</mtw:outError>
</span>
</td>
</tr>
<tr>
<td>
Confirm:
</td>
<td>
<mtw:input name="passconf" type="password" size="20" maxlength="20" id="addNewUserPassconf" />
<span id="addNewUserPassconfError">
<mtw:outError field="passconf">
<font color="red">
<b><mtw:out /></b>
</font>
</mtw:outError>
</span>
</td>
</tr>
<tr>
<td>
Group:
</td>
<td>
<mtw:select name="groupId" list="groups" emptyField="true" id="addNewUserGroup" />
<span id="addNewUserGroupError">
<mtw:outError field="groupId">
<font color="red">
<b><mtw:out /></b>
</font>
</mtw:outError>
</span>
</td>
</tr>
</table>
</form>
</div>
 
<!-- For Testing -->
<div id="dialog" title="Dialog Title" style="display: none;">I'm in a dialog</div>
 
1031,6 → 1210,7
</mtw:isLogged>
<mtw:isLogged>
<a href="#" onclick="return showCreateNewPageDialog();">Create New Page</a> |
<a href="#" onclick="return showAddNewUserDialog(true);">Add New User</a> |
<a href="#" onclick="return showListAllPagesDialog(<mtw:out value="sessionUser.admin" />);">List Pages</a> |
<mtw:hasAuthorization groups="admin, editor">