Activity: Adding a EULA Agreement

Scenario

You want to add an end user license agreement (EULA) to prevent user to register without checking it.

Aim

Add an end-user license agreement to the application

Steps for completion

  1. Modify NewUserViewModel, as follows:
using RestBuy.Entities;
using System.ComponentModel.DataAnnotations;
namespace RestBuy.Application.ViewModels
{
...
public bool TermsAndConditions { get; set; }
internal User CreateUser() =>
new User(this.Username, this.Password);
}
}

Note that we have added a TermsAndConditions validator with a range validator that can only be true.

  1. Then modify the registration page as follows:

Go to https://goo.gl/uUxNau to access the code.
@model RestBuy.Application.ViewModels.NewUserViewModel
@{
ViewBag.Title = "Register";
}
<h1>Register</h1>
...
...
<input class="btn btn-primary" type="submit" value="Register" />
</div>
</form>
  1. To the bottom of the _ValidationScriptsPartial file, add the following:

Go to https://goo.gl/P6GBey to access the code.
<script>
// extend jquery range validator to work for required checkboxes
var defaultRangeValidator = $.validator.methods.range;
$.validator.methods.range = function (value, element, param)
{
if (element.type === 'checkbox')
{
// if it's a checkbox return true if it is checked
return element.checked;
}
else
{
// otherwise run the default validation function
return defaultRangeValidator.call(this, value, element, param);
}
}
</script>

Now our form looks as follows: