Changeset 7816


Ignore:
Timestamp:
Jun 5, 2020, 1:10:03 PM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #2213: Extend registration of devices

Added isVerified flag to devices. Validation should now work again. Since all devices are now registered the "Remember device" option when verifying a device simple sets the isVerifed flag to true.

Location:
trunk
Files:
1 added
8 edited

Legend:

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

    r7813 r7816  
    118118    method.
    119119  */
    120   public static final int NEW_SCHEMA_VERSION = Integer.valueOf(147).intValue();
     120  public static final int NEW_SCHEMA_VERSION = Integer.valueOf(148).intValue();
    121121 
    122122  public static synchronized int createTables(SchemaGenerator.Mode mode, ProgressReporter progress,
  • trunk/src/core/net/sf/basedb/core/SessionControl.java

    r7815 r7816  
    432432   
    433433    UserDeviceData device = null;
     434    boolean needToVerifyDevice = false;
    434435    AuthenticatedUser authUser = null;
    435436    UserData user = null;
     
    463464     
    464465      // The login was ok so far... check device verification
    465       device = verifyDevice(session, loginRequest, authUser);
     466      device = loadDevice(session, loginRequest, authUser);
     467      needToVerifyDevice = device != null && !device.isVerified() && user.getUseDeviceVerification() && EmailUtil.isEnabled();
    466468     
    467       // A null value means that either device verification is disabled
    468       // An existing device means that it is already registered (TODO - check if verification is needed!!)
    469469      LoginInfo li = null;
    470       if (device == null || device.getId() != 0)
     470      if (!needToVerifyDevice)
    471471      {
    472472        // All is ok, finalize the login
     
    496496    }
    497497   
    498     if (device != null && device.getId() == 0)
     498    if (needToVerifyDevice)
    499499    {
    500500      // Device verification is enabled and the user is using an unverified device
     
    595595      LoginRequest loginRequest = unverifiedDeviceInfo.loginRequest;
    596596      AuthenticatedUser authUser = unverifiedDeviceInfo.authenticatedUser;
    597      
    598       int deviceId = 0;
     597      int deviceId = unverifiedDeviceInfo.device.getId();
    599598      if (rememberDevice)
    600599      {
    601         HibernateUtil.saveData(session, unverifiedDeviceInfo.device);
    602         deviceId = unverifiedDeviceInfo.device.getId();
     600        HibernateUtil.loadData(session, UserDeviceData.class, deviceId).setVerified(true);
    603601      }
    604602     
     
    814812    @return An {@link UserDeviceData} object if device verification is
    815813      supported and needed, null to continue with normal login
    816     @since 3.12
    817   */
    818   private UserDeviceData verifyDevice(org.hibernate.Session session, LoginRequest loginRequest, AuthenticatedUser authUser)
     814    @since 3.12, 3.17
     815  */
     816  private UserDeviceData loadDevice(org.hibernate.Session session, LoginRequest loginRequest, AuthenticatedUser authUser)
    819817  {
    820818    // Check the submitted deviceToken
     
    874872      device.setToken(deviceToken);
    875873      device.setUserAgent(userAgent);
     874      device.setVerified(false);
    876875    }
    877876
     
    884883    device.setLocationLatitude(loc.getLatitude());
    885884    device.setLocationLongitude(loc.getLongitude());
    886 
    887     // If this is a new or unverified device we check if it needs to be verified
    888     if (device.getId() == 0)
    889     {
    890       if (user.getUseDeviceVerification() && EmailUtil.isEnabled())
    891       {
    892         // The device need verification so we do not save it
    893         // TODO -- will not work correctly if we add device.isVerified() flag
    894       }
    895       else
    896       {
    897         HibernateUtil.saveData(session, device);
    898       }
    899     }
     885   
     886    if (device.getId() == 0) HibernateUtil.saveData(session, device);
    900887
    901888    return device;
  • trunk/src/core/net/sf/basedb/core/Update.java

    r7703 r7816  
    434434    </td>
    435435  </tr>
     436  <tr>
     437    <td>148</td>
     438    <td>
     439      Added {@link UserDeviceData#isVerified()}.
     440      The update will set the value to TRUE for all existing devices.
     441    </td>
     442  </tr>
    436443  </table>
    437444
     
    709716        if (progress != null) progress.display((int)(progress_current), "--Updating schema version: " + schemaVersion + " -> 147...");
    710717        schemaVersion = updateToSchemaVersion147(session, schemaVersion);
     718        progress_current += progress_step;
     719      }
     720     
     721      if (schemaVersion < 148)
     722      {
     723        if (progress != null) progress.display((int)(progress_current), "--Updating schema version: " + schemaVersion + " -> 148...");
     724        schemaVersion = setSchemaVersionInTransaction(session, 148);
    711725        progress_current += progress_step;
    712726      }
     
    10721086          "SET at.identifier = false " +
    10731087          "WHERE at.identifier IS NULL");
     1088        query.executeUpdate();
     1089      }
     1090     
     1091      if (schemaVersion < 148)
     1092      {
     1093        // Set is_verified=true on all registered devices
     1094        org.hibernate.query.Query<?> query = HibernateUtil.createQuery(session,
     1095          "UPDATE UserDeviceData ud " +
     1096          "SET ud.verified = true " +
     1097          "WHERE ud.verified = false");
    10741098        query.executeUpdate();
    10751099      }
  • trunk/src/core/net/sf/basedb/core/UserDevice.java

    r7413 r7816  
    261261    return getData().getLocationLongitude();
    262262  }
     263 
     264  /**
     265    Has this device been verified or not? Verification is done
     266    by requesting a code via email.
     267    @since 3.17
     268  */
     269  public boolean isVerified()
     270  {
     271    return getData().isVerified();
     272  }
    263273
    264274}
  • trunk/src/core/net/sf/basedb/core/data/UserDeviceData.java

    r7461 r7816  
    236236  }
    237237 
     238  private boolean isVerified;
     239  /**
     240    This flag is TRUE if the device has been verified (by sending a code via email).
     241    @since 3.17
     242    Mapped in hibernate-properties-UserDeviceData.xml since default is not supported in XDoclet
     243    //hibernate.property column="`is_verified`" type="boolean" not-null="true" default="false"
     244  */
     245  public boolean isVerified()
     246  {
     247    return isVerified;
     248  }
     249  public void setVerified(boolean isVerified)
     250  {
     251    this.isVerified = isVerified;
     252  }
     253
    238254  private Set<SessionData> sessions;
    239255  /**
  • trunk/www/views/devices/index.jsp

    r7605 r7816  
    6262<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
    6363<%!
    64   private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,client,lastUsed,lastRemoteId,location,description");
     64  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,client,verified,lastUsed,lastRemoteId,location,description");
    6565  private static final Item itemType = Item.USERDEVICE;
    6666%>
  • trunk/www/views/devices/list_devices.jsp

    r7604 r7816  
    185185        exportable="true"
    186186        formatter="<%=dateFormatter%>"
     187      />
     188      <tbl:columndef
     189        id="verified"
     190        property="verified"
     191        datatype="boolean"
     192        title="Is verified"
     193        sortable="true"
     194        filterable="true"
     195        exportable="true"
    187196      />
    188197      <tbl:columndef
     
    413422                <tbl:cell column="userAgent"><%=HTML.encodeTags(item.getUserAgent())%></tbl:cell>
    414423                <tbl:cell column="entryDate" value="<%=item.getEntryDate()%>" />
     424                <tbl:cell column="verified" value="<%=item.isVerified() ? "Yes" : "No"%>" />
    415425                <tbl:cell column="lastUsed" value="<%=item.getLastUsed()%>" />
    416426                <tbl:cell column="lastRemoteId"><%=HTML.encodeTags(item.getLastRemoteId())%></tbl:cell>
  • trunk/www/views/devices/view_device.jsp

    r7604 r7816  
    157157      </tr>
    158158      <tr>
     159        <th>Verified</th>
     160        <td><%=device.isVerified() ? "Yes" : "No"%></td>
     161      </tr>
     162      <tr>
    159163        <th>Registered</th>
    160164        <td><%=dateFormatter.format(device.getEntryDate())%></td>
Note: See TracChangeset for help on using the changeset viewer.