• User flagged to change password

    By Fernando Levi 1 decade ago

    Hello,

    If the user trying to login is flagged to change password, the dialog shows:

    You are logged in, but do not have access (unknown reasonType 8 )...

    What I did was, I changed the custom control code, adding the following lines above the }else{ that sets this message:

     

    }else if ( reasonNr == "8") {
    
       window.location.href = "#{javascript:compositeData.urlAfterLogin}";
    

    What happens now, is that the user is redirected to the standard change password form.

    It would be nicer, though, if an XPage dialog would popup to change password, replacing the standard form. I lack the theory to do this... Maybe you can help me with it.

    Regards

    Fernando

    • No problem

      By F. Kranenburg 1 decade ago

      Fernando,

      Several thing you could do. You could extend the control so it supports a password change form by supporting a new url parameter (I'll explain later), if this parameter is set, the control should display a password change form. You should set this up just like the login controls on the form. You will have to find out what POST data is being returned to the server after you changed your password.
      This data must be added to the form with new fields (I think these are three fields, old password and two new passwords). I think the server needs to know the username, old password and new password. After this create a clientside script that posts the new data using dojo.xhrPost (maybe use a new button to change password), just the same way as the current control does this.
      After a succesfull password change, let the user login by calling the url with the &logmein parameter so it pops up the 'normal' login dialog. Also, the new url parameter should popup the login control, and it should only show the password change form you just created. So add this url to the reasonType == 8 script.
      This is all theory but it should be possible. If you need help or have questions please ask!

      Ferry Kranenburg

       

      • Password change control

        By Andrew M Norrie 1 decade ago

        Hi Ferry,



        I have made use of your login custom control which is very very useful thanks! I saw the post here

        about extending it to replace the password change default form. I had a go at setting that up and it

        was surprisingly easy to do modifying your existing code. I haven't fully fixed all the bugs yet but I

        thought I'd put it here before I get too busy on something else. Hopefully this is useful for you or

        someone else.



        Change password custom control:



        <?xml version="1.0" encoding="UTF-8"?>

        <xp:view xmlns:xp="http://www.ibm.com/xsp/core" dojoTheme="true"

        dojoParseOnLoad=&quot;true&quot; &gt;<br/>
        &lt;xp:this.resources&gt;<br/>
            &lt;xp:dojoModule name=&quot;dijit.Dialog&quot;/&gt;<br/>
            &lt;xp:dojoModule name=&quot;dijit.form.TextBox&quot;/&gt;<br/>
            &lt;xp:dojoModule name=&quot;dijit.form.CheckBox&quot;/&gt;<br/>
            &lt;xp:dojoModule name=&quot;dijit.form.Button&quot;/&gt;<br/>
            &lt;xp:dojoModule name=&quot;dojo.cookie&quot;&gt;&lt;/xp:dojoModule&gt;<br/>
        


        &lt;/xp:this.resources&gt;<br/>
        


        &lt;xp:scriptBlock id=&quot;scr_ChangePassword&quot;&gt;<br/>
            &lt;xp:this.value&gt;&lt;![CDATA[function ChangePwd(data){<br/>
        

        var changepwdurl = '#{javascript:compositeData.urlChangePwdNSF;}';

            <br/>
        // disable btnChangePassword<br/>
        dojo.byId('#{id:btnChangePassword}').disabled=true;<br/>
            <br/>
        changepwdurl = changepwdurl.split('.nsf')[0] + '.nsf?changepassword';<br/>
            <br/>
        dojo.byId(&quot;divDlgMessage&quot;).display=&quot;block&quot;;<br/>
        dojo.byId(&quot;divDlgMessage&quot;).style.color=&quot;black&quot;;<br/>
        dojo.byId(&quot;divDlgMessage&quot;).style.backgroundColor=&quot;transparent&quot;;<br/>
        dojo.byId(&quot;divDlgMessage&quot;).innerHTML = &quot;Changing password ...&quot;;<br/>
            <br/>
        dojo.xhrPost({ <br/>
            url: changepwdurl,<br/>
            handleAs: &quot;text&quot;,<br/>
            content: {<br/>
                &quot;password&quot; : dojo.byId('#{id:password}').value,<br/>
                &quot;passwordnew&quot; : dojo.byId('#{id:passwordnew}').value,<br/>
                &quot;passwordconfirm&quot; : dojo.byId('#{id:passwordconfirm}').value<br/>
            },<br/>
            load : function(response, data) {<br/>
                var responseChgPwd = response;<br/>
                responseChgPwd.toLowerCase();<br/>
                    <br/>
               //This is checking against the default password change response. May need fixing if <br/>
               //a different one is put into domcfg.nsf (I haven't checked to see if the response is <br/>
        

        different)

                if (responseChgPwd.toLowerCase().indexOf('password change request <br/>
        

        submitted')!=-1) {

                <br/>
                   //Change submitted<br/>
                    dojo.byId(&quot;divDlgMessage&quot;).display=&quot;block&quot;;<br/>
                    dojo.byId(&quot;divDlgMessage&quot;).style.color=&quot;green&quot;;<br/>
                    dojo.byId(&quot;divDlgMessage&quot;).style.backgroundColor=&quot;transparent&quot;;<br/>
                    dojo.byId(&quot;divDlgMessage&quot;).innerHTML = &quot;Password successfully changed&quot;;<br/>
                    <br/>
                   //Close dialog<br/>
                    dojo.byId('#{id:password}').value = &quot;&quot;;<br/>
                    dojo.byId('#{id:passwordnew}').value = &quot;&quot;;<br/>
                    dojo.byId('#{id:passwordconfirm}').value = &quot;&quot;;<br/>
                    dojo.byId('divDlgMessage').innerHTML = &quot;&quot;;<br/>
                    dijit.byId('#{id:dialogChangePassword}').hide();<br/>
                        <br/>
                } else {<br/>
                    <br/>
                   //error<br/>
                    dojo.byId(&quot;divDlgMessage&quot;).display=&quot;block&quot;;<br/>
                    dojo.byId(&quot;divDlgMessage&quot;).style.color=&quot;red&quot;;<br/>
                    dojo.byId(&quot;divDlgMessage&quot;).style.backgroundColor=&quot;transparent&quot;;<br/>
                                   <br/>
                    if (responseChgPwd.toLowerCase().indexOf('input name' + '=\&quot;reasontype\&quot;')==-1) <br/>
        

        {

                       // response does not have a 'reasonType' field, display default FailMessage;<br/>
                        dojo.byId(&quot;divDlgMessage&quot;).innerHTML = '#<br/>
        

        {javascript:compositeData.FailMessage;}';

                    <br/>
                    }else{<br/>
                    <br/>
                        var reasonFail = <br/>
        

        responseChgPwd.toLowerCase().substring(responseChgPwd.toLowerCase().indexOf('input

        name' + '=\"reasontype\"'), (responseChgPwd.toLowerCase().indexOf('input name' +

        '=\"reasontype\"') + 80));

                        var reasonNr = reasonFail.substring(reasonFail.indexOf('value') + 7, <br/>
        

        (reasonFail.indexOf('value') + 8)) ;//last character will be the error

                        if ( reasonNr == &quot;2&quot;) {<br/>
                            dojo.byId(&quot;divDlgMessage&quot;).innerHTML = '#<br/>
        

        {javascript:compositeData.FailReason2Message;}';

                        }<br/>
                        if ( reasonNr == &quot;3&quot;) {<br/>
                            dojo.byId(&quot;divDlgMessage&quot;).innerHTML = '#<br/>
        

        {javascript:compositeData.FailReason3Message;}';

                        }<br/>
                        if ( reasonNr == &quot;4&quot;) {<br/>
                            dojo.byId(&quot;divDlgMessage&quot;).innerHTML = '#<br/>
        

        {javascript:compositeData.FailReason4Message;}';

                        }<br/>
                        if ( reasonNr == &quot;5&quot;) {<br/>
                            dojo.byId(&quot;divDlgMessage&quot;).innerHTML = '#<br/>
        

        {javascript:compositeData.FailReason5Message;}';

                        }<br/>
                        if ( reasonNr == &quot;6&quot;) {<br/>
                            dojo.byId(&quot;divDlgMessage&quot;).innerHTML = '#<br/>
        

        {javascript:compositeData.FailReason6Message;}';

                        }<br/>
                        if ( reasonNr == &quot;7&quot;) {<br/>
                            dojo.byId(&quot;divDlgMessage&quot;).innerHTML = '#<br/>
        

        {javascript:compositeData.FailReason7Message;}';

                        }<br/>
                        if ( reasonNr == &quot;8&quot;) {<br/>
                            dojo.byId(&quot;divDlgMessage&quot;).innerHTML = '#<br/>
        

        {javascript:compositeData.FailReason8Message;}';

                        }<br/>
                        if ( reasonNr == &quot;9&quot;) {<br/>
                            dojo.byId(&quot;divDlgMessage&quot;).innerHTML = '#<br/>
        

        {javascript:compositeData.FailReason9Message;}';

                        }<br/>
                        if ( reasonNr == &quot;10&quot;) {<br/>
                            dojo.byId(&quot;divDlgMessage&quot;).innerHTML = '#<br/>
        

        {javascript:compositeData.FailReason10Message;}';

                        }<br/>
                        if ( reasonNr == &quot;11&quot;) {<br/>
                            dojo.byId(&quot;divDlgMessage&quot;).innerHTML = '#<br/>
        

        {javascript:compositeData.FailReason11Message;}';

                        }<br/>
                    }<br/>
        


                    dijit.byId('#{id:btnChangePassword}').attr(&quot;disabled&quot;, false);<br/>
        


                } <br/>
            }, <br/>
            error: function (error) {<br/>
                alert(error);<br/>
            } <br/>
        }); <br/>
        

        };]]></xp:this.value>

        &lt;/xp:scriptBlock&gt;<br/>
        &lt;div dojoType=&quot;dijit.Dialog&quot; id=&quot;dialogChangePassword&quot;<br/>
        

        title="#{javascript:compositeData.DialogTitle}" class="tundra"

            execute=&quot;ChangePwd(arguments[0]);&quot; style=&quot;display:none&quot;&gt;<br/>
            <br/>
            &lt;xp:table id=&quot;tableChangePassword&quot; style=&quot;width:400px&quot;&gt;<br/>
                &lt;xp:tr&gt;<br/>
                    &lt;xp:td colspan=&quot;2&quot; align=&quot;center&quot;&gt;<br/>
                        <br/>
                        <br/>
                        &lt;xp:br id=&quot;br3&quot;&gt;&lt;/xp:br&gt;<br/>
                    &lt;/xp:td&gt;<br/>
                &lt;/xp:tr&gt;<br/>
                &lt;xp:tr&gt;<br/>
                    &lt;xp:td&gt;<br/>
                        &lt;xp:label<br/>
                            id=&quot;lbl_password&quot;<br/>
                            styleClass=&quot;label&quot; value=&quot;Old password&quot;&gt;<br/>
                        &lt;/xp:label&gt;<br/>
                    &lt;/xp:td&gt;<br/>
                    &lt;xp:td&gt;<br/>
                        &lt;xp:inputText id=&quot;password&quot; style=&quot;width:200px&quot; password=&quot;true&quot;&gt;<br/>
                            <br/>
                        &lt;/xp:inputText&gt;<br/>
                    &lt;/xp:td&gt;<br/>
                    <br/>
                    <br/>
                &lt;/xp:tr&gt;<br/>
        


                &lt;xp:tr&gt;<br/>
                    &lt;xp:td&gt;&lt;xp:label id=&quot;lbl_password_new&quot; styleClass=&quot;label&quot; value=&quot;New <br/>
        

        password">

                        &lt;/xp:label&gt;&lt;/xp:td&gt;<br/>
                    &lt;xp:td&gt;&lt;xp:inputText id=&quot;passwordnew&quot; password=&quot;true&quot; style=&quot;width:200px&quot;&gt;<br/>
                            <br/>
                            <br/>
        

        </xp:inputText></xp:td>

                    <br/>
                    <br/>
                &lt;/xp:tr&gt;<br/>
                &lt;xp:tr&gt;<br/>
                    &lt;xp:td&gt;&lt;xp:label id=&quot;lbl_password_confirm&quot; styleClass=&quot;label&quot; value=&quot;Confirm <br/>
        

        password">

                        &lt;/xp:label&gt;&lt;/xp:td&gt;<br/>
        


                    &lt;xp:td&gt;<br/>
                        <br/>
                    &lt;xp:inputText id=&quot;passwordconfirm&quot; password=&quot;true&quot; style=&quot;width:200px&quot;&gt;<br/>
                            <br/>
                            &lt;xp:eventHandler event=&quot;onkeyup&quot; submit=&quot;false&quot;<br/>
                                id=&quot;eventHandler4&quot;&gt;<br/>
                                &lt;xp:this.script&gt;&lt;![CDATA[if (thisEvent.keyCode == 13) <br/>
        

        {

        ChangePwd();<br/>
        return true<br/>
        

        }]]></xp:this.script>

                            &lt;/xp:eventHandler&gt;<br/>
                    &lt;/xp:inputText&gt;&lt;/xp:td&gt;<br/>
                &lt;/xp:tr&gt;<br/>
                &lt;xp:tr&gt;<br/>
                    &lt;xp:td colspan=&quot;2&quot; align=&quot;right&quot;&gt;<br/>
                        &lt;div name=&quot;divDlgMessage&quot; id=&quot;divDlgMessage&quot;&gt;<br/>
                            &lt;xp:br&gt;&lt;/xp:br&gt;&lt;/div&gt;<br/>
                    &lt;/xp:td&gt;<br/>
                &lt;/xp:tr&gt;<br/>
                &lt;xp:tr&gt;<br/>
                    &lt;xp:td colspan=&quot;2&quot; align=&quot;right&quot;&gt;<br/>
                        &lt;xp:button id=&quot;btnChangePassword&quot; dojoType=&quot;dijit.form.Button&quot; <br/>
        

        value="Change">

                            &lt;xp:eventHandler event=&quot;onclick&quot; submit=&quot;false&quot;<br/>
                                immediate=&quot;false&quot; save=&quot;false&quot; id=&quot;eventHandler3&quot;&gt;<br/>
                                &lt;xp:this.script&gt;&lt;![CDATA[ChangePwd();]]&gt;&lt;/xp:this.script&gt;<br/>
                            &lt;/xp:eventHandler&gt;<br/>
                        &lt;/xp:button&gt;<br/>
                    &lt;/xp:td&gt;<br/>
                &lt;/xp:tr&gt;<br/>
                &lt;xp:tr&gt;<br/>
                    &lt;xp:td colspan=&quot;2&quot;&gt;<br/>
                        &lt;/xp:td&gt;<br/>
                &lt;/xp:tr&gt;<br/>
            &lt;/xp:table&gt;<br/>
        &lt;/div&gt;<br/>
        

        </xp:view>



        The following need to go in the custom control Property definition



        DialogTitle

        urlChangePwdNSF (address book to change password against, usually/names.nsf)

        FailMessage

        FailReason1Message to FailReason11Message (taken from the reasontext field of the

        $$ChangePasswordForm in domcfg.nsf)



        Andrew Norrie