Beispiel #1
0
 public ResponseResult SaveUsers(User u)
 {
     try
     {
         String msg;
         u.Password = PasswordSaltedHashingUtility.HashPassword("123");
         var result = DataService.SaveUsers(u, DateTime.UtcNow, SessionManager.CurrentUser.UserId);
         if (result > 0)
         {
             if (u.UserId > 0)
             {
                 msg = "User Updated Successfully";
             }
             else
             {
                 msg = "User Added Successfully";
             }
             return(ResponseResult.GetSuccessObject(new
             {
                 UserId = result,
             }, msg));
         }
         else
         {
             return(ResponseResult.GetErrorObject());
         }
     }
     catch (Exception ex)
     {
         CustomUtility.HandleException(ex);
         return(ResponseResult.GetErrorObject());
     }
 }
Beispiel #2
0
        //public Object SignOut(Boolean pManualEclockLogout)
        //{
        //    try
        //    {
        //        SessionManager.CurrentUser = null;
        //        SessionManager.AbandonSession();
        //        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        //        HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddSeconds(-1));
        //        HttpContext.Current.Response.Cache.SetNoStore();

        //        if (HttpContext.Current.Request.Cookies["breadcrumbs"] != null)
        //        {
        //            HttpCookie myCookie = new HttpCookie("breadcrumbs");
        //            myCookie.Expires = DateTime.UtcNow.AddDays(-1d);
        //            HttpContext.Current.Response.Cookies.Add(myCookie);
        //        }

        //        return ResponseResult.GetSuccessObject();

        //        //var result = new
        //        //{
        //        //    success = true,
        //        //    error = ""
        //        //};

        //        //return (result);

        //    }
        //    catch (Exception ex)
        //    {
        //        CustomUtility.HandleException(ex);
        //        return ResponseResult.GetErrorObject("Email not correct");
        //    }
        //}

        public ResponseResult ResetPassword(PasswordEntity pass)
        {
            if (PUCIT.AIMRL.SFP.UI.Common.SessionManager.LogsInAsOtherUser == true)
            {
                return(ResponseResult.GetErrorObject("You Are Not Allowed"));
            }
            try
            {
                var password = pass.NewPassword;
                if (GlobalDataManager.IgnoreHashing == false)
                {
                    password = PasswordSaltedHashingUtility.HashPassword(pass.NewPassword);
                }

                var flag = DataService.UpdatePassword(pass.Token, "", password, 0, DateTime.UtcNow, false);

                if (flag)
                {
                    return(ResponseResult.GetSuccessObject(null, "Password is reset"));
                }
                else
                {
                    return(ResponseResult.GetErrorObject("Reset is failed"));
                }
            }
            catch (Exception ex)
            {
                CustomUtility.HandleException(ex);
                return(ResponseResult.GetErrorObject());
            }
        }
        public ResponseResult ChangePassword(PasswordEntity pass)
        {
            try
            {
                if (PUCIT.AIMRL.WebAppName.UI.Common.SessionManager.LogsInAsOtherUser == true)
                {
                    return(ResponseResult.GetErrorObject("You Are Not Allowed"));
                }
                if (GlobalDataManager.IgnoreHashing == false)
                {
                    pass.CurrentPassword = PasswordSaltedHashingUtility.HashPassword(pass.CurrentPassword);
                    pass.NewPassword     = PasswordSaltedHashingUtility.HashPassword(pass.NewPassword);
                }

                var userObj = SessionManager.CurrentUser;

                var isSuccess = DataService.UpdatePassword(userObj.Login, pass.CurrentPassword, pass.NewPassword, userObj.UserId, DateTime.UtcNow, true);

                if (isSuccess == false)
                {
                    return(ResponseResult.GetErrorObject("Password Change Failure."));
                }
                else
                {
                    return(ResponseResult.GetSuccessObject(new
                    {
                        Id = isSuccess
                    }, "Password is changed"));
                }
            }
            catch (Exception ex)
            {
                CustomUtility.HandleException(ex);
                return(ResponseResult.GetErrorObject());
            }
        }
Beispiel #4
0
        public ResponseResult ValidateUser(String login, String pPassword, String pEmail, Boolean pIgnorePassword, Boolean pLoginAsOtherUser)
        {
            //Object dataToReturn = null;
            //Check to see if the user is provided the rights on the application
            try
            {
                var ipAddress = HttpContext.Current.Request.UserHostAddress.ToString();
                var currTime  = DateTime.UtcNow;

                if (pLoginAsOtherUser == true && SessionManager.IsUserLoggedIn == true)
                {
                    SessionManager.LogsInAsOtherUser = true;
                    SessionManager.ActualUserUserID  = SessionManager.CurrentUser.UserId;
                    SessionManager.ActualUserLoginID = SessionManager.CurrentUser.Login;
                }
                else
                {
                    SessionManager.LogsInAsOtherUser = false;
                    SessionManager.ActualUserUserID  = 0;
                    SessionManager.ActualUserLoginID = "";
                }
                if (pEmail != "")
                {
                    pIgnorePassword = true;
                }
                else
                {
                    if (GlobalDataManager.IgnoreHashing == false)
                    {
                        pPassword = PasswordSaltedHashingUtility.HashPassword(pPassword);
                    }
                }
                var secUserForSession = DataService.ValidateUserSP(login, pPassword, pEmail, currTime, ipAddress, pIgnorePassword, SessionManager.ActualUserLoginID);

                if (secUserForSession != null)
                {
                    if (secUserForSession.IsActive == false)
                    {
                        CustomUtility.LogData("User Is Inactive, can't log in");
                        SessionManager.CurrentUser = null;
                        return(ResponseResult.GetErrorObject("Your account is not active, Please Contact Administrator"));
                    }
                    else if (secUserForSession.IsDisabledForLogin == true)
                    {
                        SessionManager.CurrentUser = null;
                        return(ResponseResult.GetErrorObject("Your account is disabled, Please Contact Administrator"));
                    }
                    else
                    {
                        PermissionManager.HandlePermissions(secUserForSession.Permissions);
                        secUserForSession.Permissions = null;


                        SessionManager.CurrentUser = secUserForSession;

                        var RedirectURl = Resources.PAGES_MANAGERS_DEFAULT_HOME_PAGE_SFP;
                        RedirectURl = RedirectURl.Replace("~/", "");

                        return(ResponseResult.GetSuccessObject(new
                        {
                            redirect = RedirectURl
                        }));
                    }
                }

                else
                {
                    //If the user was not detected as an authorized user
                    CustomUtility.LogData("Invalid Login: "******" Password: "******"Invalid Login/Password"));
                }
            }
            catch (Exception ex)
            {
                CustomUtility.HandleException(ex);
                SessionManager.CurrentUser = null;
                return(ResponseResult.GetErrorObject());
            }
        }