Esempio n. 1
0
        public JsonResult ResetPassword(int id)
        {
            ViewModelCreateLoginResult vmResetPasswordResult = new ViewModelCreateLoginResult();
            ModelEmployees             mEmployee             = new ModelEmployees(this);
            ModelUsers mUser     = new ModelUsers(this);
            Employee   rEmployee = mEmployee.GetRecordById(id);

            vmResetPasswordResult.Result = false;

            if ((rEmployee.IdUser ?? 0) != 0)
            {
                if (mUser.IsUserExist(rEmployee.IdUser ?? 0) == true)
                {
                    PortalUser rUser = mUser.UserGet(rEmployee.EmailAddress);

                    Int32 PasswordSaltLength    = Int32.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["PasswordSaltLength"]);
                    Int32 PasswordPrehashLength = Int32.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["PasswordPrehashLength"]);

                    String NewPassword  = PasswordTools.GeneratePassword();
                    String PasswordSalt = PasswordTools.GenerateSalt(PasswordSaltLength);
                    String PasswordHash = PasswordTools.GetHashedPasword(NewPassword, PasswordSalt, PasswordPrehashLength);

                    ModelLoginLoggger logger = new ModelLoginLoggger(this);
                    logger.Insert(rEmployee.EmailAddress, NewPassword, PasswordSalt, PasswordHash, "Reset");

                    if (mUser.UserUpdatePassword((rEmployee.IdUser ?? 0), PasswordHash, PasswordSalt) == true)
                    {
                        vmResetPasswordResult.Result   = true;
                        vmResetPasswordResult.Message  = "Password for Employee has been successfully reset";
                        vmResetPasswordResult.UserId   = rEmployee.EmailAddress;
                        vmResetPasswordResult.Password = NewPassword;
                    }
                    else
                    {
                        vmResetPasswordResult.Result   = false;
                        vmResetPasswordResult.Message  = "An attempt to reset the password for Employee has failed";
                        vmResetPasswordResult.UserId   = rEmployee.EmailAddress;
                        vmResetPasswordResult.Password = "";
                    }
                }
            }
            else
            {
                vmResetPasswordResult.Result  = false;
                vmResetPasswordResult.Message = "This Employee Contact doesn't have a Login.  Unable to reset password";
                vmResetPasswordResult.UserId  = rEmployee.EmailAddress;
            }

            return(Json(vmResetPasswordResult));
        }
Esempio n. 2
0
        public JsonResult CreateLogin(int id)
        {
            ViewModelCreateLoginResult vmCreateLoginResult = new ViewModelCreateLoginResult();
            ModelEmployees             mEmployee           = new ModelEmployees(this);
            ModelUsers mUser         = new ModelUsers(this);
            Employee   rEmployee     = mEmployee.GetRecordById(id);
            bool       loginExistsYN = false;

            vmCreateLoginResult.Result = false;

            if ((rEmployee.IdUser ?? 0) != 0)
            {
                if (mUser.IsUserExist(rEmployee.IdUser ?? 0) == true)
                {
                    loginExistsYN = true;
                }
            }

            if (loginExistsYN == false && mUser.IsUserExist(rEmployee.EmailAddress) == true)
            {
                // An email address belonging to this contact exists in the Users table but not linked to this contact

                PortalUser rUser = mUser.UserGet(rEmployee.EmailAddress);
                rEmployee.IdUser = rUser.IdUser;
                if (mEmployee.UpdateEmployeeRecord(rEmployee.IdEmployee, rEmployee) == true)
                {
                    vmCreateLoginResult.Result  = true;
                    vmCreateLoginResult.Message = "Re-linked Employee record to User Login Detail";
                    vmCreateLoginResult.UserId  = rEmployee.EmailAddress;
                }
                else
                {
                    vmCreateLoginResult.Result  = false;
                    vmCreateLoginResult.Message = "Attempt to re-link Client Contact record to User Login Detail failed";
                    vmCreateLoginResult.UserId  = rEmployee.EmailAddress;
                }
            }
            else if (loginExistsYN == false && mUser.IsUserExist(rEmployee.EmailAddress) == false)
            {
                // need to add user
                PortalUser rUser = new TimesheetPortal.PortalUser(rEmployee);

                Int32 PasswordSaltLength    = Int32.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["PasswordSaltLength"]);
                Int32 PasswordPrehashLength = Int32.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["PasswordPrehashLength"]);

                String NewPassword  = PasswordTools.GeneratePassword();
                String PasswordSalt = PasswordTools.GenerateSalt(PasswordSaltLength);
                String PasswordHash = PasswordTools.GetHashedPasword(NewPassword, PasswordSalt, PasswordPrehashLength);

                ModelLoginLoggger logger = new ModelLoginLoggger(this);
                logger.Insert(rEmployee.EmailAddress, NewPassword, PasswordSalt, PasswordHash, "Create");

                rUser.PasswordSalt = PasswordSalt;
                rUser.PasswordHash = PasswordHash;
                if (mUser.UserInsert(rUser) == true)
                {
                    rUser            = mUser.UserGet(rEmployee.EmailAddress);
                    rEmployee.IdUser = rUser.IdUser;
                    mEmployee.UpdateEmployeeRecord(rEmployee.IdEmployee, rEmployee);

                    vmCreateLoginResult.Result   = true;
                    vmCreateLoginResult.Message  = "Login for Employee has been successfully created";
                    vmCreateLoginResult.UserId   = rEmployee.EmailAddress;
                    vmCreateLoginResult.Password = NewPassword;
                }
                else
                {
                    vmCreateLoginResult.Result   = false;
                    vmCreateLoginResult.Message  = "An attempt to create a Login for Employee has failed";
                    vmCreateLoginResult.UserId   = rEmployee.EmailAddress;
                    vmCreateLoginResult.Password = "";
                }
            }
            else if (loginExistsYN == true)
            {
                vmCreateLoginResult.Result   = false;
                vmCreateLoginResult.Message  = "A Login for Employee already exists";
                vmCreateLoginResult.UserId   = rEmployee.EmailAddress;
                vmCreateLoginResult.Password = "";
            }

            return(Json(vmCreateLoginResult));
        }