Changeset 7404


Ignore:
Timestamp:
Oct 4, 2017, 11:07:39 AM (5 years ago)
Author:
Nicklas Nordborg
Message:

References #2097: Implement support for device verification

Added a flag to the User class to enable/disable support device verification. It is set to false for all existing users.

For now, it can only be enabled by an administrator.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/User.java

    r7381 r7404  
    3434import net.sf.basedb.core.data.DirectoryData;
    3535import net.sf.basedb.core.hibernate.TypeWrapper;
     36import net.sf.basedb.util.EqualsHelper;
    3637import net.sf.basedb.util.MD5;
    3738import net.sf.basedb.util.bcrypt.BCrypt;
     
    578579
    579580  /**
     581    A flag indicating if device verification has been enabled for this
     582    account.
     583    @since 3.12
     584  */
     585  public boolean getUseDeviceVerification()
     586  {
     587    return getData().getUseDeviceVerification();
     588  }
     589 
     590  /**
     591    Enable or disable device verification for this user account.
     592    Note that WRITE permission is required to use this method which
     593    is normally only given to administrators. To let a user
     594    enable this feature by itself, the email address must first
     595    be verified.
     596    @see xxxx
     597    @since 3.12
     598  */
     599  public void setUseDeviceVerification(boolean useDeviceVerification)
     600  {
     601    checkPermission(Permission.WRITE);
     602    if (getData().getEmail() == null) useDeviceVerification = false;
     603    getData().setUseDeviceVerification(useDeviceVerification);
     604  }
     605 
     606  /**
    580607    Check if the user account is a multiuser account or not. Multiuser accounts
    581608    don't have write permissions for contact information and settings.
     
    787814  /**
    788815    Set the email address to the user, or null if unknown.
     816   
     817    Note! If the email address is changed, device verification will be disabled
     818    until the email address is verified!
     819   
    789820    @param email Email to be set, null is allowed.
    790821    @throws PermissionDeniedException If the logged in user doesn't have
     
    797828  {
    798829    checkPermission(Permission.RESTRICTED_WRITE);
     830    String current = getData().getEmail();
    799831    getData().setEmail(StringUtil.setNullableString(email, "email", MAX_EMAIL_LENGTH));
     832    if (!EqualsHelper.equals(email, current))
     833    {
     834      getData().setUseDeviceVerification(false);
     835    }
    800836  }
    801837
  • trunk/src/core/net/sf/basedb/core/data/UserData.java

    r7015 r7404  
    184184  }
    185185
     186  private boolean useDeviceVerification;
     187  /**
     188    A flag indicating if this user want to use device verification.
     189    @since 3.12
     190    NOTE! This property is mapped in hibernate-properties-UserData.xml since
     191    'default' is not supported by XDoclet
     192    //hibernate.property type="boolean"
     193    //hibernate.column name="`use_device_verification`" not-null="true" default="false"
     194  */
     195  public boolean getUseDeviceVerification()
     196  {
     197    return useDeviceVerification;
     198  }
     199  public void setUseDeviceVerification(boolean useDeviceVerification)
     200  {
     201    this.useDeviceVerification = useDeviceVerification;
     202  }
     203
    186204  private boolean multiuserAccount = false;
    187205  /**
  • trunk/src/core/net/sf/basedb/core/data/hibernate-properties-UserData.xml

    r5442 r7404  
    1616    />
    1717  </property>
     18
     19  <property
     20    name="useDeviceVerification"
     21    type="boolean"
     22    update="true"
     23    insert="true"
     24    access="property"
     25    >
     26    <column
     27      name="`use_device_verification`"
     28      not-null="true"
     29      default="false"
     30    />
     31  </property>
     32 
  • trunk/www/admin/users/edit_user.jsp

    r6387 r7404  
    455455          </tr>
    456456          </table>
     457        </td>
     458        <td></td>
     459      </tr>
     460      <tr>
     461        <th><label for="use_device_verification">Device verfication</label></th>
     462        <td><input type="checkbox" name="use_device_verification" id="use_device_verification" value="1"
     463          <%=(user != null && user.getUseDeviceVerification()) ||
     464            (user == null && Values.getBoolean(cc.getPropertyValue("useDeviceVerification"))) ? "checked" : ""%>
     465          >(Requires a valid email address)
    457466        </td>
    458467        <td></td>
  • trunk/www/admin/users/index.jsp

    r6315 r7404  
    248248      // Contact information
    249249      user.setEmail(email);
     250      // NOTE!! Important that this is done in this order since setEmail() resets the device verification flag
     251      user.setUseDeviceVerification(Values.getBoolean(request.getParameter("use_device_verification")));
    250252      user.setOrganisation(Values.getStringOrNull(request.getParameter("organisation")));
    251253      user.setAddress(Values.getStringOrNull(request.getParameter("address")));
  • trunk/www/admin/users/list_users.jsp

    r7269 r7404  
    234234        datatype="boolean"
    235235        title="Multi-user account"
     236        sortable="true"
     237        filterable="true"
     238        exportable="true"
     239      />
     240      <tbl:columndef
     241        id="useDeviceVerification"
     242        property="useDeviceVerification"
     243        datatype="boolean"
     244        title="Device verification"
    236245        sortable="true"
    237246        filterable="true"
     
    589598                <tbl:cell column="disabled"><%=item.isDisabled() ? "yes" : "no" %></tbl:cell>
    590599                <tbl:cell column="multiuserAccount"><%=item.isMultiuserAccount() ? "yes" : "no" %></tbl:cell>
     600                <tbl:cell column="useDeviceVerification"><%=item.getUseDeviceVerification() ? "yes" : "no" %></tbl:cell>
    591601                <tbl:cell column="groups">
    592602                  <%
  • trunk/www/admin/users/view_user.jsp

    r6605 r7404  
    5050  import="net.sf.basedb.clients.web.PermissionUtil"
    5151  import="net.sf.basedb.clients.web.util.HTML"
     52  import="net.sf.basedb.util.EmailUtil"
    5253  import="net.sf.basedb.util.Values"
    5354  import="net.sf.basedb.util.formatter.Formatter"
     
    244245          <th>Multi-user account</th>
    245246          <td><%=user.isMultiuserAccount() ? "yes" : "no"%></td>
     247        </tr>
     248        <tr>
     249          <th>Device verification</th>
     250          <td><%=user.getUseDeviceVerification() ? "yes" : "no"%>
     251          <%
     252          if (!EmailUtil.isEnabled() && user.getUseDeviceVerification())
     253          {
     254            %>
     255            (You need to configure an email server in <i>base.config</i> before you can use this feature.)
     256            <%
     257          }
     258          %>
     259          </td>
    246260        </tr>
    247261        <tr>
Note: See TracChangeset for help on using the changeset viewer.