public Result SelfPasswordChange(ChangePasswordModel changePassword)
        {
            try
            {
                result          = new Result();
                result.isSucess = false;
                Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues();
                int userGroupId = Convert.ToInt32(dictionary[6].Id == "" ? 0 : Convert.ToInt32(dictionary[6].Id));

                if (userGroupId != 0)
                {
                    int    userId   = Convert.ToInt32(dictionary[3].Id);
                    string userName = dictionary[4].Id;
                    _userFactory = new UserFactory();
                    bool status = _userFactory.GetAll().Any(x => x.UserName == userName && x.UserGroupID == userGroupId);
                    if (status == true)
                    {
                        SEC_UserInformation tblUserInformation;
                        tblUserInformation = _userFactory.FindBy(x => x.ID == userId).FirstOrDefault();
                        _passwordFactory   = new UserPasswordFactory();
                        Encription   encription  = new Encription();
                        SEC_Password tblPassword = _passwordFactory.GetAll().FirstOrDefault(x => x.ID == tblUserInformation.PasswordID);
                        if (tblPassword != null)
                        {
                            tblPassword.OldPassword   = tblPassword.NewPassword;
                            tblPassword.NewPassword   = encription.Encrypt(changePassword.NewPassword.Trim());
                            tblPassword.IsSelfChanged = true;
                            tblPassword.UpdatedDate   = DateTime.Now;
                            tblPassword.UpdatedBy     = userId;
                            _passwordFactory.Edit(tblPassword);
                        }
                        result = _passwordFactory.Save();
                        if (result.isSucess)
                        {
                            result.message = "Changed Password Sucessfully";
                            return(result);
                        }
                    }
                    result.message = "Password not Changed try again";
                    return(result);
                }
                result.message = "LogOut";
            }
            catch (Exception exception)
            {
                result.isSucess = false;
                result.message  = exception.Message;
            }
            return(result);
        }
Esempio n. 2
0
        //public SecurityFactorys(ICBSEntities context)
        //{
        //    this.context = context;
        //}
        public LogInStatus CheckLogIn(LogOnModel entity)
        {
            LogInStatus _LogInStatus         = new LogInStatus();
            Dictionary <string, string> list = new Dictionary <string, string>();
            Encription encription            = new Encription();

            try
            {
                _loginStatusFactory = new LoginStatusFactory();
                _userFactory        = new UserFactory();

                //var data = _userFactory.GetAll().ToList();

                //TBLA_USER_INFORMATION tblUserInformation = _userFactory.FindBy(x => x.UserName == entity.UserName && x.IsActive == true && x.TBLB_COMPANY.Code.ToLower() == entity.Company.ToLower()).FirstOrDefault();
                SEC_UserInformation tblUserInformation = _userFactory.FindBy(x => x.UserName == entity.UserName && x.CompanyID == entity.CompanyID && x.BranchID == entity.BranchID && x.IsActive == true).FirstOrDefault();
                if (tblUserInformation != null)
                {
                    SEC_LoginStatus logInStatus = _loginStatusFactory.FindBy(x => x.UserID == tblUserInformation.ID).FirstOrDefault();
                    if (logInStatus != null)
                    {
                        if (logInStatus.ForcedLogOutStatus == true)
                        {
                            _LogInStatus.IsAllowed = false;
                            _LogInStatus.Message   = "The Page is Under maintenance";
                        }
                        else
                        {
                            _userPasswordFactory = new UserPasswordFactory();
                            SEC_Password tblPassword = _userPasswordFactory.FindBy(x => x.ID == tblUserInformation.PasswordID).FirstOrDefault();
                            if (tblPassword != null && encription.Decrypt(tblPassword.NewPassword).Trim() == (entity.Password.Trim()))
                            {
                                {
                                    list.Add("UserId", tblUserInformation.ID.ToString());
                                    list.Add("UserName", tblUserInformation.UserName);
                                    list.Add("Name", tblUserInformation.UserFullName);
                                    list.Add("UserEmployee", tblUserInformation.EmployeeID.ToString());
                                    list.Add("UserCompany", tblUserInformation.CompanyID.ToString());
                                    list.Add("UserBranch", tblUserInformation.BranchID.ToString());

                                    _LogInStatus.IsAllowed = true;
                                    _LogInStatus.Status    = list;
                                    _LogInStatus.Message   = "Login Successfully";
                                }
                            }
                            else
                            {
                                _LogInStatus.IsAllowed = false;
                                _LogInStatus.Message   = "Password or User Name does not match";
                            }
                        }
                    }
                    else
                    {
                        _userPasswordFactory = new UserPasswordFactory();
                        SEC_Password tblPassword = _userPasswordFactory.FindBy(x => x.ID == tblUserInformation.PasswordID).FirstOrDefault();
                        if (tblPassword != null && encription.Decrypt(tblPassword.NewPassword).Trim() == (entity.Password.Trim()))
                        {
                            {
                                list.Add("UserId", tblUserInformation.ID.ToString());
                                list.Add("UserName", tblUserInformation.UserName);
                                list.Add("Name", tblUserInformation.UserFullName);
                                list.Add("UserEmployee", tblUserInformation.EmployeeID.ToString());
                                list.Add("UserCompany", tblUserInformation.CompanyID.ToString());
                                list.Add("UserBranch", tblUserInformation.BranchID.ToString());

                                _LogInStatus.IsAllowed = true;
                                _LogInStatus.Status    = list;
                                _LogInStatus.Message   = "Login Successfully";
                            }
                        }
                        else
                        {
                            _LogInStatus.IsAllowed = false;
                            _LogInStatus.Message   = "Password or User Name not matching";
                        }
                    }
                }
                else
                {
                    _LogInStatus.IsAllowed = false;
                    _LogInStatus.Message   = "User are not exist";
                }

                return(_LogInStatus);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
        private JsonResult CreateUser(UserModel user, int userId)
        {
            result           = new Result();
            _questionFactory = new QuestionFactory();
            _passwordFactory = new UserPasswordFactory();

            var question = new SEC_SecurityQuestion();

            question.ID = Guid.NewGuid();
            question.SecurityQuestion = user.SecurityQuestion;
            question.SecutiryAnswer   = user.SecurityQueAns;
            question.CreatedBy        = userId;
            question.CreatedDate      = DateTime.Now;

            _questionFactory.Add(question);
            result = _questionFactory.Save();

            var password = new SEC_Password();

            if (result.isSucess)
            {
                var encription = new Encription();
                password.ID            = Guid.NewGuid();
                password.NewPassword   = encription.Encrypt(user.Password);
                password.OldPassword   = "";
                password.IsSelfChanged = false;
                password.CreatedBy     = userId;
                password.CreatedDate   = DateTime.Now;
                _passwordFactory.Add(password);
                result = _passwordFactory.Save();
            }
            var userInformation = new SEC_UserInformation();

            //userInformation.ID = Guid.NewGuid();
            if (result.isSucess)
            {
                userInformation.EmployeeID         = user.EmployeeID;
                userInformation.CompanyID          = user.CompanyID;
                userInformation.BranchID           = user.BranchID;
                userInformation.UserFullName       = user.UserFullName;
                userInformation.UserName           = user.UserName.ToLower().Trim();
                userInformation.Address            = user.Address;
                userInformation.Email              = user.EMail;
                userInformation.PhoneNo            = user.PhoneNo;
                userInformation.SecurityQuestionID = question.ID;
                userInformation.PasswordID         = password.ID;
                userInformation.IsEMailVerified    = false;
                userInformation.IsPhoneNoVerified  = false;
                userInformation.IsActive           = true;
                userInformation.CreatedBy          = userId;
                userInformation.CreatedDate        = DateTime.Now;
                userInformation.UserGroupID        = user.UserGroupID;
                _userFactory.Add(userInformation);
                result = _userFactory.Save();
            }

            if (result.isSucess)
            {
                result.message = result.SaveSuccessfull(tableName);
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }