Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For validating the uniqueness of the <code>userName</code> and <code>company</code>, I believe the problem is that on editing the <code>User</code>, the validator function finds the userName / company in the Database because it is the record you inserted beforehand. So you will need to check if the userName / company exists and if it does exist, check if the id of the row is the id of the user. If they are the same, return true because it has only found the record you're currently updating.</p> <p>With the id of the <code>User</code>, it's best to handle this in the <code>Action</code> and not the form binding due to security implications. E.g if the id is set and submitted in the form, it would be easy for someone to change the value of the id input to the id of another User to change their details. This is similar to how GitHub got compromised last year <a href="http://www.infoq.com/news/2012/03/GitHub-Compromised" rel="nofollow">http://www.infoq.com/news/2012/03/GitHub-Compromised</a> </p> <p>In terms of a rough code snippet, something along the lines of:</p> <pre><code>def update(userId: Long) = Action { implicit request =&gt; val user = User.find(userId) // Some type of authorization if(!authorize(getCurrentUser(), user) { BadRequest("access denied") } else { UserFormWithMappings.bindFromRequest().fold( formWithErrors =&gt; Ok("form errors"), updatedUser =&gt; { updatedUser.id = userId User.update(updatedUser) // insert into db Ok("User changes saved") } ) } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload