Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/28/2017 in all areas

  1. Here's a short snippet for site/ready.php that hooks after ProcessPageEdit::buildForm and moves a regular field (named "testfield here") from the Content tab to Settings. The methods used are from the InputfieldWrapper class. <?php wire()->addHookAfter("ProcessPageEdit::buildForm", null, "moveFieldToSettings"); function moveFieldToSettings(HookEvent $event) { $form = $event->return; $field = $form->find("name=testfield")->first(); if($field) { $settings = $form->find("id=ProcessPageEditSettings")->first(); // Alternatively, find a specific field to insert before/after: // $settings = $form->find("name=template")->first(); if($settings) { $form->remove($field); $settings->append($field); // In the alternative, insert before or after the found field: // $form->insertBefore($field, $settings); } } }
    6 points
  2. You can just install it like any other module. Once installed, click on the save button then the "Backup Now" button, no other steps required If you still have problem using it, please feel free to post your issue in the dev topic or PM me, I will help you with pleasure.
    5 points
  3. You could also just use the field access settings to not show the field to anyone besides superusers.
    5 points
  4. this may be a namespace snafu - have you tried putting the namespace in front of the call inside the include, e.g. \ProcessWire\myFunction(); ? to be clear, i include tons of functions from the init, in fact my _init includes a _func.php which the includes around 10 separate files all with functions and those all load and are usable everywhere; however i have run into the snafu of having to prepend the namespace for some reason within certain included files down the line
    5 points
  5. I recently had a revelation when building HTML emails, what's the difference between HTML emails, and HTML web pages? Other than the horrible table syntax, the result is the same, it's still HTML. This got me thinking why not use a CMS to help generate the HTML emails based on a template? Just like we using a CMS to help generate HTML web pages. We started by setting up ProcessWire (our usual CMS of choice) and added the relevent fields for the sections of the email. Then we took a previous email moved the content into ProcessWire and hooked up the code to pull that content back into the correct places. Repeater fields allowed us to have repeatable sections that are easy to add too, change order of or remove, giving us huge flexibility when a client changes their mind last minute. The speed of setting up and dealing with ProcessWire allowed us to go from concept to working prototype within a day. To use the emails, we just view source of the generated page, and copy and paste into the email system. Sometimes Litmus inliner is required to allow the email to work in Outlook, but we can run it through that before pasting into the email system. Future development could be integrating a css inliner into the generation step, to avoid using litmus inliner. Hope this helps show how ProcessWire can be used in a different scenario.
    4 points
  6. I did a "hotel review" app that sends emails to clients and catches responses nicely in a PageTable!! I also use PW fields to configure the survey page (add hotel logo, color styles, headlines). The users just have a list under root, each one representing a hotel, displaying the responses nicely inside brackets next to the title. New hotel for review? Just add a new page and configure! Happy clients with minimum effort and straightforward interface!
    4 points
  7. I backup everything in the root folder and do a mysqldump. In case of an emergency I can easily import db and extract files and we are good to go. Flydev is working on imo the best solution: Duplicator. I've got a beta running on several websites.
    4 points
  8. I like it, this new version of the admin theme is a step forward for Processwire. I'm a space fan in the design, I like when the user interface can breathe a lot, but I think it's too white or too "light" now, it's hard to see on a 27-inch monitor. I would like the color of the header bar, buttons hover and other small details can be configured in the administration, as well as the logo (keeping the height) to match the brand of our customer, this will be a great advantage. Of course the Processwire identity is maintained in the footer. I think the default color may match the Processwire website that I like and it's refreshing. The developer can customize with parameters in the administration, this can be achieved using a small css file with color codes to override some elements and this file can be generated when the profile page is modified. I was modifying some screens directly with the Chrome Inspector and this is the result. I made adjustments in the background tones, margins, colors, hiding elements like lines, etc. For example, the help paragraph that is always visible, it would be nice to display it on demand with help icon or directly by activating them in the VIEW menu. Because it is useful the first few times you use Processwire, but when you learn it only occupies an unnecessary space.
    4 points
  9. Hi everyone - @tpr has done a great job on changing the way the ML info tooltip is displayed - it's now part of a hidden row. Here is his screencap of it in action! This and all the other recent ML changes are now committed to Github. Please test carefully and let me know if you find any problems, and don't forget the AOS language switcher for changing between languages!
    3 points
  10. I use SmartBackup (a codecanyon script) in a subfolder and have it set to backup the /site/ folder and the database; it runs on a cron job, and creates the zip file in wherever you specify. All you need to re-create the site is your site folder and the database; unless you have placed some other custom stuff above /site/ Once Duplicator is released, i will switch to using that for backups, and drop the SmartBackup; SmartBackup is very good, but Duplicator will be a native module, and supports more options, like Amazon S3; For sites with massive assets files, like audio, i set the backup to exclude images and other media like audio and video. The i have a Forklift 'synclet' that i can run and that syncs the entire site/assets folder with an Amazon s3 account, with 1 click.
    3 points
  11. @MilenKo Ryan's example include("./MyCommentForm.php"); $form = new MyCommentForm($page, $page->comments); echo $form->render(); is for extending the class inside /wire/modules/Fieldtype/FieldtypeComments/CommentForm.php with your own inside MyCommentForm.php and changing the necessary methods to suit your needs.
    2 points
  12. I do something similar, but instead of styling the page for the email, I have a separate template file for emails that builds the html for the email using tables and inline css and sends that directly to the list of subscribers. In my case, a monthly enewsletter is composed of several different articles (each a separate child page). The template for these child pages has a field to select what month/year the article belongs to. The email sending script queries matching articles, compiles, and sends. The possibilities are endless really
    2 points
  13. I download everything to my pc with rsync, I'm on Windows 10 so I use Bash on Ubuntu on Windows, for Windows 7 there's cygwin. ssh root@ip /var/www/clients/client1/web1/web/script.sh && rsync -av -e ssh root@ip:/var/www/clients/client1 /mnt/e/zBackup/www --exclude-from '/mnt/e/zBackup/www/exclude.txt' --delete ssh root@ip /var/www/clients/client1/web1/web/script.sh - runs a script that backups all databases rsync -av -e ssh root@ip:/var/www/clients/client1 /mnt/e/zBackup/www - downloads everything from /var/www/clients/client1 on my vps to E:\zBackup\www on my pc --exclude-from '/mnt/e/zBackup/www/exclude.txt' - text file with paths to exclude from downloading Database backup script
    2 points
  14. In ProcessWire 3.x (I think only 3?) you can use implode like so: $pageIDsString = $yourPageArray->implode('|', 'id'); //echo $pageIDsString;// returns 1234|2345|8976 etc.. You can choose your delimiter and the property to implode by. There's other interesting methods here.
    2 points
  15. Phone Number Fieldtype A new fieldtype to enter phone numbers with 4 integer values for country, area code, number and extension and format the output based on predefined or custom options. StyledOutput The most common usage option will be: echo $page->fieldname //eg. +1 (123) 456-7890 x123 This provides a fully formatted phone number, based on the output format chosen from module's configuration page, or with the format override option (if enabled), when entering a phone number on a page. This is a shortcut that produces the same output as: echo $page->fieldname->formattedNumber //eg. +1 (123) 456-7890 x123 Alternate styled options are: echo $page->fieldname->formattedNumberNoExt: //eg. +1 (123) 456-7890 echo $page->fieldname->formattedNumberNoCtry: //eg. (123) 456-7890 x123 echo $page->fieldname->formattedNumberNoCtryNoExt: //eg. (123) 456-7890 echo $page->fieldname->unformattedNumber: //eg. 11234567890123 echo $page->fieldname->unformattedNumberNoExt: //eg. 11234567890 echo $page->fieldname->unformattedNumberNoCtry: //eg. 1234567890123 echo $page->fieldname->unformattedNumberNoCtryNoExt: //eg. 1234567890 Of course the actual output is determined by the selected format output Raw Output You can output the values for the component parts of the phone number like this: echo $page->fieldname->country; echo $page->fieldname->area_code; echo $page->fieldname->number; echo $page->fieldname->extension; Output for mobile compatibility To get iOS and other mobile platforms to recognize numbers and be able to automatically dial them, use something like this: echo '<a href="tel:+'.$page->fieldname->unformattedNumberNoExt.'">'.$page->fieldname->formattedNumber.'</a>'; Selectors for searching The component parts can be used in selectors like this: $pages->find("phone.area_code=123"); Field Settings There is a field settings for the width of the inputs in pixels. There is a field settings for the width of the inputs in pixels. You can also choose whether to display the country and extension fields for input. Off by default. There is an additional checkbox that determines whether there is an option to override the default format option on a per entry basis, which will be useful when styling phone numbers from different countries on the one website. Off by default. Custom formatting options On the module's configuration page you can choose from predefined formats, or create custom formats using syntax like this: {+[phoneCountry] }{([phoneAreaCode]) }{[phoneNumber,0,3]-}{[phoneNumber,3,4]}{ x[phoneExtension]} which generates: +1 (123) 456-7890 x123 Each component is surrounded by { } The names of the component parts are surrounded by [ ] Two comma separated numbers after the component name are used to get certain parts of the number using php's substr function, allowing for complete flexibility. Anything outside the [ ] is used directly: +,-,(,),x, spaces, etc - whatever every you want to use. There are lots of complicated rules around numbers changing when dialed from different locations. A simple example is for Australia. When dialing from within Australia, area codes start with a 0, but when dialing from another country, the 0 must be omitted. You can write a simple format to handle this. The following truncates the first number from an Australian two digit area code: {+[phoneCountry] }{([phoneAreaCode,1,1]) }{[phoneNumber,0,4] }{ [phoneNumber,4,4]}{ x[phoneExtension]} which generates: +1 (7) 1234 5678 x123 even though the full "07" is stored in the area code field. Where to get Available from github: https://github.com/adrianbj/FieldtypePhone And the modules directory: http://modules.processwire.com/modules/fieldtype-phone/ To Do Need to increase the number of pre-defined formats. There seem to be so many options and no real standards, so I thought rather than create a huge list of options that no-one will use, I thought I'd wait and get you guys to contribute them as you need them. Either post your formats here, or send me a PR on github and I'll add them. How to install Download and place the module folder named "FieldtypePhone" in: /site/modules/ In the admin control panel, go to Modules. At the bottom of the screen, click the "Check for New Modules" button. Now scroll to the FieldtypePhone module and click "Install". The required InputfieldPhone will get installed automatically. Create a new Field with the new "Phone" Fieldtype. Choose a Phone Output Format from the details tab. Acknowledgments This module uses code from Soma's DimensionFieldtype and the core FieldtypeDatetime module - thanks guys for making it so easy.
    1 point
  16. The alerts work great, every time I edit some files I get an email. Until now I've never had false positives. I don't get any alerts for database changes, and I'm not sure you can do that. Their site is in maintenance right now, so I can't check that out. The alerts are available on the free version.
    1 point
  17. Me too, however, I'm not a fan of it in the case of administration interfaces. I do not like scrolling around, I prefer to see all stuff possible right in front of my face I'm not saying whitespace should be eliminated, but people often work on 11''-13'' laptop screens and not on 27" desktop monsters It would be nice to have some sort of whitespace settings and/or whitespace could adapt to the viewport size.
    1 point
  18. I have to say I find Codeguard quite amazing. Independently of which method you will chose to backup locally, it won't hurt to have an extra backup in the cloud, and Codegard does backups for one website, with one database, until 1GB, for free. ps: I mentioned it on another thread already
    1 point
  19. Sorry, AFAIK, GD doesn't support TIF.
    1 point
  20. Try installing the Tracy Debugger module http://modules.processwire.com/modules/tracy-debugger/ . I believe there is new feature in that module to handle ajax errors like this now, but may also require updating Processwire to a newer version as well. It might give you more insight into what is causing the error.
    1 point
  21. Not sure if it suits your needs or not, but TracyDebugger has a Mail Interceptor panel that intercepts all outgoing emails and instead shows all their details/content in the panel. If not, I can look into changing the address like you want, but thought I'd mention that first just in case.
    1 point
  22. I have a pull-request for this module, pull-request adding multi language support to reCAPTCHA and multiple usage on one page. You can see usage on screenshot. For set reCAPTCHA language, (reCAPTCHA Language Codes) : <?php if(modules()->isInstalled('MarkupGoogleRecaptcha')) { echo modules()->MarkupGoogleRecaptcha->render($lang = "en"); }; ?> For multiple reCAPTCHA usage, after all form render, call multiple usage script : <?php if(modules()->isInstalled('MarkupGoogleRecaptcha')) { echo modules()->MarkupGoogleRecaptcha->getScriptMulti(); }; ?>
    1 point
  23. Thanks, I've added width: auto to the CSS (no version change).
    1 point
  24. Never done that (I usually use responsive CSS frameworks like UIkit to allow smooth scaling with a single set of templates), but you might have a look at @justb3a's MobileDetect module. With it, you should be able to adapt the paths (with code in site/init.php, not config.php, since the module needs to be initialized first) like in this recipe.
    1 point
  25. Ah really? that's cool, tbh i'm not sure why i didn't think of it sooner.
    1 point
  26. Afaik that's what Ryan does for the weekly processwire newsletter.
    1 point
  27. Hi @Roman Schmitz - sorry about that! I will commit a fix a little later (I want to clean up some other stuff while I am at it), but for now please change: https://github.com/adrianbj/FieldtypePhone/blob/56ec89e7fc81cdc693ce72f9f9030edf3f49bd63/FieldtypePhone.module#L159 to: if($value['data_extension'] != '') $pn->extension = wire('sanitizer')->text($value['data_extension']);
    1 point
  28. Yes, the first blog post on the feature says that for now it must be explicitly enabled in $config: $config->useMarkupRegions = true; You have to be deliberately using the feature too in order to be affected by the stripped comments. So contrary to what I said above it isn't so much that useMarkupRegions is enabled, it's when there are comments in the HTML that occur before the doctype or <html> tag. ---- _main.php <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title><?= $page->title ?></title> </head> <body> <?= $my_var ?> <!-- this comment will be rendered --> <div id="main"> <p>Default main content.</p> </div> </body> </html> home.php <?php $my_var = " <!-- this comment will be rendered --> <p>hello</p> "; ?> <!-- this comment will not be rendered --> <div id="main"> <!-- and this comment will also not be rendered --> <p>Main content from home template.</p> </div>
    1 point
  29. It must be pro cache; i have a site with pro cache enabled and i don't have it set to strip comments, and my comments still appear; have you tried turning off the html minification features of PC? i believe it still processes, even when the caching is off.
    1 point
  30. Of course, I waited for this all day I may try to implement the full-width bcePageName layout tomorrow too if you don't mind.
    1 point
  31. I'll check the text-transform thing tomorrow. I got an error on loading the module settings, plus the language text on top is showing as a non-rendered markup (even if AOS uninstalled, if it's enabled it's not showing at all):
    1 point
  32. Thanks again @tpr for the feedback. I have changed the icon to the info-circle. I have added a new tooltip which provides a summary of titles/names for all languages: For the Add New page problem - I decided to go with populating the default language with the values for the current user language so there is at least valid entries for these that can be edited later if needed. Note that I also added a Language label at the top of the table (rather than being added to several columns in the table). I would also like to mention the awesome Language Switcher in your AOS module - I think that having that enabled along with the new changes to BCE actually makes for a pretty decent start to multi-language support because it makes it so easy to instantly switch languages. I think this new version is ready for release, but will attach here for one more review by you (and anyone else who is interested). Thanks, Adrian BatchChildEditor.zip
    1 point
  33. @k07n and everyone else who uses this module. I just committed a pretty major revision to the API export method. It now works like this: $modules->get('ProcessTableCsvExport'); // load module // field name, delimiter, enclosure, file extension, multiple values separator, names in first row, columns to export, selector(filter) string // columns to export can be index starting at 1, or column names $page->exportTableCsv('table_field_name', ',', '"', 'csv', '|', true, array('col1', 'col2'), 'year=2017'); Unfortunately this is a breaking change, but I realized that the old approach didn't allow calling the method on an alternate page. This new version also supports limiting the exported columns (an array of column names, or indices starting at 1), as well as defining of a selector filter. Please let me know if you have any problems.
    1 point
  34. Thanks, much better Perhaps I would change the new exclamation icon to "fa-info-circle" because it's less strict. Sometimes the page name is intentionally the same in all languages so it's not necessarily an error (eg. /sport/). But the same holds true for the "title" field too. I like the active checkboxes. Or do you mean displaying checkboxes for all languages? How? Perhaps displaying a list of languages + active state in a tooltip on hover? That would be a handy extra info so one could edit the page in question if needed. As for the add new page for non-default language, it's a tough one, I would say leave it as it is and improve later
    1 point
  35. Middle-click to open link: sorry, it was the same page that opened, not the one in the list. What if it had a link too, would the modal stop functioning? Empty "name" for non-default language names: perhaps using square brackets, or something similar, eg "*pagename"?
    1 point
  36. Thanks Ryan. Very good progress on this! Can't wait to see what the communities front dev pros can show us how to use it / what all can be done with it, now that you have opened it for easy configuration.
    1 point
  37. Cool idea . Yes; please file a feature request, thanks. No need for a hook. We can simply pass an option [which I'll create] to render(). However, this will not be as straightforward as it looks. What if that unlistable menu item has children, especially ones that are custom menus? We can't leave them parentless. They will have to be removed. Such a potential situation won't always be apparent at the editing stage; editors could unknowingly create a hierarchy that will break if the option to not list menu items is applied. Please file a request and I'll have a think.
    1 point
  38. I guess blanks would be better if that would prevent unintended saves, thanks. Hiding them in a tooltip is perhaps not the best idea, it would be better to make them visible all the time (wouldn't require hovering with the mouse). Actually I could add non-default language titles and other titles were remained intact. But I have the Page Rename Options plugin installed, maybe that's interfering.
    1 point
  39. @adrian On a multilanguage site, loading the Children tab (BCE) shows the titles for the default language if there are no title set for the current language which is fine. But if I save the page, even without any editing, these default titles are saved to the DB (for the non-default language). This happens only after navigating to the Children tab. From a user/editor POV I regard this as a bug, do you think there's an easy fix? So do not overwrite empty titles with the titles from the default language. Currently it's not an issue because all titles will be translated for all languages but it's a bit confusing imo.
    1 point
  40. The "official" blog post about this topic might also be of interest: https://processwire.com/blog/posts/making-efficient-use-of-fields-in-processwire/ True, the word "performance" is not even mentioned in it, but I guess this is because this is not really about optimizing performance too much. Optimizing database access by means of proper usage of API calls and cache should matter the most.
    1 point
  41. Less fields is better for you - less to manage, but it won't matter to PW either way because all the field db tables (eg field_slider) are indexed by the pages_id so PW finds the relevant entries very quickly. Having a separate field won't improve this.
    1 point
  42. Great module from what I could see in the videos. Definitely something I want to use in my upcoming projects. Only one question regarding the handling and output of images Is there a way to make any kind of pre-defined crop-settings (like in the Croppable Image 3 module) or something like the focus area from the (unsurpassedly useful but unfortunately not PW 3 compatible) ImageFocusArea module available with Media Manager? Why I ask In my websites I use responsive images wherever possible, usually using the picture element because I often need its art direction feature. So my workflow in PW 2.x was: Use the ImageFocusArea module’s input field to upload an image. Define the important region (= “focus”) of the image which must be fully visible in all cropped image variations. Have ProcessWire create all required sizes of all required image variations directly from the original image using the image sizing options (extended by the ImageFocusArea module) in the template files. The two big pros of this workflow were that the user only had to define the important area of the image once – and was not bothered with any cropping settings (like finding a good-looking image section for an extremely wide horizontal format) – and that all required variations and sizes (I usually use about 10 different images per picture element) were created directly from the original image (which ensures best quality because no unnecessary compression steps were included). In PW 3.x I had to change this due to the new image field which makes the ImageFocusArea module incompatible with PW 3: Use the Croppable Image 3 module’s input field to upload an image. Use the input field’s settings to define the biggest (in pixels) version of each required aspect ratio variation of the image. Let the user define the best looking image sections for the different crop variations (let’s say we need a 2:1 aspect ratio version and a 4:3 aspect ratio version of the image for one picture element). Have ProcessWire create the required downscaled versions of the “source images” (i. e. the variants created using the pre-defined crop settings of the Croppable Image input field) using the standard image sizing options in the template files. While it works, the two big cons here are that the user has to define the different aspect ratio variations manually (assuming that the automatically created default cropping around the image’s center isn’t the best-looking option) and that the downscaled variations of each aspect ratio variations are created from an already processed image (so this includes at least one unnecessary compression step). And of course changing aspect ratio variations later (because of a website layout revision) can result in a lot of manual work to adapt cropped image variations. What would really be a great extension for Media Manager in my opinion It would be great if the ImageFocusArea module’s functionality would be available in Media Manager under PW 3. This would make using different image variations a no-brainer – without the website editor having to know anything about image variations, aspect ratios, sizes, cropping, etc.: The website editor uploads an image in Media Manager. The website editor defines the important area of the image which may never be cut away. The website editor selects the image on the respective page using Media Manager’s input field. That’s it. The template files take care of the rest. And even if the website layout completely changes the selected image needs not to be touched, since all required image variations are created from the original, centrally available image, making sure that the image’s main motive is always presented in the best possible way. Of course, when inserted into a CKEditor field, the editor can apply an individual cropping if desired. Unfortunately I’m not a backend developer at all. So I can’t make any code suggestions on how to make this work.
    1 point
  43. This does work: $tmpls = $templates->find("tags=myTag"); $result = $pages->find(template=$tmpls");
    1 point
  44. Basicly you have one folder for templates by default. This is configured to be in "site root" + templates/ You are able to overrule this setting from the site/config.php as follow $config->urls->templates = $config->urls->site . 'mytemplates/'; $config->paths->templates = $config->paths->site . 'mytemplates/'; A trick i use a lot when developing in a live site is to duplicate the template folder and rename the copy to templates-dev. Then make sure i have an other domain (or subdomain) pointing to the hosting, for example dev.domain.ext and for the live site on www.domain.ext With the following code i can access the development templates while normal visitors keep getting the default templates. /** * Development: Alias for template-dev access * */ if($_SERVER['HTTP_HOST'] == 'dev.domain.ext') { $config->urls->templates = $config->urls->site . 'templates-dev/'; $config->paths->templates = $config->paths->site . 'templates-dev/'; $config->debug = true; } You can make up all kind of 'rules' to go by when overruling the templates folder with php from the config.php file. For example serving the same site with different layout and code for mobile on m.domain.ext /** * Mobile: Alias for template-mobile access * */ if($_SERVER['HTTP_HOST'] == 'm.domain.ext') { $config->urls->templates = $config->urls->site . 'templates-mobile/'; $config->paths->templates = $config->paths->site . 'templates-mobile/'; }
    1 point
  45. Hi, Just my 5 cents. Give Closure Compiler Service a try. It is good at removing "dead" code, i.e. the functions of your libraries/frameworks that are not used in your JS code.
    1 point
  46. On my new development I now use this tree structure: Parentpage - countries childpage hold "country"-name childpage of country-name hold province-name childpage of province-name hold city-name country field, 1st select, for country value = normal parent select > "countries" province field, 2nd select, for province name OF country selected value = custom selector > "parent=page.country' city field, 3rth select, for city name OF province selected value = custom selector > "parent=page.province'. Works great!
    1 point
  47. No offense intended to Khan, but in its current state, that module has several bugs. It also has a lot more than most people/sites need. I would recommend building your own using these posts as help: http://processwire.com/talk/topic/1716-integrating-a-member-visitor-login-form/ http://processwire.com/talk/topic/107-custom-login/ http://processwire.com/talk/topic/2937-creating-a-front-end-admin/
    1 point
  48. I recently had to setup front-end system to handle logins, password resets and changing passwords, so here's about how it was done. This should be functional code, but consider it pseudocode as you may need to make minor adjustments here and there. Please let me know if anything that doesn't compile and I'll correct it here. The template approach used here is the one I most often use, which is that the templates may generate output, but not echo it. Instead, they stuff any generated output into a variable ($page->body in this case). Then the main.php template is included at the end, and it handles sending the output. This 'main' template approach is preferable to separate head/foot includes when dealing with login stuff, because we can start sessions and do redirects before any output is actually sent. For a simple example of a main template, see the end of this post. 1. In Admin > Setup > Fields, create a new text field called 'tmp_pass' and add it to the 'user' template. This will enable us to keep track of a temporary, randomly generated password for the user, when they request a password reset. 2a. Create a new template file called reset-pass.php that has the following: /site/templates/reset-pass.php $showForm = true; $email = $sanitizer->email($input->post->email); if($email) { $u = $users->get("email=$email"); if($u->id) { // generate a random, temporary password $pass = ''; $chars = 'abcdefghjkmnopqrstuvwxyz23456789'; // add more as you see fit $length = mt_rand(9,12); // password between 9 and 12 characters for($n = 0; $n < $length; $n++) $pass .= $chars[mt_rand(0, strlen($chars)-1)]; $u->of(false); $u->tmp_pass = $pass; // populate a temporary pass to their profile $u->save(); $u->of(true); $message = "Your temporary password on our web site is: $pass\n"; $message .= "Please change it after you login."; mail($u->email, "Password reset", $message, "From: noreply@{$config->httpHost}"); $page->body = "<p>An email has been dispatched to you with further instructions.</p>"; $showForm = false; } else { $page->body = "<p>Sorry, account doesn't exist or doesn't have an email.</p>"; } } if($showForm) $page->body .= " <h2>Reset your password</h2> <form action='./' method='post'> <label>E-Mail <input type='email' name='email'></label> <input type='submit'> </form> "; // include the main HTML/markup template that outputs at least $page->body in an HTML document include('./main.php'); 2b. Create a page called /reset-pass/ that uses the above template. 3a. Create a login.php template. This is identical to other examples you may have seen, but with one major difference: it supports our password reset capability, where the user may login with a temporary password, when present. When successfully logging in with tmp_pass, the real password is changed to tmp_pass. Upon any successful authentication tmp_pass is cleared out for security. /site/templates/login.php if($user->isLoggedin()) $session->redirect('/profile/'); if($input->post->username && $input->post->pass) { $username = $sanitizer->username($input->post->username); $pass = $input->post->pass; $u = $users->get($username); if($u->id && $u->tmp_pass && $u->tmp_pass === $pass) { // user logging in with tmp_pass, so change it to be their real pass $u->of(false); $u->pass = $u->tmp_pass; $u->save(); $u->of(true); } $u = $session->login($username, $pass); if($u) { // user is logged in, get rid of tmp_pass $u->of(false); $u->tmp_pass = ''; $u->save(); // now redirect to the profile edit page $session->redirect('/profile/'); } } // present the login form $headline = $input->post->username ? "Login failed" : "Please login"; $page->body = " <h2>$headline</h2> <form action='./' method='post'> <p> <label>Username <input type='text' name='username'></label> <label>Password <input type='password' name='pass'></label> </p> <input type='submit'> </form> <p><a href='/reset-pass/'>Forgot your password?</a></p> "; include("./main.php"); // main markup template 3b. Create a /login/ page that uses the above template. 4a. Build a profile editing template that at least lets them change their password (but take it further if you want): /site/templates/profile.php // if user isn't logged in, then we pretend this page doesn't exist if(!$user->isLoggedin()) throw new Wire404Exception(); // check if they submitted a password change $pass = $input->post->pass; if($pass) { if(strlen($pass) < 6) { $page->body .= "<p>New password must be 6+ characters</p>"; } else if($pass !== $input->post->pass_confirm) { $page->body .= "<p>Passwords do not match</p>"; } else { $user->of(false); $user->pass = $pass; $user->save(); $user->of(true); $page->body .= "<p>Your password has been changed.</p>"; } } // display a password change form $page->body .= " <h2>Change password</h2> <form action='./' method='post'> <p> <label>New Password <input type='password' name='pass'></label><br> <label>New Password (confirm) <input type='password' name='pass_confirm'></label> </p> <input type='submit'> </form> <p><a href='/logout/'>Logout</a></p> "; include("./main.php"); 4b. Create a page called /profile/ that uses the template above. 5. Just to be complete, make a logout.php template and create a page called /logout/ that uses it. /site/templates/logout.php if($user->isLoggedin()) $session->logout(); $session->redirect('/'); 6. The above templates include main.php at the end. This should just be an HTML document that outputs your site's markup, like a separate head.inc or foot.inc would do, except that it's all in one file and called after the output is generated, and we leave the job of sending the output to main.php. An example of the simplest possible main.php would be: /site/templates/main.php <html> <head> <title><?=$page->title?></title> </head> <body> <?=$page->body?> </body> </html>
    1 point
  49. Absolutely! Here is a simple, but functional example for both login and logout templates. You would want to replace the markup with your own markup or includes. Likewise you'd want to change the redirects to redirect to whatever page you want them to go to after completing a login. /site/templates/login.php: <?php if($user->isLoggedin()) { // user is already logged in, so they don't need to be here $session->redirect("/somewhere/"); } // check for login before outputting markup if($input->post->user && $input->post->pass) { $user = $sanitizer->username($input->post->user); $pass = $input->post->pass; if($session->login($user, $pass)) { // login successful $session->redirect("/somewhere/"); } } ?> <html> <head> <title>Login</title> </head> <body> <form action='./' method='post'> <?php if($input->post->user) echo "<h2 class='error'>Login failed</h2>"; ?> <p><label>User <input type='text' name='user' /></label></p> <p><label>Password <input type='password' name='pass' /></label></p> <p><input type='submit' name='submit' value='Login' /></p> </form> </body> </html> /site/templates/logout.php: <?php $session->logout(); ?> <html> <head> <title>Logout</title> </head> <body> <h1>You have logged out</h1> </body> </html>
    1 point
×
×
  • Create New...