Beispiel #1
0
        private string SavePostedFile(UploadedFile uploadedFile)
        {
            Session["UploadedFile"] = null;
            string fileName = "";
            if (uploadedFile.IsValid)
            {
                Random random = new Random();
                //string _MenuGroupId = Session["MenuGroupId"].ToString();
                string dateString = String.Format("{0}{1}{2}", System.DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);
                string timeString = String.Format("{0}{1}{2}", System.DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
                fileName = String.Format("{0}-{1}-{2}-{3}", dateString, timeString, random.Next(), uploadedFile.FileName);
                if (Tools.IsImage(uploadedFile.FileBytes))
                {
                    Session["UploadedFile"] = fileName;
                    //uploadedFile.SaveAs(Server.MapPath("~/ContentData/MenuImages/") + fileName, true);
                    //byte[] thumb = Tools.CreateThumb(uploadedFile.FileBytes, 32, true);
                    //MemoryStream stream = new MemoryStream(thumb);
                    FileStream stream = new FileStream(Server.MapPath(BusinessLogicLayer.Common.ConferenceContentPath) + fileName, FileMode.Create);
                    stream.Write(uploadedFile.FileBytes, 0, uploadedFile.FileBytes.Length);
                    stream.Flush();
                    stream.Close();
                }
                else
                {
                    BusinessLogicLayer.Components.UserMonitorLogic monitorLogic = new BusinessLogicLayer.Components.UserMonitorLogic();
                    string ipMain = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                    string IpForwardedFor = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                    string ip = String.Format("{0}-{1}", ipMain, IpForwardedFor);
                    int userid = 0;
                    if (SecurityManager.isLogged(this.Page))
                        userid = SecurityManager.getUser(this.Page).BusinessEntityId;
                    monitorLogic.Insert(userid, false, ip, fileName, DateTime.Now);
                    fileName = "";
                }

            }
            return fileName;
        }
Beispiel #2
0
        private string SavePostedFile(UploadedFile uploadedFile, bool HaveWaterMark)
        {
            BusinessLogicLayer.Entities.ContentManagement.ArticleLanguage oldLanguage = SitePage.GetArticlePageLanguageByLanguageId(OldLanguageId);
            Session["UploadedFile"] = null;
            string fileName = "";
            if (uploadedFile.IsValid)
            {
                Random random = new Random();
                //string _MenuGroupId = Session["MenuGroupId"].ToString();
                string dateString = String.Format("{0}{1}{2}", System.DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);
                string timeString = String.Format("{0}{1}{2}", System.DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
                fileName = String.Format("{0}-{1}-{2}-{3}", dateString, timeString, random.Next(), uploadedFile.FileName);
                if (Tools.IsImage(uploadedFile.FileBytes))
                {
                    Session["UploadedFile"] = fileName;
                    if (oldLanguage != null)
                    {
                        oldLanguage.ArticleAttachment = fileName;
                    }
                    //uploadedFile.SaveAs(Server.MapPath("~/ContentData/MenuImages/") + fileName, true);
                    //byte[] thumb = Tools.CreateThumb(uploadedFile.FileBytes, 32, true);
                    //MemoryStream stream = new MemoryStream(thumb);
                    string fileName_withoutWaterMark = "now" + fileName ;
                    if (HaveWaterMark)
                    {
                        FileStream stream = new FileStream(Server.MapPath(BusinessLogicLayer.Common.ConferenceContentPath) + fileName_withoutWaterMark, FileMode.Create);
                        stream.Write(uploadedFile.FileBytes, 0, uploadedFile.FileBytes.Length);
                        stream.Flush();
                        stream.Close();
                        WaterMarkImage.SaveImageWithWaterMark(Server.MapPath(BusinessLogicLayer.Common.ConferenceContentPath), "www.almnatiq.net @copyright 2014", fileName_withoutWaterMark, "watermark.png", fileName);
                    }
                    else
                    {
                        FileStream stream = new FileStream(Server.MapPath(BusinessLogicLayer.Common.ConferenceContentPath) + fileName, FileMode.Create);
                        stream.Write(uploadedFile.FileBytes, 0, uploadedFile.FileBytes.Length);
                        stream.Flush();
                        stream.Close();

                    }
                }
                else
                {
                    BusinessLogicLayer.Components.UserMonitorLogic monitorLogic = new BusinessLogicLayer.Components.UserMonitorLogic();
                    string ipMain = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                    string IpForwardedFor = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                    string ip = String.Format("{0}-{1}", ipMain, IpForwardedFor);
                    int userid = 0;
                    if (SecurityManager.isLogged(this.Page))
                        userid = SecurityManager.getUser(this.Page).BusinessEntityId;
                    monitorLogic.Insert(userid, false, ip, fileName, DateTime.Now);
                    fileName = "";
                }

            }
            return fileName;
        }
Beispiel #3
0
        public static bool doLogin(Page currentPage, string uid, string pwd)
        {
            if (uid == string.Empty || pwd == string.Empty)
                return false;
            // loging
            BusinessLogicLayer.Entities.Persons.Person user = null;
            BusinessLogicLayer.Components.UserMonitorLogic monitorLogic = new BusinessLogicLayer.Components.UserMonitorLogic();
            string ipMain = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            string IpForwardedFor = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            string ip= String.Format("{0}-{1}", ipMain, IpForwardedFor);
            int countNumbers = monitorLogic.GetUserMonitorCountInPeriod(uid, ip);

            try
            {
                // autehticate

                user = BusinessLogicLayer.Common.PersonLogic.GetByUserName(uid);
                if (countNumbers >= 10)
                {
                    throw new smLoginInactiveException();
                }
                // invalid login
                if (user == null)
                {
                    throw new smInvalidLoginException();
                }

                if (user.Credentials == null)
                {
                    monitorLogic.Insert(0, false, ip, uid, DateTime.Now);
                    throw new smLoginInactiveException();
                }
                if (string.IsNullOrEmpty(user.Credentials.PasswordHash))
                {
                    monitorLogic.Insert(user.BusinessEntityId, false, ip, uid, DateTime.Now);
                    throw new smLoginInactiveException();
                }
                // password
                string passHash = Tools.MD5(pwd + user.Credentials.PasswordSalt);

                if (user.Credentials.PasswordHash != passHash)
                {

                    monitorLogic.Insert(user.BusinessEntityId, false, ip, uid, DateTime.Now);
                    throw new smInvalidPasswordException();
                }

                // copy by value to another object before saving it into session.

                // blank the user password before saving into the session
                //u.Password = string.Empty;

                // save user object into session
                monitorLogic.Insert(user.BusinessEntityId, true, ip, uid, DateTime.Now);
                currentPage.Session.Add("USER", user);
                //currentPage.Session.Add("UserAccessType", user.AccessTypeId);
                currentPage.Session.Add("USERID", user.BusinessEntityId);
                currentPage.Session["MenuSession"] = null;
                // log the current login
                // get user IP and browser type, etc, and put it in ExtraParam
                //SManager.logAction(log);
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
        }