예제 #1
0
        private static User DecryptUserData(MinifiedUser user)
        {
            try
            {
                //get user data from userData prop, and decrypt it;
                string userData = StEncrypter.Decrypt4Web(user.userData);
                //split the params to an array;
                string[] arr = userData.Split(new string[] { "|*|" }, StringSplitOptions.None);
                //get params. note, that EVERY CHANGE on the encrypted string should also reflect to that method!
                int    iEmployeeID   = int.Parse(arr[0]);
                string sEmployeeName = arr[1];

                User oUser = new User()
                {
                    EmployeeID   = iEmployeeID,
                    EmployeeName = sEmployeeName
                };

                return(oUser);
            }
            catch
            {
                return(null);
            }
        }
예제 #2
0
        internal bool CheckLogin()
        {
            //implement login check on db;
            DB   oData = new DB();
            User oUser = null;

            //something like:

            try
            {
                //check db for user and pass
                oUser = oData.Login(this.m_loginProps.userName, this.m_loginProps.password);
            }
            catch (Exception e)
            {
                if (e.Message.Contains("Sequence contains no elements"))
                {
                    this.m_loginStatusCode = LoginStatus.NoSuchUserExists;
                }
                else
                {
                    this.m_loginStatusCode = LoginStatus.GeneralError;
                    this.m_loginMessage    = e.Message;
                }

                return(false);
            }

            //** DEBUG: **
            // oUser = new User() { EmployeeID = 1, EmployeeName = "shimmi" };

            if (oUser == null)
            {
                this.m_loginStatusCode = LoginStatus.NoSuchUserExists;
                return(false);
            }
            else
            {
                //if user is logged on, add user to m_inforUser
                //create a string of user data params.
                //note, that EVERY CHANGE on the encrypted string should also reflect to UserHelper.DecryptUserData() method!
                string userData = oUser.EmployeeID.ToString() + "|*|" + oUser.EmployeeName.ToString();

                userData = StEncrypter.Encrypt4Web(userData);

                this.m_User = new MinifiedUser()
                {
                    userName    = this.m_loginProps.userName,
                    contactName = HttpUtility.UrlEncode(oUser.EmployeeName.ToString()),
                    userData    = userData,
                    persistent  = this.m_loginProps.rememberMe
                };

                this.m_loginStatusCode = LoginStatus.OK;

                return(true);
            }
        }
예제 #3
0
        /// <summary>
        /// get a 'minified' user and convert it to TenderUser class
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static object GetCurrentUser(bool minified = false)
        {
            try
            {
                //forms authentication: this way returns the current logged on user
                string userName = System.Web.HttpContext.Current.User.Identity.Name;

                if (!string.IsNullOrEmpty(userName))    //only if user is logged via forms authentication
                {
                    System.Web.HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies.Get("UserData");

                    if (cookie != null)
                    {
                        //return current user from cookie
                        MinifiedUser oUser = Newtonsoft.Json.JsonConvert.DeserializeObject <MinifiedUser>(cookie.Value);
                        if (!minified)
                        {
                            User oTenderUser = UserHelper.DecryptUserData(oUser);
                            return(oTenderUser);
                        }
                        else
                        {
                            return(oUser);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }