"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4550],{"./public/app/features/profile/ChangePasswordPage.tsx":(e,s,a)=>{a.r(s),a.d(s,{ChangePasswordPage:()=>v,default:()=>P});a("./node_modules/react/index.js");var n,r,o=a("./node_modules/react-use/esm/useMount.js"),t=a("./node_modules/react-redux/es/index.js"),i=a("./public/app/core/selectors/navModel.ts"),d=a("./public/app/core/components/Page/Page.tsx"),c=a("./node_modules/@emotion/css/dist/emotion-css.esm.js"),u=a("./packages/grafana-ui/src/index.ts"),l=a("./public/app/core/config.ts"),p=a("./public/app/core/components/PasswordField/PasswordField.tsx"),w=a("./node_modules/react/jsx-runtime.js");const g=({user:e,onChangePassword:s,isSaving:a})=>{var o,t;const{ldapEnabled:i,authProxyEnabled:d,disableLoginForm:g}=l.ZP,f=(null===(o=e.authLabels)||void 0===o?void 0:o.length)&&e.authLabels[0];return i||d?n||(n=(0,w.jsx)("p",{children:"You cannot change password when LDAP or auth proxy authentication is enabled."})):f&&g?r||(r=(0,w.jsx)("p",{children:"Password cannot be changed here."})):(0,w.jsx)("div",{className:c.css`
        max-width: 400px;
      `,children:(0,w.jsx)(u.Form,{onSubmit:s,children:({register:e,errors:s,getValues:n})=>{var r,o,i;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(u.Field,{label:"Old password",invalid:!!s.oldPassword,error:null==s||null===(r=s.oldPassword)||void 0===r?void 0:r.message,children:(0,w.jsx)(p.Z,Object.assign({id:"current-password",autoComplete:"current-password"},e("oldPassword",{required:"Old password is required"})))}),(0,w.jsx)(u.Field,{label:"New password",invalid:!!s.newPassword,error:null==s||null===(o=s.newPassword)||void 0===o?void 0:o.message,children:(0,w.jsx)(p.Z,Object.assign({id:"new-password",autoComplete:"new-password"},e("newPassword",{required:"New password is required",validate:{confirm:e=>e===n().confirmNew||"Passwords must match",old:e=>e!==n().oldPassword||"New password can't be the same as the old one."}})))}),(0,w.jsx)(u.Field,{label:"Confirm password",invalid:!!s.confirmNew,error:null==s||null===(i=s.confirmNew)||void 0===i?void 0:i.message,children:(0,w.jsx)(p.Z,Object.assign({id:"confirm-new-password",autoComplete:"new-password"},e("confirmNew",{required:"New password confirmation is required",validate:e=>e===n().newPassword||"Passwords must match"})))}),(0,w.jsxs)(u.HorizontalGroup,{children:[t||(t=(0,w.jsx)(u.Button,{variant:"primary",disabled:a,children:"Change Password"})),(0,w.jsx)(u.LinkButton,{variant:"secondary",href:`${l.ZP.appSubUrl}/profile`,fill:"outline",children:"Cancel"})]})]})}})})};var f,h=a("./public/app/features/profile/state/actions.ts");const m={loadUser:h.II,changePassword:h.Cp};function v({navModel:e,loadUser:s,isUpdating:a,user:n,changePassword:r}){return(0,o.Z)((()=>s())),(0,w.jsx)(d.Z,{navModel:e,children:(0,w.jsx)(d.Z.Contents,{isLoading:!Boolean(n),children:n?(0,w.jsxs)(w.Fragment,{children:[f||(f=(0,w.jsx)("h3",{className:"page-heading",children:"Change Your Password"})),(0,w.jsx)(g,{user:n,onChangePassword:r,isSaving:a})]}):null})})}const P=(0,t.connect)((function(e){const s=e.user,{isUpdating:a,user:n}=s;return{navModel:(0,i.h)(e.navIndex,"change-password"),isUpdating:a,user:n}}),m)(v)},"./public/app/features/profile/state/actions.ts":(e,s,a)=>{a.d(s,{Cp:()=>t,hz:()=>u,PA:()=>i,II:()=>d,cc:()=>c,Lj:()=>l});var n=a("./packages/grafana-runtime/src/index.ts"),r=a("./public/app/features/profile/state/reducers.ts");const o={changePassword:async function(e){try{await(0,n.getBackendSrv)().put("/api/user/password",e)}catch(e){console.error(e)}},revokeUserSession:async function(e){await(0,n.getBackendSrv)().post("/api/user/revoke-auth-token",{authTokenId:e})},loadUser:function(){return(0,n.getBackendSrv)().get("/api/user")},loadSessions:function(){return(0,n.getBackendSrv)().get("/api/user/auth-tokens")},loadOrgs:function(){return(0,n.getBackendSrv)().get("/api/user/orgs")},loadTeams:function(){return(0,n.getBackendSrv)().get("/api/user/teams")},setUserOrg:async function(e){await(0,n.getBackendSrv)().post("/api/user/using/"+e.orgId,{})},updateUserProfile:async function(e){try{await(0,n.getBackendSrv)().put("/api/user",e)}catch(e){console.error(e)}}};function t(e){return async function(s){s((0,r.zc)({updating:!0})),await o.changePassword(e),s((0,r.zc)({updating:!1}))}}function i(){return async function(e){await e(d()),e((async function(e){e((0,r.qD)());const s=await o.loadTeams();e((0,r.PL)({teams:s}))})),e((async function(e){e((0,r.$S)());const s=await o.loadOrgs();e((0,r.Ns)({orgs:s}))})),e((async function(e){e((0,r.Uk)());const s=await o.loadSessions();e((0,r.z0)({sessions:s}))}))}}function d(){return async function(e){const s=await o.loadUser();e((0,r.aw)({user:s}))}}function c(e){return async function(s){s((0,r.zc)({updating:!0})),await o.revokeUserSession(e),s((0,r.p$)({tokenId:e}))}}function u(e){return async function(s){s((0,r.zc)({updating:!0})),await o.setUserOrg(e),window.location.href=n.config.appSubUrl+"/profile"}}function l(e){return async function(s){s((0,r.zc)({updating:!0})),await o.updateUserProfile(e),await s(d()),s((0,r.zc)({updating:!1}))}}},"./node_modules/react-use/esm/useMount.js":(e,s,a)=>{a.d(s,{Z:()=>r});var n=a("./node_modules/react-use/esm/useEffectOnce.js");const r=function(e){(0,n.Z)((function(){e()}))}}}]);
//# sourceMappingURL=4550.8128b05ac04b15cbf98d.js.map