evolution-cms / evolution

Welcome to the new evolution of MODX Evolution!
GNU General Public License v3.0
260 stars 96 forks source link

Examples of Formlister login? #1497

Closed user83743 closed 4 years ago

user83743 commented 4 years ago

I don't see any examples on the web of how the Formlister login works - has anyone seen any pieces of demo code?

nick0 commented 4 years ago

Hi @user83743, I am just trying to work through this at the moment. A bit of a mission. It's seems powerful but is not in a user friendly package like WebLoginPE etc.

There are some great examples here on a Russian website, use Google Chrome for the translating. No delete profile or edit profile examples there.

There is an example delete profile on the Russian forum here.

Hope that helps

user83743 commented 4 years ago

thanks for the update @nick0 . i'll try that site

bossloper commented 4 years ago

@user83743 - there is also an example of Formlister login on the sample website (profile page) on the Evo installation. Just make sure you enable the userHelper plugin or it will not allow user logout.

user83743 commented 4 years ago

Thanks Mr B. i can login and logout with Formlister now, but only once. if i log in again, i cannot log out, using the exact same "button/link" logout.html?logout that I had used just 2 minutes previously. any ideas? any ideas how userHelper works? is that preventing 2 login/logout sequences?

nick0 commented 4 years ago

No worries.

I have also found that the Personalize snippet works well for showing logged in / non logged in message...

[!Personalize? &yesChunk=`wuli-content-private` &noChunk=`wuli-content-public`!]

And for DLMenu calls, use private:is:0 to display private documents only when logged in, and call it uncached so that the menu refreshes on login to show / hide the restricted content

<div id="sub" class="lilbox sub">
[!DLMenu?
    &id=`sub[*id*]`
    &parents=`[[UltimateParent]]`
    &disablePHx=`1`
    &maxDepth=`3`
    &hideSubMenus=`1`
    &showParent=`1`
    &hereClass=`active`
    &levelClass=``
    &oddClass=``
    &evenClass=``
    &parentRowTpl0=`sub-menu-starter`
    &outerTpl=`sub-menu-wrapper`
    &innerTpl=`sub-menu-inner-wrapper`  
    &rowTpl=`sub-menu-row`
    &categoryFolderTpl=`sub-menu-category`
    &orderBy=`c.menuindex ASC`
    &filters=`AND(
        content:c.hidemenu:is:0;
        private:is:0;
    )`
!]
</div>

I am interested to see how you go.

user83743 commented 4 years ago

thanks @nick0

nick0 commented 4 years ago

No worries mate. Ah, I wonder if that is the same issue I encountered for an existing user... There is a "User is verified:" checkbox. I was only able to login with the Formlister login if the checkbox was checked. And I didn't seem to be able to manually check the box. To get it working I created an "Activate Account" form and when actioned, the checkbox was checked and then I could log in no problems. Are your user's verify checkboxes checked or unchecked?

user83743 commented 4 years ago

thanks Nick. that "verify checkboxes" is not part of the main EVO. where do you see checked boxes for verified web users?

nick0 commented 4 years ago

No probs. Oooooh sorry! Its on the individual web users page for me in 1.4.11 - eg Users > Web Users > My-Test-Web-User

see screen cap below Untitled-1

user83743 commented 4 years ago

thnaks nick. this evo is 1.4.9 so no "verified" tickbox. i will upgrade and let you know. thnaks for your help

user83743 commented 4 years ago

hi Nick. i upgrade to evo 1.4.11 for that site and i see the "User is verified:" tickbox, but it does not work. as in, if you tick the tickbox and immediately go back into that user to check, the tickbox is unchecked - so it's not remembering that I just ticked it. so, i am still limited to one login and one logout per browser session. this is a mad bug.

nick0 commented 4 years ago

Howdy, that's some nice progress then. That is the same issue I noticed too. Agreed, it feels like a bug (unless the dev team don't want manual verifications but surely we need backwards compatibility for older web user accounts). If you create a new user, are they automatically verified? If not, try creating the activation form like here - not 100% sure but that seemed to verify for me. Let me know how you go

user83743 commented 4 years ago

on the off chance it worked: i created a brand new web user. and they immediately come with the "verified user" checkbox checked. and i added them to the same usergroup. then i logged in once and logged out and that works correctly. i again checked that the checkbox was checked and it is still checked. i logged in again no problem, but again , I can't log out. i checked the verified user checkbox and it is still checked for this new user, but it doesn't seem to do anything regarding the logging out a second time.

user83743 commented 4 years ago

is this what you found Nick? you can't logout a second time?

user83743 commented 4 years ago

in the userHelper plugin it says " @internal @properties &logoutKey=Request key;text;logout &cookieName=Cookie Name;text;WebLoginPE &cookieLifetime=Cookie Lifetime, seconds;text;157680000 &maxFails=Max failed logins;text;3 &blockTime=Block for, seconds;text;3600 &trackWebUserActivity=Track web user activity;list;No,Yes;No"

but we are NOT using WebLoginPE - we are using formlister - should that be changed to formlister, or does it not matter as it's just a cookie name?

also, when i login in firefox, i don't see any WebLoginPE cookie - do you?

bossloper commented 4 years ago

Formlister does use WebloginPE as the cookie name: https://github.com/evolution-cms/evolution/blob/2.0.x/assets/snippets/FormLister/core/controller/Login.php#L99

p.s. Fro me when using Formlister for login it did not seem to matter if 'user is verified' option if was checked or not for me. Documentation seems to suggest verify user logic is run by default but not sure it is: http://www.evolution-docs.com/extras/formlister/authorizing-users

If I forced the checkActivation=1 option on Formlister then it did require the user to be verified. Regardless, you do not have to have the 'user is verified' logic active if you do not want to use it.

nick0 commented 4 years ago

That sounds even more promising. I think you will be able to get the older ones verified using that Activation form. That's interesting, No I think my main issue was logging in - I couldn't login in the first place with those unverified users. This logout link works ok for me: <a href="[~[*id*]~]?logout" title="Logout">Logout</a>

In your new comment, I think there in lies the problem. WebLoginPE was a nice package that had docs and examples and was pretty easy to get working. The FormLister approach seems more complex and harder to implement (there are a gazillion settings) with little support and perhaps it shares some of WebLoginPE's coding or something. I did see reference to WebLoginPE somewhere at some stage but it wasn't in a cookie (I don't know how to look for that, can;t see it in web developer tools in Firefox)), it might have been in an error message? Mystery

nick0 commented 4 years ago

great research and tips Mr B!

user83743 commented 4 years ago

thanks @bossloper . can you @bossloper or you @nick0 log in and log out 3 successive times using the Formlister login ? I can't . after one login, the logout will not work with the logout.html?logout that had worked just one minute before that. [[[[ EVO 1.4.11 . TESTING ON lATEST FIREFOX WILL ALL cookies removed ]]]]

bossloper commented 4 years ago

yes, it works for me - Firefox with Evo 1.4.11 and Evo 2.x (demo site). Maybe you have a plugin that is causing an issue? Have you tried disabling all other plugins except userHelper?

Or could you try a clean install of the demo site?

nick0 commented 4 years ago

I just tried login / logout 7 times in a row with no probs in Evo 1.4.11 and a custom starter theme I have been building over the years.. That's weird that you can't. I am with Mr B, must be something else impacting it? We might need a dev to check in on this?

user83743 commented 4 years ago

thnaks for trying that login/logout procedure. Maybe it's a plugin ;) . do you mind cutting and pasting the [!Formlister ....] code here so I can check if you have another parameter being used versus what I am using?

On Mon 22 Jun 2020 at 9:59 a.m., Mr B notifications@github.com wrote:

yes, it works for me - Firefox with Evo 1.4.11 and Evo 2.x (demo site). Maybe you have a plugin that is causing an issue? Have you tried disabling all other plugins except userHelper?

Or could you try a clean install of the demo site?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/evolution-cms/evolution/issues/1497#issuecomment-647384007, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHUTMB6SRDNTR2IWA37MX2LRX4MQNANCNFSM4OEGGTXA .

bossloper commented 4 years ago

This is the demo template code.

Profile login page. You will need to change the rediectTo id and edit profile link url to your resource id for the edit profile page:

[!FormLister?
&checkActivation=`0`
&formid=`login`
&controller=`Login`
&loginField=`email`
&redirectTo=`49`
&defaults=`{"rememberme":1}`
&formControls=`rememberme`
&rules=`{
    "email":{
        "required":"Enter your Email",
                "email":"You should enter correct Email"
    },
    "password":{
        "required":"Enter your password"
    }
}`
&formTpl=`@CODE:

<p>In order to comment on blog entries, you must be a registered user of [(site_name)]. If you haven't already registered, you can <a href="[~5~]">request an account</a>.</p>

<form class="form-horizontal" method="post" action="[(site_url)][~[*id*]~]">
    [+form.messages+]
    <input type="hidden" name="formid" value="login">
    <div class="form-group [+email.classname+] row">
        <div class="col-sm-12">
            <label for="email">Email:</label>
            <input class="form-control" name="email" value="[+email.value+]" id="email" placeholder="Email">
        </div>
    </div>
    <div class="form-group [+password.classname+]">
        <div class="col-sm-12">
            <label for="password">Password:</label>
            <input type="password" class="form-control" name="password" id="password" placeholder="Password" value="[+password.value+]">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <div class="checkbox">
                <label>
                    <input type="checkbox" name="rememberme" value="1" [+c.rememberme.1+]> Remember me
                </label>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-8 col-xs-8 sign-in-block">
            <a href="[~37~]">Forgot Password</a>
        </div>
        <div class="col-sm-4 col-xs-4 login-button">
            <button type="submit" class="btn btn-primary pull-right"><i class="glyphicon glyphicon-log-in"></i> Login</button>
        </div>
    </div>

</form>
`
&skipTpl=`@CODE:
    <div class="text-center">Hello!</div>
    <div class="text-center">
        <a class="btn btn-primary" href="[~49~]"> Edit profile</a> 
        <a class="btn btn-primary" href="?logout"> Logout</a>
    </div>`
&errorTpl=`@CODE:<p>[+message+]</p>`
&messagesOuterTpl=`@CODE:
    <div class="text-danger">[+messages+]</div>`
&errorClass=` has-error` 
&requiredClass=` has-warning`
!]

Edit profile page, in this case resource id 49 referenced in a couple of places above:

<a class="btn btn-primary" href="?logout"> Logout</a>
  [!FormLister?
    &formid=`registerForm`
    &controller=`Profile`
    &requiredClass=`has-warning`
    &errorClass=`has-error`
    &errorTpl=`@CODE:<small class="help-block">[+message+]</small>`
    &allowedFields=`email,username,fullname,country`
    &rules=`{
        "username":{
            "required":"Enter your username",
            "alphaNumeric":"Only letters and numbers",
            "custom":{
                "function":"\\FormLister\\Register::uniqueUsername",
                "message":"Name already taken"
            }
        },
        "email":{
            "required":"Enter email",
            "email":"Incorrect email",
            "custom":{
                "function":"\\FormLister\\Register::uniqueEmail",
                "message":"This email is already in use by another user"
            }
        },
        "password":{
            "required":"Enter password"
        },
        "repeatPassword":{
            "required":"Retype password",
            "equals":{
                "message":"Passwords do not match"
            }
        }
    }`
    &formTpl=`@CODE: 

<form role="form" id="websignupfrm" method="post" name="websignupfrm" action="[+action+]">
    <input type="hidden" name="formid" value="registerForm"/>
    <h3>User Details</h3>

    <div class="form-group [+username.classname+]">
        <label class="control-label" for="su_username">User name:</label> 
        <input type="text" name="username" id="su_username" class="form-control" maxlength="30" value="[+username.value+]" placeholder="Enter Username"/>
        [+username.error+]
    </div>

    <div class="form-group [+fullname.classname+]">
        <label class="control-label" for="fullname">Full name:</label> 
        <input type="text" name="fullname" id="fullname" class="form-control" maxlength="100" value="[+fullname.value+]" placeholder="Enter fullname"/>
        [+fullname.error+]
    </div>

    <div class="form-group  [+email.classname+]">
        <label class="control-label" for="email">Email address:</label> 
        <input type="text" name="email" id="email" class="form-control" value="[+email.value+]" placeholder="Enter email"/>
        [+email.error+]
    </div>

    <div class="form-group [+password.classname+]">
        <h3>Password</h3>
        <label class="control-label" for="su_password">Password:</label> 
        <input type="password" name="password" id="su_password" class="form-control" placeholder="Enter password"/>
        [+password.error+]
    </div>
    <div class="form-group [+repeatPassword.classname+]">
        <label class="control-label" for="confirmpassword">Confirm password:</label> 
        <input type="password" name="repeatPassword" id="confirmpassword" class="form-control" placeholder="Confirm password"/>
        [+repeatPassword.error+]
    </div>

    <div class="form-group [+country.classname+]">
        <h3>Optional Account Profile Info</h3>
        <label class="control-label" for="country">Country:</label>
        <select size="1" name="country" id="country" class="form-control" >
            <option value="" selected="selected">&nbsp;</option>
            <option value="1">Afghanistan</option>
            <option value="2">Albania</option>
            <option value="3">Algeria</option>
            <option value="4">American Samoa</option>
            <option value="5">Andorra</option>
            <option value="6">Angola</option>
            <option value="7">Anguilla</option>
            <option value="8">Antarctica</option>
            <option value="9">Antigua and Barbuda</option>
            <option value="10">Argentina</option>
            <option value="11">Armenia</option>
            <option value="12">Aruba</option>
            <option value="13">Australia</option>
            <option value="14">Austria</option>
            <option value="15">Azerbaijan</option>
            <option value="16">Bahamas</option>
            <option value="17">Bahrain</option>
            <option value="18">Bangladesh</option>
            <option value="19">Barbados</option>
            <option value="20">Belarus</option>
            <option value="21">Belgium</option>
            <option value="22">Belize</option>
            <option value="23">Benin</option>
            <option value="24">Bermuda</option>
            <option value="25">Bhutan</option>
            <option value="26">Bolivia</option>
            <option value="27">Bosnia and Herzegowina</option>
            <option value="28">Botswana</option>
            <option value="29">Bouvet Island</option>
            <option value="30">Brazil</option>
            <option value="31">British Indian Ocean Territory</option>
            <option value="32">Brunei Darussalam</option>
            <option value="33">Bulgaria</option>
            <option value="34">Burkina Faso</option>
            <option value="35">Burundi</option>
            <option value="36">Cambodia</option>
            <option value="37">Cameroon</option>
            <option value="38">Canada</option>
            <option value="39">Cape Verde</option>
            <option value="40">Cayman Islands</option>
            <option value="41">Central African Republic</option>
            <option value="42">Chad</option>
            <option value="43">Chile</option>
            <option value="44">China</option>
            <option value="45">Christmas Island</option>
            <option value="46">Cocos (Keeling) Islands</option>
            <option value="47">Colombia</option>
            <option value="48">Comoros</option>
            <option value="49">Congo</option>
            <option value="50">Cook Islands</option>
            <option value="51">Costa Rica</option>
            <option value="52">Cote D&#39;Ivoire</option>
            <option value="53">Croatia</option>
            <option value="54">Cuba</option>
            <option value="55">Cyprus</option>
            <option value="56">Czech Republic</option>
            <option value="57">Denmark</option>
            <option value="58">Djibouti</option>
            <option value="59">Dominica</option>
            <option value="60">Dominican Republic</option>
            <option value="61">East Timor</option>
            <option value="62">Ecuador</option>
            <option value="63">Egypt</option>
            <option value="64">El Salvador</option>
            <option value="65">Equatorial Guinea</option>
            <option value="66">Eritrea</option>
            <option value="67">Estonia</option>
            <option value="68">Ethiopia</option>
            <option value="69">Falkland Islands (Malvinas)</option>
            <option value="70">Faroe Islands</option>
            <option value="71">Fiji</option>
            <option value="72">Finland</option>
            <option value="73">France</option>
            <option value="74">France, Metropolitan</option>
            <option value="75">French Guiana</option>
            <option value="76">French Polynesia</option>
            <option value="77">French Southern Territories</option>
            <option value="78">Gabon</option>
            <option value="79">Gambia</option>
            <option value="80">Georgia</option>
            <option value="81">Germany</option>
            <option value="82">Ghana</option>
            <option value="83">Gibraltar</option>
            <option value="84">Greece</option>
            <option value="85">Greenland</option>
            <option value="86">Grenada</option>
            <option value="87">Guadeloupe</option>
            <option value="88">Guam</option>
            <option value="89">Guatemala</option>
            <option value="90">Guinea</option>
            <option value="91">Guinea-bissau</option>
            <option value="92">Guyana</option>
            <option value="93">Haiti</option>
            <option value="94">Heard and Mc Donald Islands</option>
            <option value="95">Honduras</option>
            <option value="96">Hong Kong</option>
            <option value="97">Hungary</option>
            <option value="98">Iceland</option>
            <option value="99">India</option>
            <option value="100">Indonesia</option>
            <option value="101">Iran (Islamic Republic of)</option>
            <option value="102">Iraq</option>
            <option value="103">Ireland</option>
            <option value="104">Israel</option>
            <option value="105">Italy</option>
            <option value="106">Jamaica</option>
            <option value="107">Japan</option>
            <option value="108">Jordan</option>
            <option value="109">Kazakhstan</option>
            <option value="110">Kenya</option>
            <option value="111">Kiribati</option>
            <option value="112">Korea, Democratic People&#39;s Republic of</option>
            <option value="113">Korea, Republic of</option>
            <option value="114">Kuwait</option>
            <option value="115">Kyrgyzstan</option>
            <option value="116">Lao People&#39;s Democratic Republic</option>
            <option value="117">Latvia</option>
            <option value="118">Lebanon</option>
            <option value="119">Lesotho</option>
            <option value="120">Liberia</option>
            <option value="121">Libyan Arab Jamahiriya</option>
            <option value="122">Liechtenstein</option>
            <option value="123">Lithuania</option>
            <option value="124">Luxembourg</option>
            <option value="125">Macau</option>
            <option value="126">Macedonia, The Former Yugoslav Republic of</option>
            <option value="127">Madagascar</option>
            <option value="128">Malawi</option>
            <option value="129">Malaysia</option>
            <option value="130">Maldives</option>
            <option value="131">Mali</option>
            <option value="132">Malta</option>
            <option value="133">Marshall Islands</option>
            <option value="134">Martinique</option>
            <option value="135">Mauritania</option>
            <option value="136">Mauritius</option>
            <option value="137">Mayotte</option>
            <option value="138">Mexico</option>
            <option value="139">Micronesia, Federated States of</option>
            <option value="140">Moldova, Republic of</option>
            <option value="141">Monaco</option>
            <option value="142">Mongolia</option>
            <option value="143">Montserrat</option>
            <option value="144">Morocco</option>
            <option value="145">Mozambique</option>
            <option value="146">Myanmar</option>
            <option value="147">Namibia</option>
            <option value="148">Nauru</option>
            <option value="149">Nepal</option>
            <option value="150">Netherlands</option>
            <option value="151">Netherlands Antilles</option>
            <option value="152">New Caledonia</option>
            <option value="153">New Zealand</option>
            <option value="154">Nicaragua</option>
            <option value="155">Niger</option>
            <option value="156">Nigeria</option>
            <option value="157">Niue</option>
            <option value="158">Norfolk Island</option>
            <option value="159">Northern Mariana Islands</option>
            <option value="160">Norway</option>
            <option value="161">Oman</option>
            <option value="162">Pakistan</option>
            <option value="163">Palau</option>
            <option value="164">Panama</option>
            <option value="165">Papua New Guinea</option>
            <option value="166">Paraguay</option>
            <option value="167">Peru</option>
            <option value="168">Philippines</option>
            <option value="169">Pitcairn</option>
            <option value="170">Poland</option>
            <option value="171">Portugal</option>
            <option value="172">Puerto Rico</option>
            <option value="173">Qatar</option>
            <option value="174">Reunion</option>
            <option value="175">Romania</option>
            <option value="176">Russian Federation</option>
            <option value="177">Rwanda</option>
            <option value="178">Saint Kitts and Nevis</option>
            <option value="179">Saint Lucia</option>
            <option value="180">Saint Vincent and the Grenadines</option>
            <option value="181">Samoa</option>
            <option value="182">San Marino</option>
            <option value="183">Sao Tome and Principe</option>
            <option value="184">Saudi Arabia</option>
            <option value="185">Senegal</option>
            <option value="186">Seychelles</option>
            <option value="187">Sierra Leone</option>
            <option value="188">Singapore</option>
            <option value="189">Slovakia (Slovak Republic)</option>
            <option value="190">Slovenia</option>
            <option value="191">Solomon Islands</option>
            <option value="192">Somalia</option>
            <option value="193">South Africa</option>
            <option value="194">South Georgia and the South Sandwich Islands</option>
            <option value="195">Spain</option>
            <option value="196">Sri Lanka</option>
            <option value="197">St. Helena</option>
            <option value="198">St. Pierre and Miquelon</option>
            <option value="199">Sudan</option>
            <option value="200">Suriname</option>
            <option value="201">Svalbard and Jan Mayen Islands</option>
            <option value="202">Swaziland</option>
            <option value="203">Sweden</option>
            <option value="204">Switzerland</option>
            <option value="205">Syrian Arab Republic</option>
            <option value="206">Taiwan</option>
            <option value="207">Tajikistan</option>
            <option value="208">Tanzania, United Republic of</option>
            <option value="209">Thailand</option>
            <option value="210">Togo</option>
            <option value="211">Tokelau</option>
            <option value="212">Tonga</option>
            <option value="213">Trinidad and Tobago</option>
            <option value="214">Tunisia</option>
            <option value="215">Turkey</option>
            <option value="216">Turkmenistan</option>
            <option value="217">Turks and Caicos Islands</option>
            <option value="218">Tuvalu</option>
            <option value="219">Uganda</option>
            <option value="220">Ukraine</option>
            <option value="221">United Arab Emirates</option>
            <option value="222">United Kingdom</option>
            <option value="223">United States</option>
            <option value="224">United States Minor Outlying Islands</option>
            <option value="225">Uruguay</option>
            <option value="226">Uzbekistan</option>
            <option value="227">Vanuatu</option>
            <option value="228">Vatican City State (Holy See)</option>
            <option value="229">Venezuela</option>
            <option value="230">Viet Nam</option>
            <option value="231">Virgin Islands (British)</option>
            <option value="232">Virgin Islands (U.S.)</option>
            <option value="233">Wallis and Futuna Islands</option>
            <option value="234">Western Sahara</option>
            <option value="235">Yemen</option>
            <option value="236">Yugoslavia</option>
            <option value="237">Zaire</option>
            <option value="238">Zambia</option>
            <option value="239">Zimbabwe</option>
            </select>
            [+country.error+]
     </div>

     <div class="form-group">
         <input type="submit" class="btn btn-success btn-lg" value="Submit" name="cmdwebsignup" />
     </div>

</form>

<script language="javascript" type="text/javascript"> 
    var id = "[+country.value+]";
    var f = document.websignupfrm;
    var i = parseInt(id);   
    if (!isNaN(i)) f.country.options[i].selected = true;
</script>

    `!]
user83743 commented 4 years ago

hi again. that didn't work and we can't login/logout 2 or more times. i have all cookies displaying now on 3 test pages: login.html, logout.html and privatepage.html . can you confirm that "evo1xgfdyf" is the session cookie name for logging-in? i have code now running on logout.html and if you go to that page a piece of php will run and kill that "evo1xgfdyf" cookie and we're logged out. so that is working ok now - tested it many times over and over. i just want to check with you professionals :) . do you see that "evo1xgfdyf" session cookie?

bossloper commented 4 years ago

"evo1xgfdyf" is cookie based on your install. They all start evo... but the following characters are different for each installation. So yes that session cookie is fine.

You should not need extra code to 'kill' the session cookies at logout. Do you have the userHelper plugin running(?) as that is exactly what that does. It removes the session cookie when you log out.

But if you still cannot login multiple times I would suggest trying the demo site and seeing if that works... assuming you have tried disabling all other plugins.

user83743 commented 4 years ago

thnaks @bossloper - i see different "evoxxxxxx" strings on a few installs. i didn't know that :().

the userHelper plugin is enabled and i see it's settings but i see no cookie killing from it. many hours spent watching it not log me out.

i have it consistently working now with my own snippet to kill the session if you click through to the logout page, so that will do me :) . much appreciated Mr Boss :) . have a good day. i will close this now.

nick0 commented 4 years ago

Great news! Well done @user83743. How good is Mr B!