Last active
December 13, 2015 21:48
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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