Ejemplo 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);
     }
 }
Ejemplo 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
                });
            }
        }
Ejemplo 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
                });
            }
        }
Ejemplo 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
                });
            }
        }
Ejemplo n.º 5
0
        public IActionResult Sign([FromQuery] string token)
        {
            var raw      = string.Empty;
            var unixtime = MethodExtension.GetTimestamp();

            using (var stream = new StreamReader(HttpContext.Request.Body))
            {
                raw = stream.ReadToEnd();
            }

            var sign = ASEService.ToMD5($"{raw}{unixtime}{token}").ToLower();

            var result = new Result
            {
                Token    = token,
                UnixTime = unixtime.ToString(),
                Sign     = sign
            };

            return(new JsonResult(result));
        }
Ejemplo n.º 6
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
                });
            }
        }
Ejemplo n.º 7
0
    protected override void OnLoad()
    {
        base.OnLoad();
        //load data from setting data
        BaseData_ItemTable.Instance.LoadDataFromSettingTable();

        //create some item data(from network server)
        CreateSomeItemData();


        foreach (int item in Enum.GetValues(typeof(ItemModule.EnumMainType)))
        {
            if (item == 0)
            {
                continue;
            }
            string typeName = Enum.GetName(typeof(ItemModule.EnumMainType), item);
            ItemModule.EnumMainType temp = (ItemModule.EnumMainType)Enum.Parse(typeof(ItemModule.EnumMainType), typeName);
            int num = UnityEngine.Random.Range(3, 5);
            //Debug.Log(num);
            for (int i = 0; i < num; i++)
            {
                ItemModule.ItemData itemModile = _itemData[UnityEngine.Random.Range(0, _itemData.Count)]._ItemData;
                //tableDic[temp][i] = itemModile;
                //tableDic[temp][i]._ItemData = MethodExtension.DeepClone(itemModile);
                tableDic[temp][i] = new ItemModule()
                {
                    _ItemData = MethodExtension.DeepClone(itemModile)
                };

                //Debug.Log(_listItem.Count);
            }
            //for (int i = num; i < tableDic[temp].Length - num; i++)
            //{
            //    tableDic[temp][i] = new ItemModule() { _ItemData = new ItemModule.ItemData() };
            //    Debug.Log(tableDic[temp][i]._ItemData == null);
            //}
        }
    }
Ejemplo n.º 8
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
                });
            }
        }
Ejemplo n.º 9
0
    public void AddImageNum(ItemModule.ItemData itemData, ItemModule.EnumMainType mainType, uint count = 1)
    {
        //Debug.Log(itemData);

        if (itemData.Num < 20)
        {
            itemData.Num += count;
        }
        else
        {
            for (int i = 0; i < tableDic[mainType].Length; i++)
            {
                //Debug.Log("==");
                if (tableDic[mainType][i] == null)
                {
                    continue;
                }
                else if (tableDic[mainType][i]._ItemData.Id == itemData.Id && tableDic[mainType][i]._ItemData.Num < 20)
                {
                    AddImageNum(tableDic[mainType][i]._ItemData, mainType);
                    return;
                }
            }
            for (int i = 0; i < tableDic[mainType].Length; i++)
            {
                //Debug.Log("addNull");
                if (tableDic[mainType][i] == null || tableDic[mainType][i]._ItemData.Num == 0)
                {
                    tableDic[mainType][i] = new ItemModule()
                    {
                        _ItemData = MethodExtension.DeepClone <ItemModule.ItemData>(itemData)
                    };
                    tableDic[mainType][i]._ItemData.Num = count;
                    return;
                }
            }
        }
    }
Ejemplo n.º 10
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
                });
            }
        }
Ejemplo n.º 11
0
        protected override async Task <AuthenticateResult> HandleAuthenticateAsync()
        {
            AuthenticationHeaderValue authHeader;

            if (!AuthenticationHeaderValue.TryParse(Request.Headers["Authorization"], out authHeader))
            {
                return(AuthenticateResult.Fail("Get Out"));
            }

            var schema = authHeader.Scheme;
            var token  = authHeader.Parameter;

            string[] credentials;

            if (schema.Equals("Basic", StringComparison.OrdinalIgnoreCase))
            {
                byte[] bytes = Convert.FromBase64String(token);
                credentials = Encoding.UTF8.GetString(bytes).Split(":");
                if (credentials.Length != 2)
                {
                    return(AuthenticateResult.Fail("Get Out"));
                }

                var clientId       = credentials[0];
                var clientPassword = credentials[1];

                if (!await _auth.CheckClientCredential(clientId, clientPassword))
                {
                    return(AuthenticateResult.Fail("Get Out"));
                }

                string[] userArray = new string[] { clientId, clientPassword, MethodExtension.GetTimestamp().ToString() };
                var      claims    = new List <Claim>()
                {
                    new Claim(ClaimTypes.Name, clientId),
                    new Claim(ClaimTypes.NameIdentifier, clientPassword),
                    new Claim("Token", MethodExtension.EncryptToken(userArray))
                };
                var identify = new ClaimsIdentity(claims, nameof(OAuthHandler));
                var ticket   = new AuthenticationTicket(new ClaimsPrincipal(identify), Scheme.Name);

                return(AuthenticateResult.Success(ticket));
            }

            if (schema.Equals("Bearer", StringComparison.OrdinalIgnoreCase))
            {
                credentials = MethodExtension.DecryptToken(token).Split(':');
                if (credentials.Count() < 3)
                {
                    return(AuthenticateResult.Fail("Get Out"));
                }
                var clientId       = credentials[0];
                var clientPassword = credentials[1];
                var timestamp      = credentials[2];

                if (!await _auth.CheckClientCredential(clientId, clientPassword))
                {
                    return(AuthenticateResult.Fail("Get Out"));
                }

                if (!MethodExtension.CheckTimestamp(timestamp, 60))
                {
                    return(AuthenticateResult.Fail("Get Out"));
                }

                var claims = new List <Claim>()
                {
                    new Claim(ClaimTypes.Name, clientId),
                    new Claim(ClaimTypes.NameIdentifier, clientPassword)
                };
                var identify = new ClaimsIdentity(claims, nameof(OAuthHandler));
                var ticket   = new AuthenticationTicket(new ClaimsPrincipal(identify), Scheme.Name);

                return(AuthenticateResult.Success(ticket));
            }
            return(AuthenticateResult.NoResult());
        }