Пример #1
0
    public static void LogError(ErrorCode pCode, string pStackTrace = null, string pErrorMessage = null)
    {
        ErrorLogTableAdapter logAdapter = new ErrorLogTableAdapter();
        bool addedRow = false;

        if (HttpContext.Current.User.Identity.IsAuthenticated)
        {
            SysUserTableAdapter          adapter = new SysUserTableAdapter();
            ONyRDataSet.SysUserDataTable table   = adapter.GetDataByUserName(HttpContext.Current.User.Identity.Name);

            if (table.Count > 0)
            {
                logAdapter.ErrorLog(table[0].ID, (int)pCode, pStackTrace, pErrorMessage);
                addedRow = true;
            }

            adapter.Dispose();
            table.Dispose();
        }

        if (!addedRow)
        {
            logAdapter.ErrorLog(null, (int)pCode, pStackTrace, pErrorMessage);
        }

        logAdapter.Dispose();
    }
Пример #2
0
    public List <UserVO> RemoveUsers(UserVO[] pUser)
    {
        List <UserVO> result = new List <UserVO>();

        try
        {
            AuthenticationService.CheckIfUSerIsAuthenticated();
            SysUserTableAdapter adapter = new SysUserTableAdapter();
            string logParams            = "";

            foreach (UserVO vo in pUser)
            {
                if (logParams.Length > 0)
                {
                    logParams += ",\n";
                }

                adapter.Delete(vo.ID);
                result.Add(vo);

                logParams += String.Format("UserName: \"{0}\", Title: \"{1}\", FirstName: \"{2}\", MiddleName: \"{3}\", LastName: \"{4}\", MothersMaidenName: \"{5}\", EMail: \"{6}\", IdentityCardNumber: \"{7\", LastLogin: \"{8}\", ID: {9}", vo.UserName, vo.Title, vo.FirstName, vo.MiddleName, vo.LastName, vo.MothersMaidenName, vo.EMail, vo.IdentityCardNumber, vo.LastLogin, vo.ID);
            }

            adapter.Dispose();

            LogService.Log("UserService", "RemoveUser", logParams);
        }
        catch (ONyRException e)
        {
            LogService.LogError(e.ErrorCode, e.StackTrace);
            throw new FaultException <ONyRFaultException>(new ONyRFaultException((int)e.ErrorCode));
        }
        catch (SqlException ex)
        {
            if (ex.Class == 16)
            {
                LogService.LogError(ErrorCode.ReferenceError, ex.StackTrace);
                throw new FaultException <ONyRFaultException>(new ONyRFaultException((int)ErrorCode.ReferenceError));
            }
            string s = "Class: " + ex.Class + "\n";
            for (int i = 0; i < ex.Errors.Count; i++)
            {
                s += "Index #" + i + "\n" +
                     "Message: " + ex.Errors[i].Message + "\n" +
                     "LineNumber: " + ex.Errors[i].LineNumber + "\n" +
                     "Source: " + ex.Errors[i].Source + "\n" +
                     "Procedure: " + ex.Errors[i].Procedure + "\n" +
                     "Class: " + ex.Errors[i].Class + "\n";
            }
            LogService.LogError(ErrorCode.UnknownError, null, s);
            throw new FaultException <ONyRFaultException>(new ONyRFaultException((int)ErrorCode.DatabaseError));
        }
        catch (Exception e)
        {
            LogService.LogError(ErrorCode.UnknownError, e.StackTrace, e.Message);
            throw new FaultException <ONyRFaultException>(new ONyRFaultException((int)ErrorCode.UnknownError));
        }

        return(result);
    }
Пример #3
0
    public static void ChangePassword(string pOldPassword, string pNewPassword)
    {
        int userID = Convert.ToInt32(HttpContext.Current.Request.Cookies["UserId"].Value);

        SysUserTableAdapter adapter = new SysUserTableAdapter();
        int i = adapter.ModifyPassword(pNewPassword, pOldPassword, userID);

        if (i == 0)
        {
            throw new ONyRException(ErrorCode.InvalidCredentialsError);
        }
    }
Пример #4
0
    public static bool authenticate(string userName, string password)
    {
        bool   result      = false;
        string encodedPass = hashPassword(password);

        SysUserTableAdapter userAdapter = new SysUserTableAdapter();

        result = (int)userAdapter.CheckUser(userName, encodedPass) != 0;
        userAdapter.Dispose();

        LogService.Log("AuthenticationService", "authenticate", String.Format("username:{0}; result:{1}", userName, result));

        return(result);
    }
Пример #5
0
    public static void CreationCookie(object sender, System.Web.ApplicationServices.CreatingCookieEventArgs e)
    {
        ONyRDataSet.SysUserDataTable    users;
        ONyRDataSet.SysSessionDataTable sessions;
        ONyRDataSet.SysSessionRow       session;

        SysUserTableAdapter userAdapter = new SysUserTableAdapter();

        users = userAdapter.GetDataByUserName(e.UserName);

        if (users.Count == 0)
        {
            throw new ONyRException(ErrorCode.InvalidCredentialsError);
        }

        ONyRDataSet.SysUserRow user = users[0];

        SysSessionTableAdapter sessionAdapter = new SysSessionTableAdapter();

        sessions = sessionAdapter.GetDataByUserID(user.ID);

        foreach (ONyRDataSet.SysSessionRow row in sessions)
        {
            sessionAdapter.Delete1(row.ID);
        }

        sessionAdapter.CreateSession(user.ID);
        sessions = sessionAdapter.GetDataByUserID(user.ID);
        session  = sessions[0];
        sessionAdapter.Dispose();

        userAdapter.UpdateLoginDate(user.ID);
        userAdapter.Dispose();

        HttpContext.Current.Response.Cookies.Add(new HttpCookie("UserId", user.ID.ToString()));
        HttpContext.Current.Response.Cookies.Add(new HttpCookie("SessionId", session.ID.ToString()));
    }
Пример #6
0
    public List <UserVO> LoadUsers(UserFilter pFilter, int pId = -1, int[] pIds = null)
    {
        List <UserVO> result = null;

        try
        {
            AuthenticationService.CheckIfUSerIsAuthenticated();
            LogService.Log("UserService", "LoadUser", String.Format("Filter:{0}; ID:{1}; IDs: {2}", pFilter, pId, pIds));

            SysUserTableAdapter          adapter = new SysUserTableAdapter();
            ONyRDataSet.SysUserDataTable table;
            result = new List <UserVO>();


            if (pFilter == UserFilter.All)
            {
                table = adapter.GetData();
            }
            else if (pFilter == UserFilter.ById)
            {
                table = adapter.GetDataByID(pId);
            }
            else if (pFilter == UserFilter.ByIds)
            {
                table = adapter.GetData();
            }
            else
            {
                throw new ONyRException(ErrorCode.UnknownError);
            }

            for (int i = 0; i < table.Count; ++i)
            {
                if (pFilter != UserFilter.ByIds || pIds.Contains(table[i].ID))
                {
                    string   title              = table[i].IsTitleNull() ? "" : table[i].Title;
                    string   middleName         = table[i].IsMiddleNameNull() ? "" : table[i].MiddleName;
                    string   mothersMaindenName = table[i].IsMothersMaindenNameNull() ? "" : table[i].MothersMaindenName;
                    DateTime lastLogin          = table[i].IsLastLoginNull() ? DateTime.MinValue : table[i].LastLogin;

                    result.Add(
                        new UserVO(
                            table[i].ID,
                            table[i].UserName,
                            title,
                            table[i].FirstName,
                            middleName,
                            table[i].LastName,
                            mothersMaindenName,
                            table[i].Email,
                            table[i].IdentityCardNumber,
                            lastLogin
                            )
                        );
                }
            }

            adapter.Dispose();
        }
        catch (ONyRException e)
        {
            LogService.LogError(e.ErrorCode, e.StackTrace);
            throw new FaultException <ONyRFaultException>(new ONyRFaultException((int)e.ErrorCode));
        }
        catch (SqlException ex)
        {
            string s = "Class: " + ex.Class + "\n";
            for (int i = 0; i < ex.Errors.Count; i++)
            {
                s += "Index #" + i + "\n" +
                     "Message: " + ex.Errors[i].Message + "\n" +
                     "LineNumber: " + ex.Errors[i].LineNumber + "\n" +
                     "Source: " + ex.Errors[i].Source + "\n" +
                     "Procedure: " + ex.Errors[i].Procedure + "\n" +
                     "Class: " + ex.Errors[i].Class + "\n";
            }
            LogService.LogError(ErrorCode.UnknownError, null, s);
            throw new FaultException <ONyRFaultException>(new ONyRFaultException((int)ErrorCode.DatabaseError));
        }
        catch (Exception e)
        {
            LogService.LogError(ErrorCode.UnknownError, e.StackTrace, e.Message);
            throw new FaultException <ONyRFaultException>(new ONyRFaultException((int)ErrorCode.UnknownError));
        }


        return(result);
    }
Пример #7
0
    public List <UserVO> ModifyUsers(UserVO[] pOriginalUser, UserVO[] pNewUser, bool isForced = false)
    {
        List <UserVO> result = new List <UserVO>();

        try
        {
            AuthenticationService.CheckIfUSerIsAuthenticated();
            SysUserTableAdapter adapter = new SysUserTableAdapter();
            string logParams            = "";
            bool   modifyConflict       = false;

            for (int i = 0; i < Math.Min(pOriginalUser.Length, pNewUser.Length); ++i)
            {
                ONyRDataSet.SysUserRow row = adapter.GetDataByID(pNewUser[i].ID)[0];

                string   title              = row.IsTitleNull() ? "" : row.Title;
                string   middleName         = row.IsMiddleNameNull() ? "" : row.MiddleName;
                string   mothersMaindenName = row.IsMothersMaindenNameNull() ? "" : row.MothersMaindenName;
                DateTime lastLogin          = row.IsLastLoginNull() ? DateTime.MinValue : row.LastLogin;

                UserVO vo = new UserVO(row.ID, row.UserName, title, row.FirstName, middleName, row.LastName, mothersMaindenName, row.Email, row.IdentityCardNumber, lastLogin);

                if (vo.Equals(pOriginalUser[i]) || isForced)
                {
                    if (logParams.Length > 0)
                    {
                        logParams += ",\n";
                    }
                    adapter.UpdateUser(pNewUser[i].UserName, pNewUser[i].Title, pNewUser[i].FirstName, pNewUser[i].MiddleName, pNewUser[i].LastName, pNewUser[i].MothersMaidenName, pNewUser[i].EMail, pNewUser[i].IdentityCardNumber, vo.ID);
                    logParams += String.Format("ID: \"{0}\" => \"{1}\", UserName: \"{2}\" => \"{3}\", Title: \"{4}\" => \"{5}\", FirstName: \"{6}\" => \"{7}\", MiddleName: \"{8}\" => \"{9}\", LastName: \"{10}\" => \"{11}\", MothersMaidenName: \"{12}\" => \"{13}\", EMail: \"{14}\" => \"{15}\", IdentityCardNumber: \"{16}\" => \"{17}\", LastLogin: \"{18}\" => \"{19}\"", vo.ID, pNewUser[i].ID, vo.UserName, pNewUser[i].UserName, vo.Title, pNewUser[i].Title, vo.FirstName, pNewUser[i].FirstName, vo.MiddleName, pNewUser[i].MiddleName, vo.LastName, pNewUser[i].LastName, vo.MothersMaidenName, pNewUser[i].MothersMaidenName, vo.EMail, pNewUser[i].EMail, vo.IdentityCardNumber, pNewUser[i].IdentityCardNumber, vo.LastLogin, pNewUser[i].LastLogin);

                    result.Add(new UserVO(vo.ID, pNewUser[i].UserName, pNewUser[i].Title, pNewUser[i].FirstName, pNewUser[i].MiddleName, pNewUser[i].LastName, pNewUser[i].MothersMaidenName, pNewUser[i].EMail, pNewUser[i].IdentityCardNumber, lastLogin));
                }
                else
                {
                    modifyConflict = true;
                }
            }

            adapter.Dispose();

            LogService.Log("UserService", "ModifyUser", logParams);

            if (modifyConflict)
            {
                throw new ONyRException(ErrorCode.ModifyConflict);
            }
        }
        catch (ONyRException e)
        {
            LogService.LogError(e.ErrorCode, e.StackTrace);
            throw new FaultException <ONyRFaultException>(new ONyRFaultException((int)e.ErrorCode));
        }
        catch (SqlException ex)
        {
            string s = "Class: " + ex.Class + "\n";
            for (int i = 0; i < ex.Errors.Count; i++)
            {
                s += "Index #" + i + "\n" +
                     "Message: " + ex.Errors[i].Message + "\n" +
                     "LineNumber: " + ex.Errors[i].LineNumber + "\n" +
                     "Source: " + ex.Errors[i].Source + "\n" +
                     "Procedure: " + ex.Errors[i].Procedure + "\n" +
                     "Class: " + ex.Errors[i].Class + "\n";
            }
            LogService.LogError(ErrorCode.UnknownError, null, s);
            throw new FaultException <ONyRFaultException>(new ONyRFaultException((int)ErrorCode.DatabaseError));
        }
        catch (Exception e)
        {
            LogService.LogError(ErrorCode.UnknownError, e.StackTrace, e.Message);
            throw new FaultException <ONyRFaultException>(new ONyRFaultException((int)ErrorCode.UnknownError));
        }

        return(result);
    }