public static void SignIn(ApplicationUserManager manager, AppUser user, bool isPersistent)
 {
     IAuthenticationManager authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
     authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
     var identity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
     authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
 }
        private string ValidateUser(AppUser user)
        {
            if (user.FirstName.Length < ModelConstants.UserFirstNameMinLength ||
                user.LastName.Length < ModelConstants.UserLastNameMinLength)
            {
                return SiteConstants.ErrorFieldMinLength;
            }

            if (user.FirstName.Length > ModelConstants.UserFirstNameMaxLength ||
                 user.LastName.Length > ModelConstants.UserLastNameMaxLength)
            {
                return SiteConstants.ErrorFieldMaxLength;
            }

            if (!new Regex(SiteConstants.EmailRegex).IsMatch(user.Email))
            {
                return SiteConstants.WrongEmailAddress;
            }

            return null;
        }