Exemple #1
0
        public HttpResponseMessage ChangePassword(ChangePasswordModel changepassword)
        {
            HttpResponseMessage response = null;

            try
            {
                Employee employee      = EmployeeRepo.GetEmployeeById(changepassword.employee_id);
                User     user_instance = LeaveRepo.GetUserById(employee.user_id);
                if (user_instance.is_active == 1)
                {
                    if (changepassword.new_password == changepassword.confirm_password)
                    {
                        if (changepassword.oldpassword == changepassword.new_password)
                        {
                            response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_515", "Current Password and New password should be different", "Current Password and New password should be different"));
                        }
                        else if (EncryptPassword.CalculateHash(changepassword.oldpassword) == user_instance.password)
                        {
                            user_instance.password = EncryptPassword.CalculateHash(changepassword.new_password);
                            LeaveRepo.EditUserPassword(user_instance);
                            string user_name = employee.first_name + " " + employee.last_name;
                            MailHandler.ChangePasswordIntimation(user_name, employee.email);
                            response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_001", "Password changed sucessfully", "Password changed sucessfully"));
                        }
                        else
                        {
                            response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_514", "Invalid Current Password", "Invalid Current Password"));
                        }
                    }
                    else
                    {
                        response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_302", "New Password and Confirm Password should be same", "New Password and Confirm Password should be same"));
                    }
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_303", "Access Denied", "Access Denied"));
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                Debug.WriteLine(exception.GetBaseException());
                response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_101", "Application Error", exception.Message));
            }
            return(response);
        }
Exemple #2
0
        public HttpResponseMessage ForgotPassword(ChangePasswordModel forgotpassword)
        {
            HttpResponseMessage response = null;

            try
            {
                Employee employee = EmployeeRepo.GetEmployeeById(forgotpassword.employee_id);
                User     user     = CommonRepo.GetuserById(employee.user_id);
                if (user.is_active == 1)
                {
                    if (forgotpassword.new_password == forgotpassword.confirm_password)
                    {
                        user.password = EncryptPassword.CalculateHash(forgotpassword.new_password);
                        CommonRepo.EditUserDetails(user);
                        string user_name = employee.first_name + " " + employee.last_name;
                        MailHandler.ChangePasswordIntimation(user_name, employee.email);
                        response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_001", "your password has been changed successfully", "your password has been changed successfully"));
                    }
                    else
                    {
                        response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_302", "New Password and Confirm Password should be same", "New Password and Confirm Password should be same"));
                    }
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_303", "Access Denied", "Access Denied"));
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                Debug.WriteLine(exception.GetBaseException());
                response = Request.CreateResponse(HttpStatusCode.OK, exception.Message);
            }
            return(response);
        }