public ActionResult Connect()
        {
            var callbackUrl = Request.Url + "CallBack";

            Session["MailChimpcallbackUrl"] = callbackUrl;
            _configuration.Add("redirect_uri", callbackUrl);
            var mailChimpHelper = new MailChimpHelper(_configuration);

            return(Redirect(mailChimpHelper.getLoginURL()));
        }
        public void AddUpdateEmailAndTags(string emailAddress, string tagsCsv)
        {
            var tagList = tagsCsv.Split(',').ToList();
            //var returnObj = MailChimpHelper.GenerateUrl(uriSegment, queryString);
            var returnObj = MailChimpHelper.AddUpdateEmailAddress(ListID, new FrameworkLibrary.User()
            {
                EmailAddress = emailAddress
            }, null, tagList);

            WriteObjectAsJSON(returnObj);
        }
Beispiel #3
0
        protected void UpdateCMSAdminLogin_Click(object sender, EventArgs e)
        {
            var returnObj = new Return();

            if (CMSEmailAddress.Text == "" || CMSPassword.Text == "")
            {
                Messages.Text = "Please make sure to enter a valid 'Email Address' and 'Password'";
            }
            else
            {
                var admin = UsersMapper.GetByUserName("admin");
                if (admin == null)
                {
                    returnObj.Error = new Elmah.Error()
                    {
                        Message = "Cannot find user with username: '******'"
                    };
                }
                else
                {
                    admin.EmailAddress = CMSEmailAddress.Text;
                    admin.FirstName    = FirstName.Text;
                    admin.LastName     = LastName.Text;
                    admin.Password     = StringHelper.Encrypt(CMSPassword.Text.Trim());

                    returnObj = UsersMapper.Update(admin);
                }

                if (returnObj.IsError)
                {
                    Messages.Text = returnObj.Error.Message + "" + returnObj.Error.Exception.InnerException + "<br />";
                }
                else
                {
                    DisableInstallerPanel.Visible = true;
                    Messages.Text = "Successfully updated CMS Admin Login Credentials";

                    MailChimpHelper mailChimpHelper = new MailChimpHelper("f23d1a1ec667a40691014801ed84f096-us15");

                    mailChimpHelper.AddUserToFlexDotNetCMSInstallerList(admin);
                }
            }

            ExecutePanel.Visible = true;
        }
Beispiel #4
0
 private bool MailChimp(User user, BackupDataHelper backupDataHelper)
 {
     try
     {
         OnAccountStart(new BackupEventArgs(AccountEnum.MailChimp.ToString()));
         var members = MailChimpHelper.GetAllMembers(user.MailChimpAccount.ApiKey);
         backupDataHelper.Add("MailChimp.csv", members);
         OnAccountComplete(new BackupEventArgs(AccountEnum.MailChimp.ToString()));
         return(true);
     }
     catch (Exception ex)
     {
         OnShowError(new BackupEventArgs(AccountEnum.MailChimp.ToString()));
         logger.Error("Problems with MailChimp", ex);
         _unitOfWork.MailChimpRepository.Delete(user.Id);
         _unitOfWork.Commit();
         return(false);
     }
 }
 public ActionResult ConnectCallBack(string code)
 {
     try
     {
         if (String.IsNullOrEmpty(code))
         {
             throw new Exception();
         }
         var callbackUrl = (string)Session["MailChimpcallbackUrl"];
         _configuration.Add("redirect_uri", callbackUrl);
         _configuration.Add("code", code);
         var mailChimpHelper = new MailChimpHelper(_configuration);
         CurrentUser.MailChimpAccount = mailChimpHelper.GetMailChimpAccount();
         UnitOfWork.Commit();
     }
     catch
     {
         ModelState.AddModelError("", "Can't connect to MailChimp.");
     }
     return(RedirectToAction <UserController>(c => c.Index()));
 }
 public void DeleteUnUsedTags()
 {
     //var returnObj = MailChimpHelper.GenerateUrl(uriSegment, queryString);
     MailChimpHelper.DeleteUnUsedTags(ListID);
 }
        public ActionResult UserProfile(vmAccountUserProfile model)
        {
            //security validation (only allow site admin or user to edit their own profile)
            if ((!User.IsInRole("Admins")) && (model.UserIDX != db_Accounts.GetUserIDX()))
            {
                return(RedirectToAction("AccessDenied", "Home"));
            }

            if (ModelState.IsValid)
            {
                if (model.UserIDX > 0)
                {
                    var strippedPhone = Regex.Replace(model.Phone ?? "", "[^0-9]", "");
                    if ((model.LinkedIn ?? "").Contains("www"))
                    {
                        try {
                            Uri uri = new Uri(model.LinkedIn);
                            model.LinkedIn = uri.Segments.Last();
                        } catch { }
                    }

                    //logic for properly blanking out OrgIDX (only when accessed via Admin screen)
                    if (model.OrgIDX == null && model.uListInd == "a")
                    {
                        model.OrgIDX = Guid.Empty;
                    }

                    int SuccID = db_Accounts.UpdateT_OE_USERS(model.UserIDX, null, null, model.FName, model.LName, model.Email, model.ActInd, null, null, null, strippedPhone, model.PhoneExt ?? "", null, null, model.OrgIDX, model.JobTitle ?? "", model.LinkedIn ?? "", model.NodeAdmin, model.ExcludeBadges, null, null, null);

                    //update user expertise
                    db_EECIP.DeleteT_OE_USER_EXPERTISE(model.UserIDX);
                    foreach (string expertise in model.SelectedExpertise ?? new List <string>())
                    {
                        db_EECIP.InsertT_OE_USER_EXPERTISE(model.UserIDX, expertise);
                    }

                    //award profile badge
                    if (db_Accounts.GetUserIDX() == model.UserIDX)
                    {
                        db_Forum.EarnBadgeController(model.UserIDX, "UserProfile");
                    }

                    ////avatar handling
                    if (model.imageBrowes != null)
                    {
                        // ******************** VALIDATION START ********************************
                        //File too big check
                        if (model.imageBrowes.ContentLength > 10485760)
                        {
                            TempData["Error"] = "File cannot exceed 10MB";
                            return(RedirectToAction("UserProfile", new { a = model.uListInd }));
                        }

                        //invalid file extension check
                        var           fileExtension     = Path.GetExtension(model.imageBrowes.FileName).ToUpper();
                        List <string> allowedExtensions = new List <string> {
                            ".JPG", ".JPEG", ".PNG", ".BMP"
                        };
                        if (!allowedExtensions.Contains(fileExtension))
                        {
                            TempData["Error"] = "Invalid file type";
                            return(RedirectToAction("UserProfile", new { a = model.uListInd }));
                        }
                        // ******************** VALIDATION END ********************************

                        // Convert to Png
                        var outputStream = model.imageBrowes.InputStream.ConvertImage(ImageFormat.Png);

                        //save to db
                        db_Accounts.UpdateT_OE_USERS_Avatar(model.UserIDX, Utils.ConvertGenericStreamToByteArray(outputStream));

                        //save to file system
                        string fileName1 = model.UserIDX.ToString() + ".png";
                        model.imageBrowes.SaveAs(Server.MapPath("/Content/Images/Users/" + fileName1));

                        //award badge
                        if (db_Accounts.GetUserIDX() == model.UserIDX)
                        {
                            db_Forum.EarnBadgeController(model.UserIDX, "Photogenic");
                        }
                    }

                    //update azure search
                    if (model.ActInd)
                    {
                        AzureSearch.PopulateSearchIndexUsers(model.UserIDX);
                    }
                    else
                    {
                        AzureSearch.DeleteSearchIndexUsers(model.UserIDX);
                    }

                    //update contact in MailChimp
                    MailChimpHelper _mailchimp = new MailChimpHelper();
                    if (model.ActInd)
                    {
                        _mailchimp.AddUpdateMailChimpContact(model.Email, model.FName, model.LName);
                    }
                    else
                    {
                        _mailchimp.RemoveMailChimpContant(model.Email);
                    }

                    if (SuccID > 0)
                    {
                        TempData["Success"] = "Update successful.";
                    }
                    else
                    {
                        TempData["Error"] = "Error updating data.";
                    }
                }
            }

            return(RedirectToAction("UserProfile", new { a = model.uListInd }));
        }
        public ActionResult Register(vmAccountRegister model)
        {
            if (ModelState.IsValid)
            {
                if (model != null)
                {
                    MembershipCreateStatus status;

                    try
                    {
                        // ******************** AGENCY VALIDATION ******************************
                        List <T_OE_ORGANIZATION> o = db_Ref.GetT_OE_ORGANIZATION_ByEmail(model.UserName);
                        if (o != null)
                        {
                            if (o.Count == 0)
                            {
                                // PREVENT REGISTRATION IF NON US/GOV EMAIL
                                if (model.UserName.Substring(model.UserName.Length - 4) != ".gov" && model.UserName.Substring(model.UserName.Length - 3) != ".us")
                                {
                                    TempData["Error"] = "We verify users based on email domain and it appears your domain is not in our system. Please email [email protected] and we will get your account set up. Apologies for the delay and thank you for your interest in the Inventory.";
                                    return(View(model));
                                }
                                else
                                {
                                    if (model.suggestAgency == null || model.suggestOrgType == null)
                                    {
                                        TempData["Error"] = "No government agency is found matching that email. Please provide an agency name below.";
                                        ModelState.AddModelError("suggestAgency", "Enter your agency name");
                                        ModelState.AddModelError("suggestOrgType", "Specify an organization type");
                                        model.suggestAgencyInd = true;
                                        model.ddl_OrgTypes     = ddlHelpers.get_ddl_orgtypes(true);
                                        return(View(model));
                                    }
                                }
                            }
                            else if (o.Count > 1 && model.intSelOrgIDX == null)  //more than one match and single hasn't been identified yet
                            {
                                model.ddl_Agencies = o.Select(x => new SelectListItem
                                {
                                    Value = x.ORG_IDX.ToString(),
                                    Text  = x.ORG_NAME
                                });

                                TempData["Error"] = "Select the agency to which you belong.";
                                ModelState.AddModelError("intSelOrgIDX", "Select your agency");
                                return(View(model));
                            }
                            else if (o.Count == 1)
                            {
                                model.intSelOrgIDX = o.FirstOrDefault().ORG_IDX;
                            }
                        }
                        // ****************** END AGENCY VALIDATION ******************************


                        //create user and send out verification email
                        Membership.Provider.CreateUser(model.UserName, "", model.UserName, null, null, false, null, out status);

                        if (status == MembershipCreateStatus.Success)
                        {
                            int UserIDX = (int)Membership.GetUser(model.UserName).ProviderUserKey;

                            //create agency and email rule if new
                            Guid?NewOrgIDX = null;
                            if (model.intSelOrgIDX == null)
                            {
                                //create the agency & email rule
                                NewOrgIDX = db_Ref.InsertUpdatetT_OE_ORGANIZATION(null, null, model.suggestAgency, null, null, model.suggestOrgType, null, null, true, UserIDX);
                                db_Ref.InsertT_OE_ORGANIZATION_EMAIL_RULE(NewOrgIDX.ConvertOrDefault <Guid>(), Regex.Match(model.UserName, "@(.*)").Groups[1].Value);

                                //notify Site Admins via email
                                List <T_OE_USERS> Admins = db_Accounts.GetT_OE_USERSInRole(1);
                                foreach (T_OE_USERS Admin in Admins)
                                {
                                    Utils.SendEmail(null, Admin.EMAIL, null, null, model.UserName + " has registered a new Agency", "The user " + model.UserName + " has registered the following new agency: " + model.suggestAgency, null, "", "The user " + model.UserName + " has registered the following new agency: " + model.suggestAgency);
                                }
                            }

                            //update first name, last name, and agency
                            db_Accounts.UpdateT_OE_USERS(UserIDX, null, null, model.FirstName, model.LastName, model.UserName, null, null, null, null, null, null, null, null, model.intSelOrgIDX ?? NewOrgIDX, null, null, null, false, true, true, true);

                            //subscribe to MailChimp
                            MailChimpHelper _mailchimp = new MailChimpHelper();
                            bool            succInd    = _mailchimp.AddUpdateMailChimpContact(model.UserName, model.FirstName, model.LastName);

                            //redirect user to registration success view
                            return(RedirectToAction("RegisterSuccess", "Account"));
                        }
                        else
                        {
                            if (status.ToString() == "DuplicateUserName")
                            {
                                TempData["Error"] = "An account has already been created with that email address. Please recover lost password.";
                            }
                            else if (status.ToString() == "InvalidEmail")
                            {
                                TempData["Error"] = "Unable to send verification email. Please try again later.";
                            }
                            else
                            {
                                TempData["Error"] = status;
                            }
                        }
                    }
                    catch (MembershipCreateUserException e)
                    {
                        ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                    }
                }
            }

            // Redisplay form showing error or success message
            return(View(model));
        }