Ejemplo n.º 1
0
        public ActionResult VerifyUsers(int a, int b)
        {
            if (checkParams(a, b))
            {
                IEnumerable <User> users = _usersRepository.GetAllUsers();
                foreach (User user in users)
                {
                    if (user.ProfileExpires.HasValue)
                    {
                        if (user.ProfileExpires.Value.CompareTo(DateTime.Now) <= 0)
                        {
                            user.Profile = _profilesRepository.GetBasicProfile();
                            IEnumerable <Announcement> removeAnnouncements = user.Apartments.OrderByDescending(an => an.Created).Skip(user.Profile.MaxAnnouncements);
                            foreach (Announcement announcement in removeAnnouncements)
                            {
                                announcement.IsVisible = false;
                            }

                            foreach (Announcement announcement in user.Apartments)
                            {
                                if (announcement.Photos.Count > user.Profile.MaxPhotosPerAnnouncements)
                                {
                                    IEnumerable <Photo> removePhotos = announcement.Photos.OrderByDescending(p => p.Created).Skip(user.Profile.MaxPhotosPerAnnouncements);
                                    foreach (Photo photo in removePhotos)
                                    {
                                        photo.IsVisible = false;
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (user.ProfileExpires.Value.CompareTo(DateTime.Now.AddDays(-1 * daysToNotifyProfile)) <= 0)
                            {
                                string title = string.Format(Translation.Translation.EmailProfileWillBeExpiredTitle, daysToNotifyProfile);
                                string body  = string.Format(Translation.Translation.EmailProfileWillBeExpiredBody, daysToNotifyProfile, Url.Action("UpdateLimit", "Account", new { }, this.Request.Url.Scheme));
                                MailService.SendEmail(user.EmailAddress, title, body);
                            }
                        }
                    }
                }
                _usersRepository.SaveChanges();
            }

            return(new EmptyResult());
        }
Ejemplo n.º 2
0
        private User createUser(int userNumber, int announcementsPerUser)
        {
            User user = new User();

            user.Username         = userNumber.ToString();
            user.RoleName         = "User";
            user.RegisterDate     = DateTime.Now;
            user.Password         = userNumber.ToString();
            user.IsConfirmed      = true;
            user.EmailAddress     = userNumber.ToString() + "@aparts.in.ua";
            user.ConfirmationCode = Guid.NewGuid();
            user.Phone            = getUser(userNumber);
            user.Profile          = _profilesRepository.GetBasicProfile();


            for (int j = 0; j < announcementsPerUser; j++)
            {
                user.Apartments.Add(createAnnouncement(j, user));
            }

            return(user);
        }
Ejemplo n.º 3
0
        public ActionResult Register(RegisterViewModel model, ICollection <MobileNumber> mobileNumbers, string returnUrl)
        {
            string error;

            if (ModelState.IsValid)
            {
                if (model.IsValid(out error))
                {
                    //Get only numbers
                    string phone = StringHelper.GetOnlyNumbers(model.Phone);
                    if (phone.Length == 12)
                    {
                        if (_userRepository.GetUserByPhone(phone) == null)
                        {
                            User newUser = new User();
                            newUser.Username = model.UserName;
                            newUser.Phone    = phone;
                            newUser.Password = _passwordEncryptor.EncryptPassword(model.Password);
                            newUser.ReceiveNewAnnouncements = model.CanReceiveEmail;
                            newUser.EmailAddress            = model.Email;
                            newUser.RegisterDate            = DateTime.Now;
                            newUser.Role             = _rolesRepository.GetById("User");
                            newUser.ConfirmationCode = Guid.NewGuid();
                            newUser.Profile          = _profilesRepository.GetBasicProfile();
                            newUser.ProfileExpires   = null;

                            newUser.IsConfirmed = true;

                            _userRepository.Add(newUser);
                            _userRepository.SaveChanges();

                            if (mobileNumbers == null)
                            {
                                mobileNumbers = new List <MobileNumber>();
                            }
                            foreach (MobileNumber mobile in mobileNumbers)
                            {
                                mobile.UserId = newUser.UserID;
                                _mobileNumbersRepository.Add(mobile);
                            }
                            _mobileNumbersRepository.SaveChanges();

                            //sendConfirmEmail(newUser);
                            //return RedirectToAction("RegisterConfirm", new { userphone = newUser.Phone, confirmationCode = newUser.ConfirmationCode });

                            if (_authProvider.Authenticate(newUser) == AuthResult.Success)
                            {
                                return(RedirectToLocal(string.Empty));
                            }
                        }
                        else
                        {
                            error = Translation.Translation.RegisterPagePhoneNumberIsUsedAlready;
                        }
                    }
                    else
                    {
                        error = Translation.Translation.RegisterPageShortPhoneNumber;
                    }
                }
            }
            else
            {
                error = Translation.Translation.RegisterPageError;
            }
            ModelState.AddModelError("", error);
            ViewBag.MaxMobileNumbers = int.Parse(ConfigurationManager.AppSettings["MaxAdditionalMobileNumbers"]);
            return(View(model));
        }