public ActionResult Create(int? id, bool initial = false, bool copy = false)
        {
            LayoutViewModel.ActiveLink = Links.CreateChallenge;

            var membershipUser = Membership.GetUser();

            if (membershipUser != null && membershipUser.ProviderUserKey != null)
            {
                if (LayoutViewModel.IsCouncil)
                {

                    CreateChallengeViewModel viewModel;

                    if (id != null)
                    {
                        viewModel = GetCreateChallengeViewModelForUpdate(id.Value);

                        if (viewModel == null)
                        {
                            return RedirectToAction("Index", "ChallengesAdmin");
                        }
                        if (copy == false)
                        {
                            viewModel.IsUpdate = true;
                        }
                        else
                        {
                            viewModel.IsUpdate = false;
                        }

                        LayoutViewModel.ActiveLink = Links.Challenges;
                    }
                    else
                    {
                        viewModel = new CreateChallengeViewModel();

                        var partner = new UserService().GetUserById(LayoutViewModel.CurrentAccountId);
                        viewModel.Instance_Id = partner.Instance_Id;

                        //if (initial)
                        //{
                        //    LayoutViewModel.HideTopWrapperMenu = true;
                        //    viewModel.IsInitialRegistrationStep = true;
                        //}
                    }

                    ViewModelHelper.SetDefaultsForChallengeViewModel(viewModel, membershipUser);

                    return View(viewModel);
                }
                else
                    return RedirectToAction("Index", "Home");
            }
            else
                return RedirectToAction("Index", "Home");
        }
        public ActionResult AlterChallenges()
        {
            var config = WebConfigurationManager.OpenWebConfiguration("~");
            var section = config.SectionGroups["system.web"].Sections["membership"] as MembershipSection;
            var defaultProvider = section.DefaultProvider;
            var connectionStringName = section.Providers[defaultProvider].ElementInformation.Properties["connectionStringName"].Value.ToString();

            string connectionString = config.ConnectionStrings.ConnectionStrings[connectionStringName].ConnectionString;

            var deleted = new UserService().AlterChallenges(connectionString);

            return View();
        }
        public ActionResult CompleteProfile()
        {
            LayoutViewModel.ActiveLink = Links.SupplierUpdateProfile;

            LayoutViewModel.HideTopWrapperMenu = true;

            var userModel = new UserService().GetUserById(new Guid(LayoutViewModel.ProviderUserKey));

            CompleteSupplierProfileViewModel viewModel = new CompleteSupplierProfileViewModel
            {
                BusinessNumberABN = userModel.BusinessNumberABN,
                BusinessType = userModel.BusinessType,
                BussinesWebSite = userModel.BussinesWebSite
            };

            return View(viewModel);
        }
        //
        // GET: /Bussiness/
        public ActionResult Index()
        {
            var model = new BusinessHomeViewModel();

            var instances = new UserService().GetAllInstances();
            model.RegistrationSupplierViewModel = new RegistrationSupplierViewModel
            {
                Instances = new SelectList(instances, "Id", "Name")
            };

            model.LoginViewModel = new LoginViewModel();

            LayoutViewModel.IsAuthenticated = false;
            LayoutViewModel.HideTopWrapperMenu = true;
            LayoutViewModel.ActiveLink = Links.HomePage;

            return View(model);
        }
        public ActionResult CompleteProfile(CompleteSupplierProfileViewModel viewModel)
        {
            LayoutViewModel.ActiveLink = Links.SupplierUpdateProfile;

            LayoutViewModel.HideTopWrapperMenu = true;

            var userModel = new UserModel
            {
                Id = LayoutViewModel.CurrentAccountId,
                BusinessNumberABN = viewModel.BusinessNumberABN,
                BusinessType = viewModel.BusinessType,
                BussinesWebSite = viewModel.BussinesWebSite
            };

            var updated = new UserService().UpdateToCompleteSupplierUser(userModel);

            return RedirectToAction("CreateReward");
        }
        public ActionResult Index(UpdateSupplierProfileViewModel viewModel)
        {
            LayoutViewModel.ActiveLink = Links.SupplierUpdateProfile;

            var membershipUser = Membership.GetUser();

            if (ModelState.IsValid)
            {
                UserModel userModel = new UserModel
                {
                    Id = LayoutViewModel.CurrentAccountId,
                    FirstName = viewModel.FirstName,
                    LastName = viewModel.LastName,
                    PhotoID = viewModel.PhotoID,
                    BusinessName = viewModel.BusinessName,
                    BusinessNumberABN = viewModel.BusinessNumberABN,
                    BusinessType = viewModel.BusinessType,
                    BussinesEmail = viewModel.BussinesEmail,
                    BussinesLocation = viewModel.BussinesLocation,
                    BussinesPhone = viewModel.BussinesPhone,
                    BussinesPhoneArea = viewModel.BussinesPhoneArea,
                    BussinesPhoneMobile = viewModel.BussinesPhoneMobile,
                    BussinesWebSite = viewModel.BussinesWebSite,
                    EmailBussinesOnVoucherRedeem = viewModel.EmailBussinesOnVoucherRedeem,
                    SendEmailUpdates = viewModel.SendEmailUpdates
                };

                var success = true;

                // change password
                if (!string.IsNullOrEmpty(viewModel.OldPassword) || !string.IsNullOrEmpty(viewModel.NewPassword)
                    || !string.IsNullOrEmpty(viewModel.ConfirmNewPassword))
                {
                    if (string.IsNullOrEmpty(viewModel.OldPassword))
                    {
                        ModelState.AddModelError("OldPassword", "The Old password field is required.");
                        success = false;
                    }

                    if (string.IsNullOrEmpty(viewModel.NewPassword))
                    {
                        ModelState.AddModelError("NewPassword", "The New password field is required.");
                        success = false;
                    }

                    if (string.IsNullOrEmpty(viewModel.ConfirmNewPassword))
                    {
                        ModelState.AddModelError("ConfirmNewPassword", "The Confirm new password field is required.");
                        success = false;
                    }

                    if (success && viewModel.NewPassword != viewModel.ConfirmNewPassword)
                    {
                        ModelState.AddModelError("ConfirmNewPassword", "New password and confirmation password do not match.");
                        success = false;
                    }

                    if (success && !membershipUser.ChangePassword(viewModel.OldPassword, viewModel.NewPassword))
                    {
                        ModelState.AddModelError("OldPassword", "Old password is incorrect.");
                        success = false;
                    }
                }

                if (viewModel.Photo != null && viewModel.Photo.ContentLength > 0)
                {
                    MemoryStream target = new MemoryStream();
                    viewModel.Photo.InputStream.CopyTo(target);
                    byte[] data = target.ToArray();

                    UploadModel model = new UploadModel
                    {
                        ContentType = viewModel.Photo.ContentType,
                        Contents = data,
                        FileName = viewModel.Photo.FileName
                    };

                    UploadModel upload = new UploadService().UploadFile(membershipUser.ProviderUserKey.ToString(), model, true);

                }

                if (success)
                {
                    var updated = new UserService().UpdateSupplierUser(userModel);

                    // change username COMPLICATED
                    if (membershipUser.UserName != viewModel.BussinesEmail)
                    {

                        var config = WebConfigurationManager.OpenWebConfiguration("~");
                        var section = config.SectionGroups["system.web"].Sections["membership"] as MembershipSection;
                        var defaultProvider = section.DefaultProvider;
                        var connectionStringName = section.Providers[defaultProvider].ElementInformation.Properties["connectionStringName"].Value.ToString();

                        string connectionString = config.ConnectionStrings.ConnectionStrings[connectionStringName].ConnectionString;

                        var changed = new ProfileService().ChangeUsername(membershipUser.UserName, viewModel.BussinesEmail, connectionString);

                        if (changed)
                        {
                            // change email as well
                            membershipUser.Email = viewModel.BussinesEmail;

                            // need to re-verify
                            membershipUser.IsApproved = false;
                            //SendVerifyEmail(membershipUser, user, false);
                            //instead I'm showing verifucation code in the view

                            Membership.UpdateUser(membershipUser);

                            // need to sign out to force verification
                            FormsAuthentication.SignOut();

                            TempData["VerifyCode"] = ZBase32.Encode(LayoutViewModel.CurrentAccountId.ToByteArray());

                            // redirect to screen which tells user to check email
                            return RedirectToAction("EmailChangeSuccess", "Account");
                        }
                        else
                        {
                            ModelState.AddModelError("", "A user for that email address already exists. Please enter a different email address.");
                        }
                    }

                    return RedirectToAction("Dashboard");
                }

                return View(viewModel);
            }

            return View(viewModel);
        }
        public ActionResult UpdateAuspost()
        {
            LayoutViewModel.ActiveLink = Links.AccountUpdateProfile;

            var profileModel = new ProfileService().GetMyProfile(LayoutViewModel.ProviderUserKey,
                LayoutViewModel.CurrentUserEmail, 1);

            UpdateProfileAuspostViewModel viewModelCompany = new UpdateProfileAuspostViewModel
            {
                FirstName = profileModel.User.FirstName,
                LastName = profileModel.User.LastName,
                PhoneNumber = profileModel.User.PhoneNumber,
                Sex = profileModel.User.Sex,
                Email = LayoutViewModel.CurrentUserEmail,
                CompanyEmail = LayoutViewModel.CurrentUserEmail.Split('@')[0],
                CompanyEmailDomain = string.Format("@{0}", LayoutViewModel.CurrentUserEmail.Split('@')[1]),
                PhotoId = profileModel.User.PhotoID,
                Address = ViewModelHelper.GetUserAddress(profileModel.Address),
                SupportEmail = ConfigurationManager.AppSettings["SupportEmail"],
                PushNotifications = profileModel.User.PushNotifications
            };

            //Private company - auspost
            viewModelCompany.EmploymentType = profileModel.User.EmploymentType;

            if (profileModel.User.DateOfBirth.HasValue)
            {
                DateTime date = profileModel.User.DateOfBirth.Value;
                viewModelCompany.DateOfBirthDay = date.Day;
                viewModelCompany.DateOfBirthMonth = date.Month;
                viewModelCompany.DateOfBirthYear = date.Year;
            }

            var streetTypes = new UserService().GetAllStreetTypes((int)LayoutViewModel.Instance_Id);
            var streetNames = new UserService().GetAllStreetNames((int)LayoutViewModel.Instance_Id);
            var suburbs = new UserService().GetAllSuburbs((int)LayoutViewModel.Instance_Id);
            var states = new UserService().GetAllStates((int)LayoutViewModel.Instance_Id);

            viewModelCompany.StreetTypes = new SelectList(streetTypes);
            viewModelCompany.StreetNames = new SelectList(streetNames);
            viewModelCompany.Subrps = new SelectList(suburbs);
            viewModelCompany.States = new SelectList(states);

            viewModelCompany.StreetType = profileModel.Address.StreetType;
            viewModelCompany.StreetName = profileModel.Address.StreetName;
            viewModelCompany.Subrp = profileModel.Address.Suburb;
            viewModelCompany.State = profileModel.Address.State;

            return View("UpdateProfileAuspost", viewModelCompany);
        }
        public ActionResult AddHouseholdMembers(List<HouseholdMemberModel> householdMembers)
        {
            ViewData["competed"] = true;

            string tempUrl = string.Empty;
            foreach (var member in householdMembers.Where(m => !string.IsNullOrEmpty(m.Email)))
            {
                // create invite additional members url
                var url = Url.Action("RegisterHouseholdMembers", "Account", new
                {
                    emailaddress = member.Email,
                    inviter = member.InviterName,
                    addressid = member.AddressId,
                    firstname = member.FirstName,
                    lastname = member.LastName
                }, Request.Url.Scheme);

                tempUrl = string.Format("{0} ... {1}", tempUrl, url);

                // Give them the Invite Member Bonus
                int numBonusPoints = Convert.ToInt16(ConfigurationManager.AppSettings["BonusPoints.InviteMember.Points"]);
                string descBonusPoints = Convert.ToString(ConfigurationManager.AppSettings["BonusPoints.InviteMember.Description"]);
                int? transactionTypeId = Convert.ToInt16(ConfigurationManager.AppSettings["TransactionType.ShareHeart"]);

                // email content
                if (User.Identity.IsAuthenticated)
                {
                    var membership = Membership.GetUser();
                    if (membership != null)
                    {
                        var userModel = new InviteUserModel
                        {
                            Email = member.Email,
                            FirstName = member.FirstName,
                            LastName = member.LastName,
                            User_Id = new Guid(member.InviterId)
                        };

                        InviteUserModel invited = new UserService().InviteHouseholdMembers(userModel, numBonusPoints, descBonusPoints, transactionTypeId);

                        //Send email to invite members to register
                        EmailService.SendEmailAdditionalMemberInvitation(member.Email, member.InviterName, url);
                    }

                    //return RedirectToAction("InviteFriends", new {urltemp = tempUrl}); TODO later
                    return RedirectToAction("MyProfile", "Account");
                }
            }

            //return RedirectToAction("InviteFriends");
            return RedirectToAction("MyProfile", "Account");
        }
        public ActionResult RegisterHouseholdMembers(HouseholdMemberModel householdMemberModel)
        {
            AddressModel address = new UserService().GetAddressById(householdMemberModel.AddressId);

            //Don't allow duplicate user
            var tryToFindUser = Membership.GetUserNameByEmail(householdMemberModel.Email);
            if (string.IsNullOrEmpty(tryToFindUser))
            {

                var id = Guid.NewGuid();

                Boolean isFBUser = false;
                Boolean isApproved = true;
                Int32 FBUserId = 0;

                // create the ASP membership user
                MembershipCreateStatus status;
                var membershipUser = Membership.CreateUser(username: householdMemberModel.Email, password: householdMemberModel.Password, email: householdMemberModel.Email,
                    passwordQuestion: null, passwordAnswer: null,
                    isApproved: isApproved, providerUserKey: id,
                    status: out status
                );

                // Check inviter user role and the same role for invited user
                var addressHolderUserEmail = new UserService().GetUserNameHolderForAddress(householdMemberModel.AddressId);
                if (!string.IsNullOrWhiteSpace(addressHolderUserEmail))
                {
                    if (Roles.IsUserInRole(addressHolderUserEmail, "Supplier") && membershipUser != null)
                    {
                        Roles.AddUserToRole(membershipUser.Email, "Supplier");
                    }
                }

                if (status == MembershipCreateStatus.Success)
                {
                    // create the GM user
                    var user = new UserModel
                    {
                        Id = id,
                        FirstName = householdMemberModel.FirstName,
                        LastName = householdMemberModel.LastName,
                        AddressModel = address,
                        AddressId = address.Id,
                        Instance_Id = address.Instance_Id,
                        SendEmailOffers = householdMemberModel.SendEmailOffers,
                        SendEmailUpdates = householdMemberModel.SendEmailUpdates,
                        IsFBAccount = isFBUser,
                        FBUserId = FBUserId,
                        IsAdditionalAccountHolder = true
                    };

                    // Give them the New Member Bonus
                    int numBonusPoints = Convert.ToInt16(ConfigurationManager.AppSettings["BonusPoints.NewMember.Points"]);
                    string descBonusPoints = Convert.ToString(ConfigurationManager.AppSettings["BonusPoints.NewMember.Description"]);
                    int? transactionTypeId = Convert.ToInt16(ConfigurationManager.AppSettings["TransactionType.ShareHeart"]);

                    // store it
                    var newUser = new UserService().CreateUser(user, numBonusPoints, descBonusPoints, transactionTypeId);

                    int numBonusInvitationAcceptedPoints = Convert.ToInt16(ConfigurationManager.AppSettings["BonusPoints.InviteMember.Points"]);
                    string descInvitationAcceptedBonusPoints = Convert.ToString(ConfigurationManager.AppSettings["BonusPoints.InviteMember.Description"]);

                    bool addPoints = new UserService().InvitationAcceptedAddBonusPoints(addressHolderUserEmail,
                        numBonusInvitationAcceptedPoints, descInvitationAcceptedBonusPoints, transactionTypeId);

                    SendVerifyEmail(membershipUser.Email, user.FirstName, user.Id, true);

                    bool isProduction = Convert.ToBoolean(ConfigurationManager.AppSettings["MailChimp.ListId"]);

                    if (isProduction)
                    {
                        // Add them to the relevant MailChimp List
                        MailChimpManager mc = new MailChimpManager(ConfigurationManager.AppSettings["MailChimp.APIKey"]);
                        EmailParameter email = new EmailParameter()
                        {
                            Email = user.Email
                        };

                        EmailParameter results = mc.Subscribe(ConfigurationManager.AppSettings["MailChimp.ListId"], email);

                    }

                    return RedirectToAction("RegisterAccountSuccess");

                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(status));
                    return View(householdMemberModel);
                }
            }
            else
            {
                // email has already been registered in the system
                ModelState.AddModelError("", "User with the same email address has already been registered with GreenMoney.");
                return View(householdMemberModel);

            }
        }
Esempio n. 10
0
        public ActionResult RegisterAddress(string instid, string firstname, string lastname, string email, string sex, 
            string birthDate, string p, string code, bool sendme = false)
        {
            DateTime bdate;
            var hasBirthDate = DateTime.TryParse(birthDate, out bdate);

            var passDecrypted = "notused";//p is empty for fb login
            if (!string.IsNullOrWhiteSpace(p))
            {
                passDecrypted = Encryption.DecryptString(p);
            }

            var viewModel = new RegisterAccountViewModel();
            viewModel.InstanceId = !string.IsNullOrWhiteSpace(instid) ? int.Parse(instid) : 0; //new added field
            viewModel.FirstName = firstname;
            viewModel.LastName = lastname;
            viewModel.Email = email;
            viewModel.SendEmailOffers = sendme;
            viewModel.SendEmailUpdates = sendme;
            viewModel.sendme = sendme;
            //model.Sex = sex;
            viewModel.Password = passDecrypted;
            viewModel.Postcode = code;

            var privateClientId = ConfigurationManager.AppSettings["PrivateClientId"] == null
                ? 5
                : int.Parse(ConfigurationManager.AppSettings["PrivateClientId"]);

            var suburbs = new UserService().GetAllSuburbs(privateClientId, toExclude: true);
            var streetTypes = new UserService().GetAllStreetTypes(privateClientId, toExclude: true);
            viewModel.Suburbs = new SelectList(suburbs);
            viewModel.StreetTypes = new SelectList(streetTypes);

            viewModel.DateOfBirth = hasBirthDate ? bdate : DateTime.MinValue;

            //Display
            LayoutViewModel.HideTopWrapperMenu = true;

            return View(viewModel);
        }
Esempio n. 11
0
        public ActionResult ForgotPassword(ForgotPasswordViewModel model)
        {
            var membershipUser = Membership.GetUser(model.Email);

            if (membershipUser != null)
            {
                var user = new UserService().GetUserById((Guid)membershipUser.ProviderUserKey);

                // generate password
                const string chars = "ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789";

                var sb = new StringBuilder();
                var rand = new Random();
                for (var i = 0; i < 10; i++)
                    sb.Append(chars[rand.Next(chars.Length)]);

                var password = sb.ToString();

                // reset password
                var old = membershipUser.ResetPassword();
                membershipUser.ChangePassword(old, password);
                Membership.UpdateUser(membershipUser);

                // create login url
                var url = Url.Action("Login", "Account", null, Request.Url.Scheme);
                var emailContentPath = Server.MapPath("~/App_Data/Emails/reset-password.cshtml");
                EmailService.SendEmailResetPassword(emailContentPath, user, password, url, membershipUser);

                return RedirectToAction("ForgotPasswordSuccess");
            }
            else
            {
                ModelState.AddModelError("", "No user with that email exists.");
            }

            // something failed
            return View(model);
        }
Esempio n. 12
0
        public bool AdditionalUsersAjax(string email, string firstname, string lastname)
        {
            //TODO check model state etc.
            var currentUser = new UserService().GetUserById(new Guid(LayoutViewModel.ProviderUserKey));

            var isValid = !string.IsNullOrWhiteSpace(email) &&
                          !string.IsNullOrWhiteSpace(firstname) &&
                          !string.IsNullOrWhiteSpace(lastname);

            if (isValid)
            {

                // create invite additional members url
                var url = Url.Action("RegisterHouseholdMembers", "Account", new
                {
                    emailaddress = email,
                    inviter = currentUser.FirstName,
                    addressid = currentUser.AddressModel.Id,
                    firstname = firstname,
                    lastname = lastname
                }, Request.Url.Scheme);

                // email content

                var userModel = new InviteUserModel
                {
                    Email = email,
                    FirstName = firstname,
                    LastName = lastname,
                    User_Id = currentUser.Id
                };

                int numBonusPoints = Convert.ToInt16(ConfigurationManager.AppSettings["BonusPoints.InviteMember.Points"]);
                string descBonusPoints = Convert.ToString(ConfigurationManager.AppSettings["BonusPoints.InviteMember.Description"]);
                int? transactionTypeId = Convert.ToInt16(ConfigurationManager.AppSettings["TransactionType.ShareHeart"]);

                InviteUserModel invited = new UserService().InviteHouseholdMembers(userModel, numBonusPoints, descBonusPoints, transactionTypeId);

                //Send email to invite members to register
                EmailService.SendEmailAdditionalMemberInvitation(email, currentUser.FirstName, url);

                return true;
            }

            return false;
        }
Esempio n. 13
0
        public ActionResult AdditionalUsers(HouseholdMemberModel householdMemberModel)
        {
            LayoutViewModel.ActiveLink = Links.AccountAdditionalUsers;

            //TODO check model state etc.
            var currentUser = new UserService().GetUserById(new Guid(LayoutViewModel.ProviderUserKey));

            var isValid = !string.IsNullOrWhiteSpace(householdMemberModel.Email) &&
                          !string.IsNullOrWhiteSpace(householdMemberModel.ConfirmEmail) &&
                          !string.IsNullOrWhiteSpace(householdMemberModel.FirstName) &&
                          !string.IsNullOrWhiteSpace(householdMemberModel.LastName);

            if (isValid)
            {

                // create invite additional members url
                var url = Url.Action("RegisterHouseholdMembers", "Account", new
                {
                    emailaddress = householdMemberModel.Email,
                    inviter = currentUser.FirstName,
                    addressid = currentUser.AddressModel.Id,
                    firstname = householdMemberModel.FirstName,
                    lastname = householdMemberModel.LastName
                }, Request.Url.Scheme);

                // email content

                var userModel = new InviteUserModel
                {
                    Email = householdMemberModel.Email,
                    FirstName = householdMemberModel.FirstName,
                    LastName = householdMemberModel.LastName,
                    User_Id = currentUser.Id
                };

                // Give them the Invite Member Bonus
                int numBonusPoints = Convert.ToInt16(ConfigurationManager.AppSettings["BonusPoints.InviteMember.Points"]);
                string descBonusPoints = Convert.ToString(ConfigurationManager.AppSettings["BonusPoints.InviteMember.Description"]);
                int? transactionTypeId = Convert.ToInt16(ConfigurationManager.AppSettings["TransactionType.ShareHeart"]);

                InviteUserModel invited = new UserService().InviteHouseholdMembers(userModel, numBonusPoints, descBonusPoints, transactionTypeId);

                //Send email to invite members to register
                EmailService.SendEmailAdditionalMemberInvitation(householdMemberModel.Email, householdMemberModel.InviterName, url);

            }

            return RedirectToAction("AdditionalUsers");
        }
Esempio n. 14
0
        public ActionResult AdditionalUsers()
        {
            LayoutViewModel.ActiveLink = Links.AccountAdditionalUsers;

            AdditionalAccountsViewModel viewModel = new AdditionalAccountsViewModel();
            List<UserModel> list = new UserService().GetAdditionalAccounts(LayoutViewModel.ProviderUserKey);
            viewModel.AdditionalAccounts = list;

            List<UserModel> invitedUsers = new UserService().GetInvitedUsersAccounts(LayoutViewModel.ProviderUserKey);

            invitedUsers = invitedUsers.Where(x => !list.Select(l=>l.Email).Contains(x.Email)).ToList();

            viewModel.InvitedUsersAccounts = invitedUsers;

            var currentUser = new UserService().GetUserById(new Guid(LayoutViewModel.ProviderUserKey));

            viewModel.HouseholdMemberModel = new HouseholdMemberModel();

            return View(viewModel);
        }
Esempio n. 15
0
        private static void FillBaseViewModelData(UpdateProfileAuspostViewModel viewModel)
        {
            var privateClientId = ConfigurationManager.AppSettings["PrivateClientId"] == null
                ? 5
                : int.Parse(ConfigurationManager.AppSettings["PrivateClientId"]);

            var streetTypes = new UserService().GetAllStreetTypes(privateClientId);
            var streetNames = new UserService().GetAllStreetNames(privateClientId);
            var suburbs = new UserService().GetAllSuburbs(privateClientId);
            var states = new UserService().GetAllStates(privateClientId);

            viewModel.StreetTypes = new SelectList(streetTypes);
            viewModel.StreetNames = new SelectList(streetNames);
            viewModel.Subrps = new SelectList(suburbs);
            viewModel.States = new SelectList(states);

            //Something not valid, show errors
            viewModel.SupportEmail = ConfigurationManager.AppSettings["SupportEmail"];
        }
Esempio n. 16
0
        // GET: /Supplier/
        // Update profile
        public ActionResult Index()
        {
            LayoutViewModel.ActiveLink = Links.SupplierUpdateProfile;

            LayoutViewModel.ActiveLink = Links.AccountUpdateProfile;

            var userModel = new UserService().GetUserById(new Guid(LayoutViewModel.ProviderUserKey));

            bool isDefaultSupplierAddress;
            UpdateSupplierProfileViewModel viewModel = new UpdateSupplierProfileViewModel
            {
                FirstName = userModel.FirstName,
                LastName = userModel.LastName,
                PhotoID = userModel.PhotoID,
                BusinessName = userModel.BusinessName,
                BusinessNumberABN = userModel.BusinessNumberABN,
                BusinessType = userModel.BusinessType,
                BussinesEmail = LayoutViewModel.CurrentUserEmail,//userModel.BussinesEmail,
                BussinesLocation = userModel.BussinesLocation,
                BussinesPhone = userModel.BussinesPhone,
                BussinesPhoneArea = userModel.BussinesPhoneArea,
                BussinesWebSite = userModel.BussinesWebSite,
                BussinesPhoneMobile = userModel.BussinesPhoneMobile,
                EmailBussinesOnVoucherRedeem = userModel.EmailBussinesOnVoucherRedeem,
                SendEmailUpdates = userModel.SendEmailUpdates,
                Address = GetSupplierAddress(userModel.AddressModel, out isDefaultSupplierAddress),
                IsDefaultSupplierAddress = isDefaultSupplierAddress
            };

            return View(viewModel);
        }
Esempio n. 17
0
        public ActionResult RegisterAddress(RegisterAccountViewModel model)
        {
            if (ModelState.IsValid)
            {

                AddressModel addressModelFind = new AddressModel();

                // find new user's address
                AddressModel address = new UserService().FindMatchingAdressModel(
                    unitNumber: model.UnitNumber,
                    streetNumber: model.StreetNumber,
                    streetName: model.StreetName,
                    streetType: model.StreetType,
                    suburb: model.Suburb,
                    postcode: null
                    );

                //Address exists in database
                if (address != null)
                {
                    bool addressHasUsers = new UserService().CheckAddressHasUsersRegistered(
                        unitNumber: model.UnitNumber,
                        streetNumber: model.StreetNumber,
                        streetName: model.StreetName,
                        streetType: model.StreetType,
                        suburb: model.Suburb,
                        postcode: null
                        );

                    //This address still does not have registered users
                    if (!addressHasUsers)
                    {
                        var id = Guid.NewGuid();

                        Boolean isFBUser = false;
                        Boolean isApproved = false;
                        Int64 FBUserId = 0;

                        FacebookUserModel fbUser = null;
                        if (Session["FacebookUser"] != null)
                        {
                            fbUser = (FacebookUserModel)Session["FacebookUser"];
                        }

                        if (fbUser != null)
                        {
                            isFBUser = true;
                            isApproved = true;
                            FBUserId = Convert.ToInt64(fbUser.id);
                        }

                        // create the ASP membership user
                        MembershipCreateStatus status;

                        //Don't allow duplicate user
                        var tryToFindUser = Membership.GetUserNameByEmail(model.Email);
                        if (string.IsNullOrEmpty(tryToFindUser))
                        {
                            var membershipUser = Membership.CreateUser(username: model.Email, password: model.Password, email: model.Email,
                                passwordQuestion: null, passwordAnswer: null,
                                isApproved: isApproved, providerUserKey: id,
                                status: out status
                            );

                            if (status == MembershipCreateStatus.Success)
                            {
                                DateTime? saveDate = null;

                                if (model.DateOfBirthDay != null && model.DateOfBirthMonth != null && model.DateOfBirthYear != null)
                                {
                                    saveDate = new DateTime(year: (int)model.DateOfBirthYear.Value,
                                        month: (int)model.DateOfBirthMonth.Value,
                                        day: (int)model.DateOfBirthDay.Value);
                                }

                                // create the GM user
                                UserModel userModel = new UserModel();
                                userModel.Id = id;
                                userModel.FirstName = model.FirstName;
                                userModel.LastName = model.LastName;
                                userModel.AddressId = address.Id;
                                userModel.Instance_Id = address.Instance_Id;
                                userModel.SendEmailOffers = model.SendEmailOffers; //TODO check matching
                                userModel.SendEmailUpdates = model.SendEmailUpdates; //TODO check matching

                                userModel.IsFBAccount = isFBUser;
                                userModel.FBUserId = FBUserId;
                                userModel.IsAdditionalAccountHolder = false;
                                userModel.Sex = model.Sex;
                                userModel.DateOfBirth = saveDate;
                                userModel.PhoneNumber = model.PhoneNumber;

                                // Give them the New Member Bonus
                                int numBonusPoints = Convert.ToInt16(ConfigurationManager.AppSettings["BonusPoints.NewMember.Points"]);
                                string descBonusPoints = Convert.ToString(ConfigurationManager.AppSettings["BonusPoints.NewMember.Description"]);
                                int? transactionTypeId = Convert.ToInt16(ConfigurationManager.AppSettings["TransactionType.ShareHeart"]);

                                UserModel newUserModel = new UserService().CreateUser(userModel, numBonusPoints, descBonusPoints, transactionTypeId);

                                if (newUserModel != null)
                                {
                                    FormsAuthentication.SetAuthCookie(model.Email, createPersistentCookie: false);
                                }

                                if (!isApproved)
                                {
                                    SendVerifyEmail(membershipUser.Email, userModel.FirstName, userModel.Id, true);
                                    // THey are a normal user
                                    //TODO later - email sending before approve, not it is approved immediately
                                    //SendVerifyEmail(membershipUser, user, true);
                                    membershipUser.IsApproved = true;
                                    Membership.UpdateUser(membershipUser);

                                    //TODO later - checkout what is this
                                    //if (false)
                                    //{
                                    //    // Add them to the relevant MailChimp List
                                    //    MailChimpManager mc = new MailChimpManager(ConfigurationManager.AppSettings["MailChimp.APIKey"]);
                                    //    EmailParameter email = new EmailParameter()
                                    //    {
                                    //        Email = user.Email
                                    //    };

                                    //    EmailParameter results = mc.Subscribe(ConfigurationManager.AppSettings["MailChimp.ListId"], email);
                                    //}

                                }
                                else
                                {
                                    // They have just logged in with FB so Login as usual
                                    FormsAuthentication.SetAuthCookie(model.Email, createPersistentCookie: false);
                                }

                                // the next registration step
                                return RedirectToAction("AddHouseholdMembers", new { addressId = address.Id, inviter = model.Email, inviterId = id });

                            }
                            else
                            {
                                ModelState.AddModelError("", ErrorCodeToString(status));
                            }
                        }
                        else
                        {
                            // email has already been registered in the system
                            ModelState.AddModelError("", "User with the same email address has already been registered with GreenMoney.");
                        }
                    }
                    else
                    {
                        // address already has a user on it!
                        ModelState.AddModelError("", "Address has already been registered with GreenMoney.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Please contact us with your address details and we'll assist you in creating an account.");

                    TempData["ProblemWithAddress"] = true;
                }
            }

            var suburbs = new UserService().GetAllSuburbs();
            var streetTypes = new UserService().GetAllStreetTypes();

            model.Suburbs = new SelectList(suburbs);
            model.StreetTypes = new SelectList(streetTypes);

            //Display
            LayoutViewModel.HideTopWrapperMenu = true;

            // something failed, redisplay form
            return View(model);
        }
Esempio n. 18
0
        public ActionResult RegisterSupplier(RegistrationSupplierViewModel registrationSupplierViewModel)
        {
            if (ModelState.IsValid)
            {

                //Don't allow duplicate user
                var tryToFindUser = Membership.GetUserNameByEmail(registrationSupplierViewModel.BusinessEmail);
                if (string.IsNullOrEmpty(tryToFindUser))
                {

                    // Create the ASP membership user
                    var id = Guid.NewGuid();
                    MembershipCreateStatus status;

                    var membershipUser = Membership.CreateUser(username: registrationSupplierViewModel.BusinessEmail,
                        password: registrationSupplierViewModel.Password, email: registrationSupplierViewModel.BusinessEmail,
                        passwordQuestion: null, passwordAnswer: null,
                        isApproved: true, providerUserKey: id,
                        status: out status
                    );

                    if (status == MembershipCreateStatus.Success)
                    {

                        // Create the GM user for supplier with default address (temp id= 258440)
                        UserModel userModel = new UserModel();
                        userModel.Id = id;
                        userModel.Instance_Id = registrationSupplierViewModel.InstanceId;
                        userModel.BusinessName = registrationSupplierViewModel.BusinessName;

                        // TODO - think about logic Email vs. BusinessEmail
                        userModel.BussinesEmail = registrationSupplierViewModel.BusinessEmail;
                        userModel.Email = registrationSupplierViewModel.BusinessEmail;

                        userModel.BussinesPhoneArea = registrationSupplierViewModel.BussinesPhoneArea;
                        userModel.BussinesPhone = registrationSupplierViewModel.BusinessPhone;
                        userModel.FirstName = registrationSupplierViewModel.FirstName;
                        userModel.LastName = registrationSupplierViewModel.LastName;

                        userModel.AddressId = int.Parse(ConfigurationManager.AppSettings["DefaultSupplierAddressId"]);
                        //TODO this should be bigint actually? add error logging
                        userModel.IsAdditionalAccountHolder = false;

                        // Give them the New Member Bonus
                        int numBonusPoints = Convert.ToInt16(ConfigurationManager.AppSettings["BonusPoints.NewMember.Points"]);
                        string descBonusPoints = Convert.ToString(ConfigurationManager.AppSettings["BonusPoints.NewMember.Description"]);
                        int? transactionTypeId = Convert.ToInt16(ConfigurationManager.AppSettings["TransactionType.ShareHeart"]);

                        UserModel newUserModel = new UserService().CreateSupplierUser(userModel, numBonusPoints, descBonusPoints, transactionTypeId);

                        if (newUserModel != null)
                        {
                            if (!Roles.IsUserInRole(membershipUser.Email, "Supplier"))
                            {
                                Roles.AddUserToRole(membershipUser.Email, "Supplier");
                            }
                            FormsAuthentication.SetAuthCookie(registrationSupplierViewModel.BusinessEmail, createPersistentCookie: false);
                        }
                    }

                    return RedirectToAction("CompleteProfile", "Supplier");
                }
                else
                {
                    return RedirectToAction("Index", "Business");
                }
            }
            else // something failed, redisplay form
            {
                BusinessHomeViewModel viewModel = new BusinessHomeViewModel();
                viewModel.SupplierRegistrationIsNotValid = true;

                var instances = new UserService().GetAllInstances();
                registrationSupplierViewModel.Instances = new SelectList(instances, "Id", "Name");
                viewModel.RegistrationSupplierViewModel = registrationSupplierViewModel;

                LayoutViewModel.IsAuthenticated = false;
                LayoutViewModel.HideTopWrapperMenu = true;

                return View("Index", viewModel);
            }
        }
Esempio n. 19
0
        public ActionResult RegisterHouseholdMembers(string emailaddress, string inviter, string addressid, string firstname, string lastname)
        {
            var addressIdInt = Int32.Parse(addressid);

            bool inviterUserFound = new UserService().FoundOriginalUserForAddressById(addressIdInt);

            if (inviterUserFound)
            {
                var model = new HouseholdMemberModel
                {
                    Email = emailaddress,
                    ConfirmEmail = emailaddress, //hidden on form
                    FirstName = firstname,
                    LastName = lastname,
                    AddressId = addressIdInt
                };

                return View(model);
            }

            return RedirectToAction("Index", "Home");
        }