Advertisement
Guest User

Untitled

a guest
Mar 1st, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. /**
  2. * ***************************************************************************
  3. * Copyright (c) 2010 Qcadoo Limited
  4. * Project: Qcadoo Framework
  5. * Version: 1.3
  6. *
  7. * This file is part of Qcadoo.
  8. *
  9. * Qcadoo is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published
  11. * by the Free Software Foundation; either version 3 of the License,
  12. * or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty
  16. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. * See the GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. * ***************************************************************************
  23. */
  24. package com.qcadoo.plugins.users.internal;
  25.  
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28.  
  29. import com.qcadoo.model.api.DataDefinitionService;
  30. import com.qcadoo.model.api.Entity;
  31. import com.qcadoo.security.api.SecurityService;
  32. import com.qcadoo.security.constants.QcadooSecurityConstants;
  33. import com.qcadoo.view.api.ComponentState;
  34. import com.qcadoo.view.api.ViewDefinitionState;
  35. import com.qcadoo.view.api.components.FieldComponent;
  36. import com.qcadoo.view.api.components.FormComponent;
  37.  
  38. @Service
  39. public final class UserService {
  40.  
  41. @Autowired
  42. private SecurityService securityService;
  43.  
  44. @Autowired
  45. private DataDefinitionService dataDefinitionService;
  46.  
  47. public void setPasswordAndOldPasswordAdRequired(final ViewDefinitionState state) {
  48. FieldComponent viewIdentifier = (FieldComponent) state.getComponentByReference("viewIdentifierHiddenInput");
  49. FieldComponent oldPassword = (FieldComponent) state.getComponentByReference("oldPasswordTextInput");
  50. FieldComponent password = (FieldComponent) state.getComponentByReference("passwordTextInput");
  51. FieldComponent passwordConfirmation = (FieldComponent) state.getComponentByReference("passwordConfirmationTextInput");
  52.  
  53. oldPassword.setRequired(true);
  54. password.setRequired(true);
  55. passwordConfirmation.setRequired(true);
  56. viewIdentifier.setFieldValue("profileChangePassword");
  57. }
  58.  
  59. public void setPasswordAsRequired(final ViewDefinitionState state) {
  60. FieldComponent viewIdentifier = (FieldComponent) state.getComponentByReference("viewIdentifierHiddenInput");
  61. FieldComponent password = (FieldComponent) state.getComponentByReference("passwordTextInput");
  62. FieldComponent passwordConfirmation = (FieldComponent) state.getComponentByReference("passwordConfirmationTextInput");
  63.  
  64. password.setRequired(true);
  65. passwordConfirmation.setRequired(true);
  66. viewIdentifier.setFieldValue("userChangePassword");
  67. }
  68.  
  69. public void hidePasswordOnUpdateForm(final ViewDefinitionState state) {
  70. FormComponent form = (FormComponent) state.getComponentByReference("form");
  71. FieldComponent password = (FieldComponent) state.getComponentByReference("passwordTextInput");
  72. FieldComponent passwordConfirmation = (FieldComponent) state.getComponentByReference("passwordConfirmationTextInput");
  73. ComponentState changePasswordButton = state.getComponentByReference("changePasswordButton");
  74.  
  75. password.setRequired(true);
  76. passwordConfirmation.setRequired(true);
  77.  
  78. if (form.getEntityId() == null) {
  79. password.setVisible(true);
  80. passwordConfirmation.setVisible(true);
  81. changePasswordButton.setVisible(false);
  82. } else {
  83. password.setVisible(false);
  84. passwordConfirmation.setVisible(false);
  85. changePasswordButton.setVisible(true);
  86. }
  87. }
  88.  
  89. public void disableFormForAdmin(final ViewDefinitionState state) {
  90. FormComponent form = (FormComponent) state.getComponentByReference("form");
  91.  
  92. Entity loggedUser = dataDefinitionService
  93. .get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_USER).get(
  94. securityService.getCurrentUserId());
  95.  
  96. if (!securityService.hasRole(loggedUser, "ROLE_SUPERADMIN")) {
  97. form.setFormEnabled(false);
  98. }
  99. }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement