Skip to content

Instantly share code, notes, and snippets.

@Lucasus
Last active December 13, 2015 21:48
Show Gist options
  • Save Lucasus/4979427 to your computer and use it in GitHub Desktop.
Save Lucasus/4979427 to your computer and use it in GitHub Desktop.
This example shows how to decorate method with LucValidation validation attributes and rules.
[ValidateArguments]
public virtual void RegisterUser([Required, UserName]string userName, [Required, Email]string email, [Required, Password]string password, [Required, Password]string rePassword)
{
if (CheckAllRules(new PasswordsAreSame() { Password = password, RePassword = rePassword},
new UserNameUnique() { UserName = userName },
new EmailUnique() { Email = email }))
{
User newUser = new User()
{
UserName = userName,
Email = email,
HashedPassword = new HashProvider().GetPasswordHash(password),
CreateDate = DateTime.Now,
IsApproved = false,
AuthorizationKey = Guid.NewGuid(),
Roles = new List<Role>()
};
newUser.Roles.Add(roleQueries.GetByName(RoleNames.User));
Session.SaveOrUpdate(newUser);
var emailSent = new EmailSender().SendActivationEmail(newUser.UserName, newUser.Email, newUser.AuthorizationKey);
if (emailSent == false)
{
ValidationResult.AddError(ValidationKeys.Email, ValidationMessages.EmailInvalid);
Session.Transaction.Rollback();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment