use of com.helger.photon.security.user.IUser in project peppol-practical by phax.
the class CommentUI method getCreateComment.
@Nonnull
public static IHCNode getCreateComment(@Nonnull final ILayoutExecutionContext aLEC, @Nonnull final String sResultDivID, @Nonnull final ITypedObject<String> aObject, @Nullable final ICommentThread aCommentThread, @Nullable final IComment aParentComment, @Nullable final CommentFormErrors aFormErrors, @Nullable final IHCNode aMessageBox) {
final IRequestWebScopeWithoutResponse aRequestScope = aLEC.getRequestScope();
final Locale aDisplayLocale = aLEC.getDisplayLocale();
final IUser aLoggedInUser = LoggedInUserManager.getInstance().getCurrentUser();
final boolean bIsCreateNewThread = aCommentThread == null || aParentComment == null;
final HCDiv aFormContainer = new HCDiv();
if (bIsCreateNewThread)
if (aFormErrors == null || aFormErrors.isEmpty())
aFormContainer.addStyle(CCSSProperties.DISPLAY_NONE);
aFormContainer.addClass(CCommentCSS.CSS_CLASS_COMMENT_CREATE);
if (aFormErrors != null && !aFormErrors.isEmpty())
aFormContainer.addChild(new BootstrapErrorBox().addChild(EPhotonCoreText.ERR_INCORRECT_INPUT.getDisplayText(aDisplayLocale)));
final BootstrapViewForm aForm = aFormContainer.addAndReturnChild(new BootstrapViewForm());
aForm.setTitle(ECommentText.MSG_CREATE_COMMENT.getDisplayText(aDisplayLocale));
HCEdit aEditAuthor = null;
if (aLoggedInUser != null) {
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory(ECommentText.MSG_FIELD_AUTHOR.getDisplayText(aDisplayLocale)).setCtrl(aLoggedInUser.getDisplayName()));
} else {
aEditAuthor = new HCEdit(new RequestField(FIELD_COMMENT_AUTHOR));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory(ECommentText.MSG_FIELD_AUTHOR.getDisplayText(aDisplayLocale)).setCtrl(aEditAuthor).setHelpText(ECommentText.DESC_FIELD_AUTHOR.getDisplayText(aDisplayLocale)).setErrorList(aFormErrors == null ? null : aFormErrors.getListOfField(FIELD_COMMENT_AUTHOR)));
}
final HCEdit aEditTitle = new HCEdit(new RequestField(FIELD_COMMENT_TITLE));
aForm.addFormGroup(new BootstrapFormGroup().setLabel(ECommentText.MSG_FIELD_TITLE.getDisplayText(aDisplayLocale)).setCtrl(aEditTitle).setHelpText(ECommentText.DESC_FIELD_TITLE.getDisplayText(aDisplayLocale)).setErrorList(aFormErrors == null ? null : aFormErrors.getListOfField(FIELD_COMMENT_TITLE)));
final HCTextAreaAutosize aTextAreaContent = new HCTextAreaAutosize(new RequestField(FIELD_COMMENT_TEXT)).setRows(5);
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory(ECommentText.MSG_FIELD_TEXT.getDisplayText(aDisplayLocale)).setCtrl(aTextAreaContent).setHelpText(ECommentText.DESC_FIELD_TEXT.getDisplayText(aDisplayLocale)).setErrorList(aFormErrors == null ? null : aFormErrors.getListOfField(FIELD_COMMENT_TEXT)));
final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aLEC);
// What to do on save?
{
final JSAnonymousFunction aOnSuccess = new JSAnonymousFunction();
final JSVar aJSData = aOnSuccess.param("data");
aOnSuccess.body().add(JQuery.idRef(sResultDivID).replaceWith(aJSData.ref(PhotonUnifiedResponse.HtmlHelper.PROPERTY_HTML)));
JQueryInvocation aSaveAction;
if (bIsCreateNewThread) {
// Create a new thread
aSaveAction = new JQueryAjaxBuilder().url(CAjax.COMMENT_CREATE_THREAD.getInvocationURL(aRequestScope)).data(new JSAssocArray().add(AjaxExecutorCommentCreateThread.PARAM_OBJECT_TYPE, aObject.getObjectType().getName()).add(AjaxExecutorCommentCreateThread.PARAM_OBJECT_ID, aObject.getID()).add(AjaxExecutorCommentCreateThread.PARAM_AUTHOR, aLoggedInUser != null ? JSExpr.lit("") : JQuery.idRef(aEditAuthor).val()).add(AjaxExecutorCommentCreateThread.PARAM_TITLE, JQuery.idRef(aEditTitle).val()).add(AjaxExecutorCommentCreateThread.PARAM_TEXT, JQuery.idRef(aTextAreaContent).val())).success(JSJQueryHelper.jqueryAjaxSuccessHandler(aOnSuccess, null)).build();
} else {
// Reply to a previous comment
aSaveAction = new JQueryAjaxBuilder().url(CAjax.COMMENT_ADD.getInvocationURL(aRequestScope)).data(new JSAssocArray().add(AjaxExecutorCommentAdd.PARAM_OBJECT_TYPE, aObject.getObjectType().getName()).add(AjaxExecutorCommentAdd.PARAM_OBJECT_ID, aObject.getID()).add(AjaxExecutorCommentAdd.PARAM_COMMENT_THREAD_ID, aCommentThread.getID()).add(AjaxExecutorCommentAdd.PARAM_COMMENT_ID, aParentComment.getID()).add(AjaxExecutorCommentAdd.PARAM_OBJECT_ID, aObject.getID()).add(AjaxExecutorCommentAdd.PARAM_AUTHOR, aLoggedInUser != null ? JSExpr.lit("") : JQuery.idRef(aEditAuthor).val()).add(AjaxExecutorCommentAdd.PARAM_TITLE, JQuery.idRef(aEditTitle).val()).add(AjaxExecutorCommentAdd.PARAM_TEXT, JQuery.idRef(aTextAreaContent).val())).success(JSJQueryHelper.jqueryAjaxSuccessHandler(aOnSuccess, null)).build();
}
aToolbar.addButtonSave(aDisplayLocale, aSaveAction);
}
BootstrapButton aButtonCreate = null;
if (bIsCreateNewThread) {
// The create button
aButtonCreate = new BootstrapButton().addChild(ECommentText.MSG_CREATE_COMMENT.getDisplayText(aDisplayLocale));
aButtonCreate.setOnClick(new JSStatementList(JQuery.idRef(aFormContainer).show(), JQuery.jQueryThis().disable()));
}
// What to do on cancel?
{
final JSStatementList aCancelAction = new JSStatementList(JQuery.idRefMultiple(aEditTitle, aTextAreaContent).val(""), JQuery.idRef(aFormContainer).hide());
if (aButtonCreate != null)
aCancelAction.add(JQuery.idRef(aButtonCreate).enable());
if (aEditAuthor != null)
aCancelAction.add(JQuery.idRef(aEditAuthor).val(""));
aToolbar.addButtonCancel(aDisplayLocale, aCancelAction);
}
aFormContainer.addChild(aToolbar);
// Show create comment button
final HCNodeList ret = new HCNodeList();
ret.addChild(aButtonCreate);
ret.addChild(aFormContainer);
ret.addChild(aMessageBox);
return ret;
}
use of com.helger.photon.security.user.IUser in project peppol-practical by phax.
the class LayoutAreaContentProviderPublic method _getNavbar.
@Nonnull
private static BootstrapNavbar _getNavbar(final LayoutExecutionContext aLEC) {
final ISimpleURL aLinkToStartPage = aLEC.getLinkToMenuItem(aLEC.getMenuTree().getDefaultMenuItemID());
final Locale aDisplayLocale = aLEC.getDisplayLocale();
final IRequestWebScopeWithoutResponse aRequestScope = aLEC.getRequestScope();
final IUser aUser = LoggedInUserManager.getInstance().getCurrentUser();
final BootstrapNavbar aNavbar = new BootstrapNavbar();
aNavbar.addBrand(new HCSpan().addClass(AppCommonUI.CSS_CLASS_LOGO1).addChild(AppHelper.getApplicationTitle()), aLinkToStartPage);
aNavbar.addChild(new BootstrapButton(EBootstrapButtonType.DEFAULT).addChild("Participant information").setIcon(EFamFamIcon.USER_GREEN).setOnClick(aLEC.getLinkToMenuItem(CMenuPublic.MENU_TOOLS_PARTICIPANT_INFO)).addClass(CBootstrapCSS.ML_AUTO).addClass(CBootstrapCSS.MX_2));
aNavbar.addChild(new BootstrapButton(EBootstrapButtonType.DEFAULT).addChild("Document validation").setIcon(EFamFamIcon.SCRIPT_GO).setOnClick(aLEC.getLinkToMenuItem(CMenuPublic.MENU_VALIDATION_UPLOAD)).addClass(CBootstrapCSS.ML_AUTO).addClass(CBootstrapCSS.MX_2));
aNavbar.addChild(new BootstrapButton(EBootstrapButtonType.DEFAULT).addChild("ID information").setIcon(EFamFamIcon.CUP).setOnClick(aLEC.getLinkToMenuItem(CMenuPublic.MENU_TOOLS_ID_INFO)).addClass(CBootstrapCSS.ML_AUTO).addClass(CBootstrapCSS.MX_2));
final BootstrapNavbarToggleable aToggleable = aNavbar.addAndReturnToggleable();
if (aUser != null) {
aToggleable.addAndReturnText().addClass(CBootstrapCSS.ML_AUTO).addClass(CBootstrapCSS.MX_2).addChild("Welcome ").addChild(new HCStrong().addChild(SecurityHelper.getUserDisplayName(aUser, aDisplayLocale)));
if (SecurityHelper.hasUserRole(aUser.getID(), CPPApp.ROLE_CONFIG_ID)) {
aToggleable.addChild(new BootstrapButton().setOnClick(LinkHelper.getURLWithContext(AbstractSecureApplicationServlet.SERVLET_DEFAULT_PATH)).addChild("Administration").addClass(CBootstrapCSS.MX_2));
}
aToggleable.addChild(new BootstrapButton().setOnClick(LinkHelper.getURLWithContext(aRequestScope, LogoutServlet.SERVLET_DEFAULT_PATH)).addChild(EPhotonCoreText.LOGIN_LOGOUT.getDisplayText(aDisplayLocale)).addClass(CBootstrapCSS.MX_2));
} else {
// show login in Navbar
final BootstrapNavbarNav aNav = aToggleable.addAndReturnNav();
final BootstrapDropdownMenu aDropDown = new BootstrapDropdownMenu();
{
final HCDiv aDiv = new HCDiv().addClass(CBootstrapCSS.P_2).addStyle(CCSSProperties.MIN_WIDTH.newValue("400px"));
aDiv.addChild(AppCommonUI.createViewLoginForm(aLEC, null, false));
aDropDown.addChild(aDiv);
}
aNav.addItem().addNavDropDown("Login", aDropDown);
aToggleable.addChild(new BootstrapButton(EBootstrapButtonType.SUCCESS).addChild(EPhotonCoreText.BUTTON_SIGN_UP.getDisplayText(aDisplayLocale)).setOnClick(aLEC.getLinkToMenuItem(CMenuPublic.MENU_SIGN_UP)).addClass(CBootstrapCSS.ML_AUTO).addClass(CBootstrapCSS.MX_2));
}
return aNavbar;
}
use of com.helger.photon.security.user.IUser in project peppol-practical by phax.
the class PagePublicSignUp method validateAndSaveInputParameters.
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final FormErrorList aFormErrors) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
final IUserGroupManager aUserGroupMgr = PhotonSecurityManager.getUserGroupMgr();
final String sFirstName = aWPEC.params().getAsString(FIELD_FIRSTNAME);
final String sLastName = aWPEC.params().getAsString(FIELD_LASTNAME);
final String sEmailAddress = aWPEC.params().getAsString(FIELD_EMAIL1);
final String sEmailAddressConfirm = aWPEC.params().getAsString(FIELD_EMAIL2);
final String sPlainTextPassword = aWPEC.params().getAsString(FIELD_PASSWORD);
final String sPlainTextPasswordConfirm = aWPEC.params().getAsString(FIELD_PASSWORD_CONFIRM);
if (StringHelper.hasNoText(sFirstName))
aFormErrors.addFieldError(FIELD_FIRSTNAME, "A first name must be provded!!");
if (StringHelper.hasNoText(sLastName))
aFormErrors.addFieldError(FIELD_LASTNAME, "A last name must be provded!!");
if (StringHelper.hasNoText(sEmailAddress))
aFormErrors.addFieldError(FIELD_EMAIL1, "An email address must be provded!!");
else if (!EmailAddressHelper.isValid(sEmailAddress))
aFormErrors.addFieldError(FIELD_EMAIL1, "The provided email address is not valid!");
else if (!sEmailAddress.equals(sEmailAddressConfirm)) {
aFormErrors.addFieldError(FIELD_EMAIL2, "The two provided email addresses don't match!");
} else {
IUser aUser = aUserMgr.getUserOfLoginName(sEmailAddress);
if (aUser == null)
aUser = aUserMgr.getUserOfEmailAddress(sEmailAddress);
if (aUser != null)
aFormErrors.addFieldError(FIELD_EMAIL1, "Another user with the same email address is already registered!");
}
final List<String> aPasswordErrors = GlobalPasswordSettings.getPasswordConstraintList().getInvalidPasswordDescriptions(sPlainTextPassword, aDisplayLocale);
for (final String sPasswordError : aPasswordErrors) aFormErrors.addFieldError(FIELD_PASSWORD, "Error: " + sPasswordError);
if (!aFormErrors.hasEntryForField(FIELD_PASSWORD) && !EqualsHelper.equals(sPlainTextPassword, sPlainTextPasswordConfirm))
aFormErrors.addFieldError(FIELD_PASSWORD_CONFIRM, "The two provided passwords don't match!");
if (aFormErrors.isEmpty()) {
final String sDescription = "User signed up at " + PDTFactory.getCurrentLocalDateTime().toString() + " from " + aWPEC.getRequestScope().getRemoteAddr();
// Create new user
final IUser aCreatedUser = aUserMgr.createNewUser(sEmailAddress, sEmailAddress, sPlainTextPassword, sFirstName, sLastName, sDescription, aDisplayLocale, (Map<String, String>) null, false);
if (aCreatedUser == null)
aNodeList.addChild(error("Error creating the new user!"));
else {
// Assign new user to user group
if (aUserGroupMgr.assignUserToUserGroup(CPPApp.USERGROUP_VIEW_ID, aCreatedUser.getID()).isUnchanged())
aNodeList.addChild(error("Error assigning the user to the user group!"));
else {
aNodeList.addChild(success("You have been registered successfully! You may now login with your email address '" + sEmailAddress + "' and the selected password."));
// Show login form
aNodeList.addChild(AppCommonUI.createViewLoginForm(aWPEC, sEmailAddress, false));
}
}
}
}
use of com.helger.photon.security.user.IUser in project peppol-practical by phax.
the class AppCommonUI method createViewLink.
@Nonnull
public static IHCNode createViewLink(@Nonnull final IWebPageExecutionContext aWPEC, @Nullable final ITypedObject<String> aObject, @Nullable final String sDisplayName) {
if (aObject == null)
return HCTextNode.createOnDemand(sDisplayName);
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
if (aObject instanceof IRole) {
final IRole aTypedObj = (IRole) aObject;
final String sRealDisplayName = sDisplayName != null ? sDisplayName : aTypedObj.getName();
final String sMenuItemID = BootstrapPagesMenuConfigurator.MENU_ADMIN_SECURITY_ROLE;
final IMenuObject aObj = aWPEC.getMenuTree().getItemDataWithID(sMenuItemID);
if (aObj != null && aObj.matchesDisplayFilter())
return new HCA(getViewLink(aWPEC, sMenuItemID, aTypedObj)).addChild(sRealDisplayName).setTitle("Show details of role '" + sRealDisplayName + "'");
return new HCTextNode(sRealDisplayName);
}
if (aObject instanceof IUser) {
final IUser aTypedObj = (IUser) aObject;
final String sRealDisplayName = sDisplayName != null ? sDisplayName : SecurityHelper.getUserDisplayName(aTypedObj, aDisplayLocale);
final String sMenuItemID = BootstrapPagesMenuConfigurator.MENU_ADMIN_SECURITY_USER;
final IMenuObject aObj = aWPEC.getMenuTree().getItemDataWithID(sMenuItemID);
if (aObj != null && aObj.matchesDisplayFilter())
return new HCA(getViewLink(aWPEC, sMenuItemID, aTypedObj)).addChild(sRealDisplayName).setTitle("Show details of user '" + sRealDisplayName + "'");
return new HCTextNode(sRealDisplayName);
}
if (aObject instanceof IUserGroup) {
final IUserGroup aTypedObj = (IUserGroup) aObject;
final String sRealDisplayName = sDisplayName != null ? sDisplayName : aTypedObj.getName();
final String sMenuItemID = BootstrapPagesMenuConfigurator.MENU_ADMIN_SECURITY_USER_GROUP;
final IMenuObject aObj = aWPEC.getMenuTree().getItemDataWithID(sMenuItemID);
if (aObj != null && aObj.matchesDisplayFilter())
return new HCA(getViewLink(aWPEC, sMenuItemID, aTypedObj)).addChild(sRealDisplayName).setTitle("Show details of user group '" + sRealDisplayName + "'");
return new HCTextNode(sRealDisplayName);
}
// add other types as desired
throw new IllegalArgumentException("Unsupported object: " + aObject);
}
Aggregations