001 package net.databinder.auth.components.ao;
002
003 import java.util.Map;
004
005 import net.databinder.auth.AuthApplication;
006 import net.databinder.auth.components.DataProfilePanelBase;
007 import net.databinder.auth.components.DataSignInPageBase.ReturnPage;
008 import net.databinder.auth.data.ao.UserHelper;
009 import net.databinder.components.ao.DataForm;
010 import net.databinder.models.ao.EntityModel;
011
012 import org.apache.wicket.authorization.strategies.role.Roles;
013 import org.apache.wicket.markup.html.form.Form;
014 import org.apache.wicket.model.IModel;
015
016 /**
017 * Registration with username, password, and password confirmation.
018 * Replaceable String resources: <pre>
019 * data.auth.username
020 * data.auth.password
021 * data.auth.passwordConfirm
022 * data.auth.remember
023 * data.auth.register
024 * data.auth.update
025 * data.auth.username.taken * </pre> * Must be overriden in a containing page
026 * or a subclass of this panel.
027 */
028 public class DataProfilePanel extends DataProfilePanelBase {
029
030 public DataProfilePanel(String id, ReturnPage returnPage) {
031 super(id, returnPage);
032 }
033
034 private DataForm form;
035
036 @Override
037 protected Form profileForm(String id, IModel userModel) {
038 if (userModel == null)
039 userModel = new EntityModel(((AuthApplication)getApplication()).getUserClass());
040 return form = new DataForm(id, (EntityModel) userModel) {
041 @SuppressWarnings("unchecked")
042 @Override
043 protected void onSubmit() {
044 if (!getEntityModel().isBound()) {
045 Map<String, Object> map = (Map) getModelObject();
046 map.put("roleString", Roles.USER);
047 }
048 super.onSubmit();
049 }
050 @Override
051 protected void afterSubmit() {
052 DataProfilePanel.this.afterSubmit();
053 }
054 };
055 }
056
057 /**
058 * Uses super implementation if bound, but for new users this method must call
059 * UserHelper.getHash(password) to set the hash in "passwordHash". If application
060 * uses different hasing implementation.
061 */
062 @SuppressWarnings("unchecked")
063 @Override
064 protected void setPassword(String password) {
065 if (form.getEntityModel().isBound())
066 super.setPassword(password);
067 else
068 ((Map)form.getModelObject()).put("passwordHash", UserHelper.getHash(password));
069 }
070
071 }