예제 #1
0
        public string GetShareBodyText(Team team, EventWave eventWave, User user, EventDate eventDate,
                              bool includeJavascriptLineBreaks)
        {
            if (team == null || user == null || eventDate == null)
                return string.Empty;

            var filePath = HostingEnvironment.MapPath(string.Format("~/{0}/{1}", DirtyGirlServiceConfig.Settings.EmailTemplatePath,
                                                      DirtyGirlServiceConfig.Settings.TeamInviteBody)) ?? "";
            var bodyText =
                System.IO.File.ReadAllText(filePath)
                      .Replace("{RegistrantName}",
                               string.Format("{0} {1}", user.FirstName, user.LastName))
                      .Replace("{EventID}", team.Event.EventId.ToString())
                      .Replace("{RaceLocation}", team.Event.GeneralLocality)
                      .Replace("{DayOfWeek}", eventDate.DateOfEvent.ToString("dddd"))
                      .Replace("{Month}", eventDate.DateOfEvent.ToString("MMMM"))
                      .Replace("{Day}", eventDate.DateOfEvent.ToString("dd"))
                      .Replace("{Year}", eventDate.DateOfEvent.ToString("yyyy"))
                      .Replace("{WaveNumber}", eventWave.EventWaveId.ToString())
                      .Replace("{BeginTime}", eventWave.StartTime.ToString("hh:mm tt"))
                      .Replace("{EndTime}", eventWave.EndTime.ToString("hh:mm tt"))
                      .Replace("{TeamCode}", team.Code)
                      .Replace("{LineBreak}", (includeJavascriptLineBreaks ? "\\" : ""));
            return bodyText;
        }
예제 #2
0
        public ServiceResult CreateUser(User u)
        {
            var result = new ServiceResult();
            try
            {
                if (ValidateUser(u, result))
                {

                    //Non-Facebook Users
                    if (u.FacebookId == null)
                    {
                        var chc = Crypto.CreateHash(u.Password);
                        u.Password = chc.hash;
                        u.Salt = chc.salt;
                        u.EmailVerificationCode = DirtyGirlServiceConfig.Settings.UsersMustConfirmEmail ? GenerationEmailConfirmationCode() : null;

                    }

                    //If a user is created with both image data and "User Facebook Image" selected, the uploaded image will be used instead.
                    if (u.Image != null) { u.UseFacebookImage = false; }

                    u.IsActive = true;
                    u.UserName = u.UserName.Trim();

                    _repository.Users.Create(u);

                    u.Roles = new List<Role>();
                    u.Roles.Add(_repository.Roles.Find(x => x.Name == "Registrant"));

                    if (result.Success)
                    {
                        _repository.SaveChanges();
                        SendEmailConfirmation(u.UserId);
                    }

                }
            }
            catch (Exception ex)
            { result.AddServiceError(Utilities.GetInnerMostException(ex)); }
            return result;
        }
예제 #3
0
 public vmUser_EditUser(User u)
 {
     User = u;
 }
예제 #4
0
 public vmUser_EditUser()
 {
     User = new User();
 }
예제 #5
0
 private static void SendPasswordResetForGoLiveEmail(User user)
 {
     IEmailService emailService = new EmailService();
     emailService.SendPasswordResetForGoLiveEmail(user.UserId);
 }
예제 #6
0
        private ServiceResult GeneratePasswordResetRequest(User user)
        {
            if (user == null) throw new ArgumentNullException("user");
            // Get user object
            var result = new ServiceResult();
            try
            {
                // check for existing Reset Token
                if (user.PasswordResetToken != null &&
                    DateTime.Compare(
                        (user.PasswordResetRequested.HasValue
                             ? user.PasswordResetRequested.Value
                             : new DateTime(1900, 1, 1)),
                        DateTime.Now.AddHours(DirtyGirlServiceConfig.Settings.RequestValidForHours * -1)) > 0)
                {
                    SendPasswordResetEmail(user);
                }
                else
                {
                    var byteArray = new byte[128];
                    // Create new Cryptography object
                    using (var crypto = new RNGCryptoServiceProvider())
                    {
                        crypto.GetNonZeroBytes(byteArray);

                        user.PasswordResetToken = Convert.ToBase64String(byteArray);
                        user.PasswordResetToken = user.PasswordResetToken.Replace("+", "");
                        user.PasswordResetRequested = DateTime.Now;
                        _repository.SaveChanges();

                        SendPasswordResetEmail(user);
                    }
                }
            }
            catch (Exception ex)
            {
                result.AddServiceError(Utilities.GetInnerMostException(ex));
            }
            return result;
        }
예제 #7
0
        protected bool ValidateUser(User userToValidate, ServiceResult serviceResult)
        {
            //Users tied to a FB account will not have a password
            //When updating users, a password will not be included, thus the UserId condition
            if (userToValidate.UserId <= 0 && String.IsNullOrEmpty(userToValidate.Password) && userToValidate.FacebookId == null)
            {
                serviceResult.AddServiceError("Password", "A password is required");
            }
            if (_repository.Users.Filter(user => user.UserName.Trim().ToLower().Equals(userToValidate.UserName.Trim().ToLower()) && !user.UserId.Equals(userToValidate.UserId)).Count() > 0)
            {
                serviceResult.AddServiceError("UserName", "A user with this username already exists.");
            }
            if (_repository.Users.Filter(user => user.EmailAddress.Equals(userToValidate.EmailAddress) && !user.UserId.Equals(userToValidate.UserId)).Count() > 0)
            {
                serviceResult.AddServiceError("EmailAddress", "This email is already in use by another user.");
            }
            //TODO: Swear filter username

            if (userToValidate.Image != null)
            {
                userToValidate.Image = Utilities.ResizeImage(userToValidate.Image, 180, 180);
            }

            return serviceResult.Success;
        }
예제 #8
0
        public ServiceResult UpdateUser(User u, bool setIsActive)
        {
            var result = new ServiceResult();
            try
            {
                if (ValidateUser(u, result))
                {

                    var updateUser = GetUserById(u.UserId);
                    updateUser.UserName = u.UserName.Trim();
                    updateUser.FirstName = u.FirstName;
                    updateUser.LastName = u.LastName;
                    updateUser.Address1 = u.Address1;
                    updateUser.Address2 = u.Address2;
                    updateUser.Locality = u.Locality;
                    updateUser.RegionId = u.RegionId;
                    updateUser.PostalCode = u.PostalCode;
                    updateUser.EmailAddress = u.EmailAddress;

                    if (setIsActive)
                    {
                        updateUser.IsActive = u.IsActive;
                    }

                    //if uploading a new imagine but also selected "use facebook image", use uploaded photo instead
                    if (u.Image != null)
                    {
                        updateUser.Image = u.Image;
                        u.UseFacebookImage = false;
                    }

                    updateUser.UseFacebookImage = u.UseFacebookImage;

                    //Clear out their uploaded image if they opt to use their FB image
                    if (u.UseFacebookImage) { updateUser.Image = null; }

                    _repository.Users.Update(updateUser);

                    if (result.Success)
                    {
                        _repository.SaveChanges();
                        _repository.Users.LoadProperties(updateUser);
                    }
                }
            }
            catch (Exception ex)
            {
                result.AddServiceError(Utilities.GetInnerMostException(ex));
            }

            return result;
        }
예제 #9
0
        public bool SendEmailConfirmation(User user)
        {
            try
            {
                if (user.EmailVerificationCode == null)
                {
                    // Auto-Activate user.  Ability to have email validation exists in the app and to enable it
                    // Uncomment the following line and then change the Email Confirmation Template.
                    user.EmailVerificationCode = DirtyGirlServiceConfig.Settings.UsersMustConfirmEmail ? GenerationEmailConfirmationCode() : null;
                    _repository.SaveChanges();
                }

                IEmailService emailService = new EmailService();
                emailService.SendRegistrationConfirmationEmail(user.UserId);

                return true;
            }
            catch
            {
                return false;
            }
        }
예제 #10
0
 public ServiceResult RemoveUser(User u)
 {
     throw new NotImplementedException();
 }
예제 #11
0
        public ServiceResult GeneratePasswordResetRequestForGoLive(User user)
        {
            if (user == null) throw new ArgumentNullException("user");
            // Get user object
            var result = new ServiceResult();
            try
            {

                var byteArray = new byte[128];
                // Create new Cryptography object
                using (var crypto = new RNGCryptoServiceProvider())
                {
                    crypto.GetNonZeroBytes(byteArray);

                    user.PasswordResetToken = Convert.ToBase64String(byteArray);
                    user.PasswordResetToken = user.PasswordResetToken.Replace("+", "");
                    user.PasswordResetRequested = DateTime.Now.AddDays(10);
                    _repository.SaveChanges();

                    SendPasswordResetForGoLiveEmail(user);
                }

            }
            catch (Exception ex)
            {
                result.AddServiceError(Utilities.GetInnerMostException(ex));
            }
            return result;
        }