示例#1
0
        public ActionResult Create(UserCreateViewModel profile)
        {
            if (ModelState.IsValid)
            {
                var profileToCreate = new UserCreateDto {Email = profile.Email, Password = profile.Password, Username = profile.Username};

                foreach (InterestCreate interest in profile.UserInterests)
                {
                    var userInterest = new UserAddInterestDto(interest.Id, interest.Name, interest.CategoryId);
                    profileToCreate.InterestDtos.Add(userInterest);
                }

                var locationData = GetLocationData();

                User user = _userTasks.Create(profileToCreate, locationData);

                _userTasks.Login(user, false);

                return RedirectToAction("ThankYou");
            }

            //TODO: Implement PRG pattern for post forms
            return View(profile);
        }
示例#2
0
        public User Create(UserCreateDto userToCreate, LocationData location)
        {
            string salt = PasswordHelper.GenerateSalt(16); //TODO: should this be 32 - encapsulate this somehwere
            string pHash = PasswordHelper.GetPasswordHash(userToCreate.Password, salt);

            var user = new User(userToCreate.Username, userToCreate.Email, pHash, salt)
            {
                CreateDate = DateTime.UtcNow
            };

            MajorLocation majorLocation = _locationService.GetNearestMajorCity(location.Latitude, location.Longitude);

            user.UpdateBio("I ♥ " + string.Join(", ", user.Interests.Select(x => x.Interest.Name)));
            user.UpdateHeadline("I am " + user.Username + ", hear me roar!");
            user.UpdateLocation(location, majorLocation);

            user.UpdateCreateDate();

            _userRepository.SaveOrUpdate(user);

            ProcessUserInterests(user, userToCreate.InterestDtos);

            return user;
        }