Beispiel #1
0
        public ActionResult Download(DownloadFileType FileType)
        {
            if (FileType == DownloadFileType.CSV)
            {
                StringBuilder sb    = new StringBuilder();
                List <Role>   Roles = Web.Admin.Logic.Collections.Roles.Get();

                sb.Append("Name,Settings,Color,BackgroundColor Created, Modified\r\n");
                foreach (Role Role in Roles)
                {
                    sb.Append(String.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\"\r\n", Role.Name, Role.Settings, Role.BackColor, Role.ForeColor, Role.Created.ToString("dd.MM.yyyy HH:mm:ss"), Role.Modified.ToString("dd.MM.yyyy HH:mm:ss")));
                }

                ControllerContext.HttpContext.Response.AddHeader("content-disposition", "attachment; filename=roles-" + DateTime.Now.ToString("dd.MM.yyyy") + ".csv");
                ControllerContext.HttpContext.Response.ContentType = "text/csv";
                ControllerContext.HttpContext.Response.BinaryWrite(System.Text.ASCIIEncoding.UTF8.GetBytes(sb.ToString()));
                ControllerContext.HttpContext.Response.Flush();

                AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleDounloaded, Roles.Count));
            }
            else if (FileType == DownloadFileType.XLS)
            {
            }

            return(new EmptyResult());
        }
Beispiel #2
0
        public JsonResult SaveFieldGroup(int GroupID, string Name, string Description, string Order, bool IsActive, bool AdminUseOnly)
        {
            ProfileFieldGroup fieldGroup = ProfileFieldGroups.GetBy(GroupID);
            String            Message    = "";

            if (fieldGroup.FieldGroupName.Trim().ToLower() != Name.Trim().ToLower())
            {
                if (ProfileFieldGroups.GetByName(Name.Trim()).FieldGroupID > 0)
                {
                    Message = "The group \"" + Name + "\" already exists.";
                }
            }

            if (fieldGroup.FieldGroupName.Trim().ToLower().Length == 0)
            {
                Message = "The group name should not be empty.";
            }


            if (Message != "")
            {
                RequestResultModel _model = new RequestResultModel();
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                _model.Message  = Message;
                AuditEvent.AppEventWarning(Profile.Member.Email, Message);

                return(Json(new
                {
                    NotifyType = NotifyType.DialogInline,
                    Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model),
                }, JsonRequestBehavior.AllowGet));
            }


            fieldGroup.FieldGroupName        = Name;
            fieldGroup.FieldGroupDescription = Description;
            fieldGroup.IsActive     = IsActive ? 1 : 0;
            fieldGroup.AdminUseOnly = AdminUseOnly ? 1 : 0;
            fieldGroup.Save();

            if (GroupID > 0)
            {
                AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format("The \"{0}\" profile group has been updated.", Name));
            }
            else
            {
                AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format("The \"{0}\" profile group has been added.", Name));
            }

            if (Order != "")
            {
                ProfileFieldGroups.UpdateOrder(Order);
            }

            return(Json(new
            {
                NotifyType = -1,
                Html = "",
            }, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        /// <summary>
        /// Send email to a recipient and BCC members.
        /// </summary>
        /// <param name="FromName">Sender name.</param>
        /// <param name="FromEmail">Sender email.</param>
        /// <param name="ToName">Recipient name.</param>
        /// <param name="ToEmail">Recipient email.</param>
        /// <param name="Bcc">BCC recipient emails.</param>
        /// <param name="Subject">Mail subject.</param>
        /// <param name="Body">Mail body.</param>
        /// <returns>True if an email has been sent succesfully.</returns>
        public static bool SendMail(string FromName, string FromEmail, string ToName, string ToEmail, string Bcc, string Subject, string Body)
        {
            ApplicationParameters AppParams = Parameters;
            var    fromAddress  = new MailAddress(FromEmail, FromName);
            var    toAddress    = new MailAddress(ToEmail, ToName);
            string fromPassword = AppParams.MailServerSmtpPassword.Value;
            string subject      = Subject;
            string body         = Body;

            var smtp = new SmtpClient
            {
                Host           = Parameters.MailServerSmtpHost.Value,
                Port           = int.Parse(AppParams.MailServerSmtpPort.Value),
                EnableSsl      = bool.Parse(AppParams.MailServerSmtpSSLEnabled.Value),
                DeliveryMethod = SmtpDeliveryMethod.Network,
                Credentials    = new NetworkCredential(fromAddress.Address, fromPassword),
                Timeout        = 20000
            };

            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = body,
                IsBodyHtml = true
            })

                try
                {
                    if (Bcc != null && Bcc.Length > 0)
                    {
                        message.Bcc.Add(Bcc);
                    }
                    else
                    {
                        Bcc = "";
                    }

                    string Title = String.Format(AuditEvent.TheEmailhasBeenSent, FromName, FromEmail, ToName, ToEmail, Bcc, Subject);
                    smtp.Send(message);
                    AuditEvent.AppEventSuccess(FromEmail, Title, "##Details%%" + Title + "\r\n\r\nE-mail message:\r\n" + Body + "%%");
                    return(true);
                }
                catch (Exception ex)
                {
                    AuditEvent.AddAppEvent(
                        new AuditEventItem
                    {
                        EventType   = AuditEventType.Error,
                        IPAddress   = HttpContext.Current.Request.UserHostAddress,
                        MemberEmail = AppParams.GeneralAdminEmail.Value,
                        Description = ex.Message,
                        Details     = AuditEvent.GetSessionDetails("E-mail message:\r\n" + body + "\r\nStackTrace:\r\n" + ex.StackTrace)
                    }
                        );

                    return(false);
                }
        }
Beispiel #4
0
        public JsonResult RemoveRole(int[] RemoeRoles)
        {
            RoleListModel _model   = new RoleListModel();
            List <Role>   _deleted = new List <Role>();

            foreach (int RoleID in RemoeRoles)
            {
                Role role = Web.Admin.Logic.Collections.Roles.GetBy(RoleID);
                List <ProfileField> _profileFields = ProfileFields.GetByRole(RoleID);

                if (Web.Admin.Logic.Collections.Roles.GetMemberCount(role.RoleID) > 0)
                {
                    role.WasDeleted    = false;
                    role.UIMessage     = "The role contains members.";
                    role.UIMessageType = UIMessageType.Warning;
                    AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleContainsMembers, role.Name));
                }
                else if (_profileFields.Count > 0)
                {
                    role.WasDeleted = false;
                    role.UIMessage  = "The role has not been deleted. Attached fields: ";
                    foreach (ProfileField profileField in _profileFields)
                    {
                        role.UIMessage += "<u>" + profileField.FieldName + "</u>&nbsp;";
                    }
                    role.UIMessageType = UIMessageType.Warning;
                    AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleContainsMembers, role.Name));
                }
                else
                {
                    if (role.IsBuiltIn)
                    {
                        role.WasDeleted    = true;
                        role.UIMessage     = "The role is built in and can't be deleted.";
                        role.UIMessageType = UIMessageType.Warning;
                        AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleIsBuiltIn, role.Name));
                    }
                    else if (role.Delete())
                    {
                        role.WasDeleted    = true;
                        role.UIMessage     = "The role has been deleted.";
                        role.UIMessageType = UIMessageType.Success;
                        AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleDeleted, role.Name));
                    }
                }

                _deleted.Add(role);
            }

            _model.Roles = _deleted;

            return(Json(new
            {
                NotifyType = NotifyType.Dialog,
                Html = this.RenderPartialView(@"_RemoveRolesResult", _model)
            }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult RemoveDomain(int[] RemoveDomains)
        {
            DomainListModel _model   = new DomainListModel();
            List <Domain>   _deleted = new List <Domain>();

            foreach (int DomainID in RemoveDomains)
            {
                Domain domain = Web.Admin.Logic.Collections.Domains.GetBy(DomainID);
                List <ProfileField> _profileFields = ProfileFields.GetByDomain(DomainID);

                if (ProfileFields.GetByDomain(domain.DomainID).Count > 0)
                {
                    domain.WasDeleted = false;
                    domain.UIMessage  = "The domain has not been deleted. Attached fields: ";
                    foreach (ProfileField profileField in _profileFields)
                    {
                        domain.UIMessage += "<u>" + profileField.FieldName + "</u>&nbsp;";
                    }
                    domain.UIMessageType = UIMessageType.Warning;
                    AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleContainsMembers, domain.Name));
                }
                else
                {
                    if (domain.Delete())
                    {
                        domain.WasDeleted    = true;
                        domain.UIMessage     = "The domain has been deleted.";
                        domain.UIMessageType = UIMessageType.Success;
                        AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleDeleted, domain.Name));
                    }
                }

                _deleted.Add(domain);
            }

            _model.Domains = _deleted;

            return(Json(new
            {
                NotifyType = NotifyType.Dialog,
                Html = this.RenderPartialView(@"_RemoveDomainsResult", _model)
            }, JsonRequestBehavior.AllowGet));
        }
Beispiel #6
0
        public JsonResult RemoveProfileFields(int[] Fields)
        {
            foreach (int Field in Fields)
            {
                ProfileField field = ProfileFields.GetBy(Field);
                field.Delete();
                AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format("The \"{0}\" field has been deleted.", field.FieldName));
            }

            RequestResultModel _model = new RequestResultModel();

            _model.InfoType = RequestResultInfoType.Success;
            _model.Message  = "All selected fields (and their data) have been deleted.";

            return(Json(new
            {
                NotifyType = NotifyType.PageInline,
                Html = this.RenderPartialView(@"_RequestResultPageInLine", _model),
            }, JsonRequestBehavior.AllowGet));
        }
Beispiel #7
0
        public JsonResult RemoveFieldGroup(int GroupID)
        {
            ProfileFieldGroup  fieldGroup = ProfileFieldGroups.GetBy(GroupID);
            RequestResultModel _model     = new RequestResultModel();

            if (fieldGroup.FieldGroupID > 0)
            {
                fieldGroup.Delete();

                _model.InfoType = RequestResultInfoType.Success;
                _model.Message  = "The group \"" + fieldGroup.FieldGroupName + "\" has been removed.";

                if (GroupID > 0)
                {
                    AuditEvent.AppEventSuccess(Profile.Member.Email, _model.Message);
                }

                return(Json(new
                {
                    NotifyType = NotifyType.PageInline,
                    Html = this.RenderPartialView(@"_RequestResultPageInLine", _model),
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                _model.InfoType = RequestResultInfoType.Success;
                _model.Message  = "The group doesn't exist.";

                AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                return(Json(new
                {
                    NotifyType = NotifyType.PageInline,
                    Html = this.RenderPartialView(@"_RequestResultPageInLine", _model),
                }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult SaveDomain(DomainInfo Info)
        {
            RequestResultModel _model = new RequestResultModel();

            if (Info.Name == null || Info.Name.Trim().Length == 0)
            {
                _model          = new RequestResultModel();
                _model.Title    = "Warning";
                _model.Message  = "Name is empty. Please, enter domain name.";
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                return(Json(new
                {
                    NotifyType = NotifyType.DialogInline,
                    Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                }, JsonRequestBehavior.AllowGet));
            }


            if (Info.DomainID > 0)
            {
                Domain domain       = Web.Admin.Logic.Collections.Domains.GetBy(Info.DomainID);
                Domain domainExists = Web.Admin.Logic.Collections.Domains.GetByName(Info.Name);

                // The domain has been deleted.
                if (domain.DomainID <= 0)
                {
                    _model.Title   = "Warning";
                    _model.Message = String.Format("Domain '{0}' doesn't exist. Please, refresh role list and try again.", domainExists.Name);
                    AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                    return(Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                    }, JsonRequestBehavior.AllowGet));
                }

                // The domain already esists.
                if (domainExists.DomainID > 0 && Info.DomainID != domainExists.DomainID)
                {
                    _model.Title   = "Warning";
                    _model.Message = String.Format("Domain '{0}' already exists. Please, change domain name and try again.", domainExists.Name);
                    AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                    return(Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                    }, JsonRequestBehavior.AllowGet));
                }

                domain.Name        = Info.Name;
                domain.Description = Info.Description;
                domain.Save();

                _model               = new RequestResultModel();
                _model.Message       = String.Format("Domain \"{0}\"has been updated.", domain.Name);
                _model.HideInSeconds = 4000;
                AuditEvent.AppEventSuccess(Profile.Member.Email, _model.Message);

                return(Json(new
                {
                    NotifyType = NotifyType.PageInline,
                    Html = this.RenderPartialView(@"_RequestResultPageInLine", _model)
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                Domain domainExists = Web.Admin.Logic.Collections.Domains.GetByName(Info.Name);

                // The domain already esists.
                if (domainExists.DomainID > 0)
                {
                    _model.Title    = "Warning";
                    _model.Message  = String.Format("Domain '{0}' already exists. Please, change domain name and try again.", domainExists.Name);
                    _model.InfoType = RequestResultInfoType.ErrorOrDanger;

                    return(Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                    }, JsonRequestBehavior.AllowGet));
                }

                Domain Domain = new Domain();
                Domain.Name        = Info.Name;
                Domain.Description = Info.Description;
                Domain.Save();

                _model.Message = String.Format("New domain \"{0}\" has been created.", Domain.Name);

                return(Json(new
                {
                    NotifyType = NotifyType.PageInline,
                    Html = this.RenderPartialView(@"_RequestResultPageInLine", _model)
                }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #9
0
        public JsonResult AddField(String Name, String FieldType, String Comment, String PossibleValues, String SelectText, String IsMandatory, String ShowInSignup, String SortValues, String IsActive, String AdminUseOnly, String VerticalLayout, int FieldGroupID, bool Encrypted, int[] SelectedDomains, int[] SelectedRoles)
        {
            ProfileField profileField = ProfileFields.GetByName(Name);
            String       Message      = "";

            if (profileField.FieldID > 0 && profileField.FieldName.Trim().ToLower() == Name.Trim().ToLower())
            {
                Message = "The field \"" + Name + "\" already exists.";
            }

            if (Name.Trim().ToLower().Length == 0)
            {
                Message = "The field name should not be empty.";
            }

            if (Message != "")
            {
                RequestResultModel _model = new RequestResultModel();
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                _model.Message  = Message;

                AuditEvent.AppEventWarning(Profile.Member.Email, Message);

                return(Json(new
                {
                    NotifyType = NotifyType.DialogInline,
                    Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model),
                }, JsonRequestBehavior.AllowGet));
            }


            profileField.FieldName       = Name;
            profileField.Comment         = Comment;
            profileField.FieldTypeID     = (ProfileFieldTypeEnum)int.Parse(FieldType);
            profileField.PossibleValues  = PossibleValues;
            profileField.TextSelectValue = SelectText;
            profileField.IsMandatory     = (IsMandatory == "True" ? 1 : 0);
            profileField.ShowInSignUp    = (ShowInSignup == "True" ? 1 : 0);
            profileField.SortValues      = SortValues == "True" ? 1 : 0;
            profileField.IsActive        = IsActive == "True" ? 1 : 0;
            profileField.AdminUseOnly    = AdminUseOnly == "True" ? 1 : 0;
            profileField.VerticalLayout  = VerticalLayout == "True" ? 1 : 0;
            profileField.FieldGroupID    = FieldGroupID;
            profileField.Encrypted       = Encrypted == true ? 1 : 0;
            profileField.Save();

            if (SelectedDomains != null)
            {
                List <Domain> _domains = Domains.Get();
                foreach (Domain _domain in _domains)
                {
                    DomainProfileField _domainField = new DomainProfileField();
                    _domainField.DomainID       = _domain.DomainID;
                    _domainField.ProfileFieldID = profileField.FieldID;

                    if (SelectedDomains.Where(t => t == _domain.DomainID).FirstOrDefault() != default(int))
                    {
                        _domainField.Save();
                    }
                }
            }

            if (SelectedRoles != null)
            {
                List <Role> _roles = Web.Admin.Logic.Collections.Roles.Get();
                foreach (Role _role in _roles)
                {
                    RoleProfileField _roleField = new RoleProfileField();
                    _roleField.RoleID         = _role.RoleID;
                    _roleField.ProfileFieldID = profileField.FieldID;

                    if (SelectedRoles.Where(t => t == _role.RoleID).FirstOrDefault() != default(int))
                    {
                        _roleField.Save();
                    }
                }
            }

            AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format("The \"{0}\" field has been added.", Name));

            return(Json(new
            {
                NotifyType = -1,
                Html = "",
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult SaveSettings(List <ParamNameValue> ParamNameValues)
        {
            List <ParamNameValue> WrongParams = new List <ParamNameValue>();
            string GeneralSecretAdminUrlOld   = AppParams.GeneralSecretAdminUrl.Value;
            string AppApiSecretURL            = AppParams.AppApiSecretURL.Value;

            foreach (ParamNameValue Param in ParamNameValues)
            {
                if (Param.Name == null || Param.Name.Length == 0)
                {
                    continue;
                }

                Parameter Parameter = Parameters.GetBy(Param.Name);
                Parameter.MemberID = Profile.Member.MemberID;

                string oldValue = Parameter.Value;
                Param.Value = Param.Value == null ? "" : Param.Value;

                if (Parameter.Type == ParameterType.Bool)
                {
                    if (Param.Value.ToLower() == "true")
                    {
                        Param.Value = Parameter.Value = "true";
                    }
                    else
                    {
                        Param.Value = Parameter.Value = "false";
                    }
                }
                else if (Parameter.Type == ParameterType.SmallInteger || Parameter.Type == ParameterType.RadioInteger)
                {
                    long value  = -1;
                    bool result = long.TryParse(Param.Value, out value);
                    Parameter.Value = result ? Param.Value : Parameter.Value;

                    if (!result)
                    {
                        WrongParams.Add(Param);
                    }
                }
                else
                {
                    Parameter.Value = Param.Value;
                }

                if (oldValue != Param.Value)
                {
                    Parameter.Save();
                }

                if (AppParams.GeneralAuditEnabled.Value == "true" && Param.Value != oldValue)
                {
                    AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format("Changed: {0} -> from \"{1}\" to \"{2}\"", Parameter.Name, oldValue, Parameter.Value));
                }
            }

            AppParams.RefreshAppParameters();
            List <ParamNameValue> ParamValues = new List <ParamNameValue>();
            List <Parameter>      Params      = Parameters.Get();

            ////////////////////////////////////////////
            // Change admin route
            ////////////////////////////////////////////
            bool   AdminRouteChaned  = false;
            string RelativeAdminPath = "{controller}/{action}/{id}";

            if (AppParams.GeneralSecretAdminUrl != null && AppParams.GeneralSecretAdminUrl.Value.Length > 0 && GeneralSecretAdminUrlOld != AppParams.GeneralSecretAdminUrl.Value)
            {
                RouteCollection routes = RouteTable.Routes;
                using (routes.GetWriteLock())
                {
                    RelativeAdminPath = Path.Combine(AppSession.Parameters.GeneralSecretAdminUrl.Value.Replace("/", "\\"), RelativeAdminPath.Replace("/", "\\")).Replace("\\", "/");

                    if (RelativeAdminPath[0] == '/')
                    {
                        RelativeAdminPath = RelativeAdminPath.Remove(0, 1);
                    }

                    Route route = (Route)routes["Admin-Secret-Path"];
                    route.Url = RelativeAdminPath;
                }

                // If admin route changed redirect admin to correct url
                AdminRouteChaned = true;
            }
            else if ((AppParams.GeneralSecretAdminUrl == null || AppParams.GeneralSecretAdminUrl.Value.Length == 0) && GeneralSecretAdminUrlOld != AppParams.GeneralSecretAdminUrl.Value)
            {
                RouteCollection routes = RouteTable.Routes;
                using (routes.GetReadLock())
                {
                    Route route = (Route)routes["Admin-Secret-Path"];
                    route.Url = "Admin/" + RelativeAdminPath;
                }

                AdminRouteChaned = true;
            }

            ////////////////////////////////////////////
            // Change API route
            ////////////////////////////////////////////
            bool   APIRouteChaned  = false;
            string RelativeAPIPath = "{action}/{id}";

            if (AppParams.AppApiSecretURL != null && AppParams.GeneralSecretAdminUrl.Value.Length > 0 && AppApiSecretURL != AppParams.AppApiSecretURL.Value)
            {
                RouteCollection routes = RouteTable.Routes;
                using (routes.GetWriteLock())
                {
                    RelativeAPIPath = Path.Combine(AppSession.Parameters.AppApiSecretURL.Value.Replace("/", "\\"), RelativeAPIPath.Replace("/", "\\")).Replace("\\", "/");

                    if (RelativeAdminPath[0] == '/')
                    {
                        RelativeAdminPath = RelativeAPIPath.Remove(0, 1);
                    }

                    Route route = (Route)routes["API-Secret-Path"];
                    route.Url = RelativeAPIPath;
                }

                // If API route changed redirect admin to correct url
                APIRouteChaned = true;
            }
            else if ((AppParams.AppApiSecretURL == null || AppParams.AppApiSecretURL.Value.Length == 0) && AppApiSecretURL != AppParams.AppApiSecretURL.Value)
            {
                RouteCollection routes = RouteTable.Routes;
                using (routes.GetReadLock())
                {
                    Route route = (Route)routes["API-Secret-Path"];
                    route.Url = "Admin/API/" + RelativeAPIPath;
                }

                APIRouteChaned = true;
            }


            foreach (Parameter Param in Params)
            {
                ParamValues.Add(new ParamNameValue {
                    Name = Param.Name, Value = Param.Value, Type = Param.Type.ToString()
                });
            }


            string             Message         = "";
            string             AdminUrlChanged = "";
            string             APIUrlChanged   = "";
            RequestResultModel _model          = new RequestResultModel();

            if (AdminRouteChaned)
            {
                AdminUrlChanged = String.Format("<br/><strong>Admin URL has been changed. Click <a href=\"{0}\">here</a> to redirect to actual admin URL.</strong>", Url.Action("", "Settings"));
            }

            if (APIRouteChaned)
            {
                string Path = (AppParams.AppApiSecretURL.Value.Length > 0 ? AppParams.AppApiSecretURL.Value : "Admin/API");
                APIUrlChanged = String.Format("<br/>API URL has been changed. Please update all API clients. Here is base url now: <strong>{0}</strong>", Path);
            }


            if (WrongParams.Count == 0)
            {
                _model.Title    = GetLabel("Account.Controller.Congrat");
                _model.InfoType = RequestResultInfoType.Success;
                _model.Message  = "Application settngs have been saved." + AdminUrlChanged + APIUrlChanged;
                Message         = this.RenderPartialView(@"_RequestResultDialogInLine", _model);
            }
            else
            {
                _model.Title    = GetLabel("Account.Controller.Warning");
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                _model.Message  = "Some parametrs have not been saved. Please check." + AdminUrlChanged + APIUrlChanged;
                Message         = this.RenderPartialView(@"_RequestResultDialogInLine", _model);
            }



            return(Json(new
            {
                Message = Message,
                Settings = ParamValues,
            }, JsonRequestBehavior.AllowGet));
        }
Beispiel #11
0
        public ActionResult ImportRoles()
        {
            System.Threading.Thread.Sleep(200);
            CultureInfo provider = CultureInfo.InvariantCulture;

            List <Role> RoleResult = new List <Role>();

            try
            {
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    System.Threading.Thread.Sleep(1);

                    String             FileContent = "";
                    HttpPostedFileBase PostedFile  = Request.Files[i];

                    using (System.IO.Stream input = PostedFile.InputStream)
                    {
                        byte[] buffer = new byte[PostedFile.InputStream.Length];
                        input.Read(buffer, 0, buffer.Length);
                        FileContent = System.Text.ASCIIEncoding.UTF8.GetString(buffer);
                    }


                    if (FileContent.Length > 0)
                    {
                        string[] Lines = FileContent.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                        AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleUploadHasStarted, Lines.Length));

                        int LineNumber = 1;
                        foreach (String Line in Lines)
                        {
                            if (LineNumber == 1 || Line == null || Line.Trim().Length == 0)
                            {
                                LineNumber++;
                                continue;
                            }

                            List <string> Values = new List <string>();
                            CsvParser     parser = new CsvParser(Line);

                            foreach (string s in parser)
                            {
                                Values.Add(s.Trim());
                            }

                            if (Values.Count >= 4)
                            {
                                Role Role = Web.Admin.Logic.Collections.Roles.GetBy(Values[0]);
                                if (Role.RoleID > 0)
                                {
                                    Role.UIMessage     = "Role already exists.";
                                    Role.UILineNumber  = LineNumber;
                                    Role.UIMessageType = Logic.UIMessageType.Warning;
                                    AuditEvent.AppEventWarning(Profile.Member.Email, String.Format(AuditEvent.RoleUploadMemberExists, Role.Name));
                                }
                                else
                                {
                                    Role.Name     = Values[0];
                                    Role.Settings = Values[1];

                                    if (Values[3].Trim().Length == 0)
                                    {
                                        Role.BackColor = "aaaaaa";
                                    }
                                    else
                                    {
                                        Role.BackColor = Values[2];
                                    }

                                    if (Values[3].Trim().Length == 0)
                                    {
                                        Role.ForeColor = "000000";
                                    }
                                    else
                                    {
                                        Role.ForeColor = Values[3];
                                    }

                                    if (BuiltInRoleMember.ContainsRole(Role.Name))
                                    {
                                        Role.IsBuiltIn = true;
                                    }
                                    else
                                    {
                                        Role.IsBuiltIn = false;
                                    }

                                    try
                                    {
                                        Role.Created = DateTime.ParseExact(Values[4], "dd.MM.yyyy HH:mm:ss", provider);
                                    }
                                    catch { }

                                    try
                                    {
                                        Role.Modified = DateTime.ParseExact(Values[5], "dd.MM.yyyy HH:mm:ss", provider);
                                    }
                                    catch {
                                    }

                                    Role.Save();

                                    Role.UIMessage     = "Role has been added.";
                                    Role.UIMessageType = Logic.UIMessageType.Success;
                                    Role.UILineNumber  = LineNumber;
                                    AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleUploadedItemAdded, Role.Name));
                                }

                                RoleResult.Add(Role);
                            }
                            else if (Values.Count > 0)
                            {
                                Role Role = new Role();

                                Role.UIMessage     = "Wrong line format. Number of columns: " + Values.Count.ToString();
                                Role.UIMessageType = Logic.UIMessageType.ErrorOrDanger;
                                Role.UILineNumber  = LineNumber;
                                AuditEvent.AppEventSuccess(Profile.Member.Email, String.Format(AuditEvent.RoleUploadWrongLineFormat, LineNumber, Values.Count));

                                RoleResult.Add(Role);
                            }

                            LineNumber++;
                        }
                    }
                }

                System.Threading.Thread.Sleep(1000);
                RoleListModel Model = new RoleListModel();
                Model.Roles = RoleResult;

                return(Json(new
                {
                    NotifyType = NotifyType.Dialog,
                    Html = this.RenderPartialView(@"_ImportRolesResult", Model)
                }, "text/html", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                RequestResultModel _model = new RequestResultModel();

                _model.Title         = "Warning";
                _model.Message       = String.Format("Something went wrong: {0}", HttpUtility.HtmlEncode(ex.Message));
                _model.InfoType      = RequestResultInfoType.ErrorOrDanger;
                _model.HideInSeconds = 0;
                _model.Height        = 250;

                AuditEvent.AppEventError(Profile.Member.Email, _model.Message, AuditEvent.GetSessionDetails(ex.StackTrace));

                return(Json(new
                {
                    NotifyType = NotifyType.DialogInline,
                    Html = this.RenderPartialView(@"_RequestResultDialog", _model)
                }, "text/html", JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #12
0
        public JsonResult SaveRole(RoleInfo Info)
        {
            RequestResultModel _model = new RequestResultModel();

            if (Info.Name == null || Info.Name.Trim().Length == 0)
            {
                _model          = new RequestResultModel();
                _model.Title    = "Warning";
                _model.Message  = "Name is empty. Please, enter role name.";
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                return(Json(new
                {
                    NotifyType = NotifyType.DialogInline,
                    Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                }, JsonRequestBehavior.AllowGet));
            }

            if (!AppSession.IsColor(Info.Color))
            {
                _model          = new RequestResultModel();
                _model.Title    = "Warning";
                _model.Message  = "Wrong color value or format, please check.";
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                return(Json(new
                {
                    NotifyType = NotifyType.DialogInline,
                    Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                }, JsonRequestBehavior.AllowGet));
            }

            if (Info.RoleID > 0)
            {
                Role role       = Web.Admin.Logic.Collections.Roles.GetBy(Info.RoleID);
                Role roleExists = Web.Admin.Logic.Collections.Roles.GetBy(Info.Name);

                // The role has been deleted.
                if (role.RoleID <= 0)
                {
                    _model.Title   = "Warning";
                    _model.Message = String.Format("Role '{0}' doesn't exist. Please, refresh role list and try again.", roleExists.Name);
                    AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                    return(Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                    }, JsonRequestBehavior.AllowGet));
                }

                // The role already esists.
                if (roleExists.RoleID > 0 && Info.RoleID != roleExists.RoleID)
                {
                    _model.Title   = "Warning";
                    _model.Message = String.Format("Role '{0}' already exists. Please, change role name and try again.", roleExists.Name);
                    AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                    return(Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                    }, JsonRequestBehavior.AllowGet));
                }

                if (!role.IsBuiltIn)
                {
                    role.Name      = Info.Name;
                    role.IsBuiltIn = false;
                }
                else
                {
                    role.IsBuiltIn = true;
                }

                role.Settings  = Info.Settings;
                role.BackColor = Info.Color != null?Info.Color.Replace("#", "") : "FFFFFF";

                role.ForeColor = Role.ContrastColor(role.BackColor.Replace("#", ""));
                role.Save();

                _model               = new RequestResultModel();
                _model.Message       = String.Format("Role \"{0}\"has been updated.", role.Name);
                _model.HideInSeconds = 4000;
                AuditEvent.AppEventSuccess(Profile.Member.Email, _model.Message);

                return(Json(new
                {
                    NotifyType = NotifyType.PageInline,
                    Html = this.RenderPartialView(@"_RequestResultPageInLine", _model)
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                Role roleExists = Web.Admin.Logic.Collections.Roles.GetBy(Info.Name);

                // The role already esists.
                if (roleExists.RoleID > 0)
                {
                    _model.Title   = "Warning";
                    _model.Message = String.Format("Role '{0}' already exists. Please, change role name and try again.", roleExists.Name);

                    return(Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                    }, JsonRequestBehavior.AllowGet));
                }

                Role Role = new Role();
                Role.Name      = Info.Name;
                Role.Settings  = Info.Settings;
                Role.BackColor = Info.Color != null?Info.Color.Replace("#", "") : "FFFFFF";

                Role.ForeColor = Role.ContrastColor(Role.BackColor.Replace("#", ""));
                Role.IsBuiltIn = false;
                Role.Save();

                _model.Message = String.Format("New role \"{0}\" has been created.", Role.Name);

                return(Json(new
                {
                    NotifyType = NotifyType.PageInline,
                    Html = this.RenderPartialView(@"_RequestResultPageInLine", _model)
                }, JsonRequestBehavior.AllowGet));
            }
        }