Exemplo n.º 1
0
 protected void fileUpload_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e)
 {
     if (fileUpload.UploadedFiles.Count() > 0)
     {
         string sSavePath       = "~/Pictures/Profiles/";
         string resultExtension = Path.GetExtension(e.UploadedFile.FileName);
         string resultFileName  = Path.ChangeExtension(MethodExtension.GetMd5Hash(CurrentUser.salt.ToString() + CurrentUser.ID), resultExtension);
         string resultFileUrl   = sSavePath + resultFileName;
         string resultFilePath  = MapPath(resultFileUrl);
         e.UploadedFile.SaveAs(resultFilePath);
     }
 }
Exemplo n.º 2
0
        public static string[] Save(string info)
        {
            try
            {
                var values = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize <Dictionary <string, object> >(info);

                var CurrentPass = values["CurrentPass"].ToString();
                var NewPass     = values["NewPass"].ToString();
                var ConfirmPass = values["ConfirmPass"].ToString();

                if (CurrentPass == "" || NewPass == "" || ConfirmPass == "")
                {
                    throw new Exception("اطلاعات ورودی کافی نیست");
                }

                if (NewPass != ConfirmPass)
                {
                    throw new Exception("رمز جدید با رمز قبلی آن یکسان نیست");
                }

                if (NewPass == CurrentPass)
                {
                    throw new Exception("رمز فعلی با رمز جدید یکسان است");
                }

                var UserInfo = Business.FacadeAutomation.GetUsersBusiness().GetByID(CurrentUser.ID);

                if (UserInfo == null)
                {
                    throw new Exception("کاربری پیدا نشد");
                }

                if (UserInfo.Password != MethodExtension.GetMd5Hash(CurrentPass + UserInfo.salt))
                {
                    throw new Exception("رمز فعلی اشتباه است");
                }

                UserInfo.Password = MethodExtension.GetMd5Hash(NewPass + UserInfo.salt);

                UserInfo.Save();

                return(new string[2] {
                    "1", "رمز عوض شد"
                });
            }
            catch (Exception ex)
            {
                return(new string[2] {
                    "0", ex.Message
                });
            }
        }
Exemplo n.º 3
0
        public static string[] GetPrivilge()
        {
            try
            {
                if (CurrentUser.IsManager == true)
                {
                    return new string[2] {
                               "1", Newtonsoft.Json.JsonConvert.SerializeObject(new string[1] {
                            "manager"
                        })
                    }
                }
                ;

                var UserPrivilege = Business.FacadeAutomation.GetVwUserPrivilegeRoleBusiness().GetByUserID(CurrentUser.ID);

                #region GetProfilePicture


                var RootPath = HostingEnvironment.MapPath("~/Pictures/Profiles");
                var FileName = MethodExtension.GetMd5Hash(CurrentUser.salt.ToString() + CurrentUser.ID) + ".*";

                var files = Directory.GetFiles(RootPath, FileName);

                if (files.Count() > 0)
                {
                    FileName = Path.GetFileName(files[0]);
                }
                else
                {
                    FileName = "default-profile.png";
                }

                #endregion

                return(new string[3] {
                    "1", Newtonsoft.Json.JsonConvert.SerializeObject(UserPrivilege.Select(r => r.Gid).ToList()), FileName
                });
            }
            catch (Exception ex)
            {
                return(new string[2] {
                    "0", ex.Message
                });
            }
        }
Exemplo n.º 4
0
        public static string[] GetInfo()
        {
            try
            {
                dynamic MyObject = new System.Dynamic.ExpandoObject();

                MyObject.Username = CurrentUser.Username;
                MyObject.Name     = CurrentUser.Name;
                MyObject.Family   = CurrentUser.Family;
                MyObject.Address  = CurrentUser.Address;
                MyObject.Email    = CurrentUser.Email;
                MyObject.Mobile   = CurrentUser.Mobile;

                #region GetProfilgePictures
                var RootPath = HostingEnvironment.MapPath("~/Pictures/Profiles");
                var FileName = MethodExtension.GetMd5Hash(CurrentUser.salt.ToString() + CurrentUser.ID) + ".*";

                var files = Directory.GetFiles(RootPath, FileName);

                if (files.Count() > 0)
                {
                    FileName = Path.GetFileName(files[0]);
                }
                else
                {
                    FileName = "default-profile.png";
                }
                #endregion

                MyObject.PictureUrl = FileName;

                return(new string[2] {
                    "1", Newtonsoft.Json.JsonConvert.SerializeObject(MyObject)
                });
            }
            catch (Exception ex)
            {
                return(new string[2] {
                    "0", ex.Message
                });
            }
        }
Exemplo n.º 5
0
        public static string[] Get()
        {
            try
            {
                CurrentUser = Business.FacadeAutomation.GetUsersBusiness().GetByUsername("1");


                var RootPath = HostingEnvironment.MapPath("~/Pictures/Profiles");
                var FileName = MethodExtension.GetMd5Hash(CurrentUser.salt.ToString() + CurrentUser.ID) + ".*";

                var files = Directory.GetFiles(RootPath, FileName);

                if (files.Count() > 0)
                {
                    return new string[2] {
                               "1", Path.GetFileName(files[0])
                    }
                }
                ;

                else
                {
                    return new string[2] {
                               "1", "Can not find"
                    }
                };



                return(new string[2] {
                    "1", RootPath
                });
            }
            catch (Exception ex)
            {
                return(new string[2] {
                    "0", ex.Message
                });
            }
        }
Exemplo n.º 6
0
        public static string[] CheckLogin(string info)
        {
            try
            {
                var values = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize <Dictionary <string, object> >(info);

                var Username = values["Username"].ToString().ToLower();
                var Password = values["Password"].ToString();

                if (Username == "" || Password == "")
                {
                    throw new Exception(Resources.Texts.NotEnoughEntry);
                }

                var Userinfo = Business.FacadeAutomation.GetUsersBusiness().GetByUsername(Username);

                if (Userinfo == null)
                {
                    throw new Exception(Resources.Texts.UserNotFound);
                }

                if (Userinfo.Password != MethodExtension.GetMd5Hash(Password + Userinfo.salt))
                {
                    throw new Exception(Resources.Texts.IncorrectPassword);
                }

                CurrentUser = Userinfo;

                return(new string[2] {
                    "1", Resources.Texts.Success
                });
            }
            catch (Exception ex)
            {
                return(new string[2] {
                    "0", ex.Message
                });
            }
        }
Exemplo n.º 7
0
        public static string[] Save(string info)
        {
            try
            {
                var values = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize <Dictionary <string, object> >(info);

                var Username = values["Username"].ToString().ToLower();
                var Name     = values["Name"].ToString();
                var Family   = values["Family"].ToString();
                var Email    = values["Email"].ToString();
                var Address  = values["Address"].ToString();
                var Mobile   = values["Mobile"].ToString();
                var RoleIDs  = values["RoleIDs"] as ArrayList;
                var LevelID  = values["LevelID"].ToLong();
                var ID       = values["ID"].ToLong();

                if (Username == "" || Name == "" || Family == "" || Email == "")
                {
                    throw new Exception(Resources.Texts.NotEnoughEntry);
                }

                if (RoleIDs.Count == 0)
                {
                    throw new Exception(Resources.Texts.RoleNotFound);
                }

                if (ID == 0 && values["Password"].ToString() == "")
                {
                    throw new Exception(Resources.Texts.NotEnoughEntry);
                }

                var UserInfo = Business.FacadeAutomation.GetUsersBusiness().GetByID(ID);

                if (UserInfo == null)
                {
                    UserInfo = new Data.Models.Generated.Automation.User();
                }

                UserInfo.Username = Username;
                UserInfo.Name     = Name;
                UserInfo.Family   = Family;
                UserInfo.Email    = Email;
                UserInfo.Address  = Address;
                UserInfo.Mobile   = Mobile;
                UserInfo.IsActive = true;
                UserInfo.LevelID  = LevelID;

                if (Business.FacadeAutomation.GetUsersBusiness().IsDuplicatedUsername(Username, ID) == true)
                {
                    throw new Exception(Resources.Texts.DuplicatedUsername);
                }

                if (ID == 0)
                {
                    var password = values["Password"].ToString();
                    UserInfo.salt     = Guid.NewGuid();
                    UserInfo.Password = MethodExtension.GetMd5Hash(password + UserInfo.salt);
                }

                UserInfo.Save();

                #region SaveRoles

                var NewUserRole = new List <Data.Models.Generated.Automation.UserRole>();

                foreach (var item in RoleIDs)
                {
                    var node = new Data.Models.Generated.Automation.UserRole();
                    node.UserID = UserInfo.ID;
                    node.RoleID = item.ToLong();
                    NewUserRole.Add(node);
                }

                Business.FacadeAutomation.GetSPBusiness().SP_DeleteOldRoles(UserInfo.ID);

                foreach (var item in NewUserRole)
                {
                    item.Save();
                }

                #endregion

                Business.FacadeAutomation.GetVwUserPrivilegeRoleBusiness().RefreshCache();

                return(new string[2] {
                    "1", Resources.Texts.Success
                });
            }
            catch (Exception ex)
            {
                return(new string[2] {
                    "0", ex.Message
                });
            }
        }