Jump to content

adrianmak

Members
  • Posts

    533
  • Joined

  • Last visited

Everything posted by adrianmak

  1. I expected , when viewing the submitted form data, it will presented into a normal page instead of a edit form page.
  2. I enabled save form as page with this line of code as instructed from the readme $form->parent = $page; all submitted form are saved. When I view each of submitted form result, it just show me a form I have to use edit to edit form result to see the data
  3. how to add a autofocus attribue on a input element I tried to add this attribute with this line of code. But it didn't work. I'm expected it require a value to output the attribute. However, it is odd to give whatever value to autofocus attribute as it is not necessary under html5 spec $field->attr("autofocus","");
  4. I tried all the four const value on the code $submit->skipLabel = xxxxxxx ; skipLabelHeader skipLabelBlank skipLabelFor skipLabelNo but not work
  5. $submit = $modules->get("InputfieldSubmit"); $submit->attr("value","Submit"); $submit->attr("name","submit"); how to get rid of the label of a submit button ? Even though I don't provide the label attribute, it will use the name attribute as the label name
  6. How could I change individual field markup and class ? The default html markup is not or to much for bootstrap. For example, each input element is wrapped by a div, this html markup is too much and I want to get rid of it.
  7. This is my original question asking for access control for a template https://processwire.com/talk/topic/8847-redirect-to-a-url-in-the-access-tab-of-a-template/ Eventually, as of Soma suggestion, I implemented access control and redirection in template itself. The problem is after a sucessful login, the $session ->redirect method only destinate to one assigned url (in my case it is the homepage). Reading the api doc, the session redirect provide just a simple url redirection. NO MORE functionality provided. Then I append a GET variable on redirect url a page template required a specific user role privilege <?php if (!$user->isLoggedin()) { /* get current page id for page redirection after a successful login */ $pageId = $page->id; $session->redirect(($pages->get("template=login")->url . "?redirect=" . $pageId)); } /* required user with role registered to view this template */ if ($user->hasRole("registered")) { $page->title; $page->body; } else { $page->body = "Your account do not have enough access privileges to view this page."; } include('./main.php'); login form template <?php $pageID = $_GET["redirect"]; $lang = ($user->language->name == 'default') ? '' : $user->language->name . '/'; if ($user->isLoggedin()) { $session->redirect($config->urls->root . $lang); } if ($input->post->user && $input->post->pass) { $username = $sanitizer->username($input->post->user); $password = $input->post->pass; $pageID = $input->post->redirect; $redirectPage = $pages->get($pageID)->url; try { if ($session->login($username, $password)) { if ($redirectPage) $session->redirect($redirectPage); $session->redirect($config->urls->root . $lang); } else { $error = "Wrong username or password. Login failed."; } } catch (Exception $e) { $error = $e->getMessage(); } } $form_title = __("Sign In"); $form_user = __("User"); $form_pass = __("Password"); $form_submit_btn = __("Sign in"); $form_error = __("Login failed"); $page->title = "User Login"; $page->body .= " <div class='container'> <div class='col-md-12'> <div class='login-box'> <div class='panel panel-default'> <div class='panel-heading'> <h3 class='panel-title'><span class='lock-icon'></span><strong>$form_title</strong></h3> </div> <div class='panel-body'> <form role='form' action='./' method='post'> <div class='message-error'>$error</div> <input type='hidden' name='redirect' value=$pageID /> <div class='form-group'> <label for='user'>$form_user</label> <input type='text' name='user' id='user' class='form-control' placeholder=$form_user /> </div> <div class='form-group'> <label for='pass'>$form_pass</label> <input type='password' name='pass' id='pass' class='form-control' placeholder=$form_pass /> </div> <button type='submit' class='btn btn-sm btn-primary'>$form_submit_btn</button> </form> </div> </div> </div> </div> </div> "; include('./main.php'); ?> Retrieve the original url from the GET variable and store in a form hidden field. When a successful login, checking this variable, if null , redirect to homepage or otherwise to that url is it secure to implement in this way ?
  8. I'm thinking of this code if (!$user->isLoggedin()) { $session->redirect($pages->get("template=login")->url); } if ($user->hasRole("registered")) { $page->title; $page->body; } else { $page->body = "Your account do not have enough access privileges to view this page."; } include('./main.php'); Before make a redirection, save current page url and pass direction with saved url to the login page (a custom form) , then in the custom form, when a successful login, it will check this passing variable is null, redirect to home otherwirse redirect to the url. How could i pass other information to another page in a session redirection ?
  9. Now I turn off the access control in the template and put following code in this template file <?php if (!$user->isLoggedin()) { $session->redirect($pages->get("template=login")->url); } if ($user->hasRole("registered")) { $page->title; $page->body; } else { $page->body = "Your account do not have enough access privileges to view this page."; } include('./main.php'); However, a user with that role, after login , it will redirect to home but not display that page a user without that role, after login, it will redirect to home but not display "Your account do not have enough access privileges to view this page." This is my login template file <?php $lang = ($user->language->name == 'default') ? '' : $user->language->name . '/'; if ($user->isLoggedin()) { $session->redirect($config->urls->root . $lang); } if ($input->post->user && $input->post->pass) { $username = $sanitizer->username($input->post->user); $password = $input->post->pass; try { if ($session->login($username, $password)) { $session->redirect($config->urls->root . $lang); } else { $error = "Wrong username or password. Login failed."; } } catch (Exception $e) { $error = $e->getMessage(); } } $form_title = __("Sign In"); $form_user = __("User"); $form_pass = __("Password"); $form_submit_btn = __("Sign in"); $form_error = __("Login failed"); $page->title = "User Login"; $page->body .= " <div class='container'> <div class='col-md-12'> <div class='login-box'> <div class='panel panel-default'> <div class='panel-heading'> <h3 class='panel-title'><span class='lock-icon'></span><strong>$form_title</strong></h3> </div> <div class='panel-body'> <form role='form' action='./' method='post'> <div class='message-error'>$error</div> <div class='form-group'> <label for='user'>$form_user</label> <input type='text' name='user' id='user' class='form-control' placeholder=$form_user /> </div> <div class='form-group'> <label for='pass'>$form_pass</label> <input type='password' name='pass' id='pass' class='form-control' placeholder=$form_pass /> </div> <button type='submit' class='btn btn-sm btn-primary'>$form_submit_btn</button> </form> </div> </div> </div> </div> </div> "; include('./main.php'); ?> I knew that there is something to do in successful login to fulfill my task (current it is all redirect to home) But how ?
  10. you're right, Soma. Handle redirect in template directly is much more flexible than in the access tab
  11. i am building a multi-language site with some restricted pages available for a specific user role only. Under the access tab of a template, here there are three options for pages with no access - Show a 404 Page - Show the Login page: /pw1/processwire/login/ - Redirect to another URL I use the third one, Redirect to another URL, which is a front-end user login (instead of pw login page) /pw1/user/login That option seems only for a hard-coded url. If a user changed to another language at the front-end, when view a restricited page, he/she will still redirect to that url but won't with a language prefixed url, e.g. /pw1/cht/user/login
  12. I'm studying your code. Which line(s) of code which save the path for redirection back to it when login sucessfully.
  13. I'm building a front-end login form on a multi-language pw website. I built a logoff form. I have some translated string in the logoff template file and those has been translated. When I sign in with another language, and logoff, the logoff message won't display the translated string. Here is a video I recorded my logoff template file <?php $lang = ($user->language->name == 'default') ? '' : $user->language->name . '/'; if ($user->isLoggedin()) { $session->logout(); } else { // $session->redirect($config->urls->root . $lang); } $logoutText = __("You have logged out."); //$pageRefresh = "<meta http-equiv='refresh' content='3;url={$config->urls->root}{$lang}'>"; $page->body .= $logoutText; include('./main.php'); ?> my main,php file <?php $signin_text = __("Sign in"); $logoff_text = __("Logout"); ?> <!DOCTYPE html> <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <?php echo $pageRefresh; ?> <title><?php echo $page->title; ?></title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> <link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>assets/css/normalize.css" /> <script src="<?php echo $config->urls->templates?>assets/js/vendor/modernizr-2.6.2.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css"> <link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>assets/css/main.css"> </head> <body> <!--[if lt IE 7]> <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> <![endif]--> <!-- Add your site or application content here --> <nav class="navbar navbar-default navbar-static-top"> <nav class="nav navbar-left"> <div><?php echo $page->title; ?> | Learing processwire</div> </nav> <?php $lang = ($user->language->name == 'default') ? '' : $user->language->name . '/'; if ($user->isLoggedin()) { echo <<< _OUT <nav class="nav navbar-right"> Welcome $user->name<br/> <a href="{$config->urls->root}{$lang}user/logoff">$logoff_text</a> </nav> _OUT; } else { echo <<< _OUT <div class="navbar-right"> <a href="{$config->urls->root}{$lang}user/login">$signin_text</a> </div> _OUT; } ?> </nav> <div class="header"> <ul class="nav nav-pills"> <?php $homepage = $pages->get('/'); foreach($homepage->and($homepage->children) as $item) { if($item->id == $page->rootParent->id) echo "<li class='current'>"; else echo "<li>"; echo "<a href='$item->url'>$item->title</a></li>"; } ?> </ul> <ul class="languages"> <?php $currentLanguage = $user->language; // remember language foreach($languages as $language) { if(!$page->viewable($language)) continue; // is page viewable in this language? $user->language = $language; if($language->id == $currentLanguage->id) { echo "<li class='current'>"; } else { echo "<li>"; } echo "<a href='$page->url'>$language->title</a></li>"; } $user->language = $currentLanguage; // restore language ?> </ul> </div> <div class="content"> <?php echo $page->body; ?> </div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script> <script>window.jQuery || document.write('<script src="<?php echo $config->urls->templates?>assets/js/vendor/jquery-1.10.2.min.js"><\/script>')</script> <script src="<?php echo $config->urls->templates?>assets/js/plugins.js"></script> <script src="<?php echo $config->urls->templates?>assets/js/main.js"></script> <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. --> <script> (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]= function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date; e=o.createElement(i);r=o.getElementsByTagName(i)[0]; e.src='//www.google-analytics.com/analytics.js'; r.parentNode.insertBefore(e,r)}(window,document,'script','ga')); ga('create','UA-XXXXX-X');ga('send','pageview'); </script> </body> </html>
  14. while read the pw logs, it said that Error: Call to a member function isLoggedin() on a non-object (line 42 of /var/www/html/pw1/site/templates/main.php) <?php $signin_text = __("Sign in"); $logoff_text = __("Logout"); ?> <!DOCTYPE html> <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <?php echo $pageRefresh; ?> <title><?php echo $page->title; ?></title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> <link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>assets/css/normalize.css" /> <script src="<?php echo $config->urls->templates?>assets/js/vendor/modernizr-2.6.2.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css"> <link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>assets/css/main.css"> </head> <body> <!--[if lt IE 7]> <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> <![endif]--> <!-- Add your site or application content here --> <nav class="navbar navbar-default navbar-static-top"> <nav class="nav navbar-left"> <div><?php echo $page->title; ?> | Learing processwire</div> </nav> <?php $lang = ($user->language->name == 'default') ? '' : $user->language->name . '/'; if ($user->isLoggedin()) { echo <<< _OUT <nav class="nav navbar-right"> Welcome $user->name<br/> <a href="{$config->urls->root}{$lang}user/logoff">$logoff_text</a> </nav> _OUT; } else { echo <<< _OUT <div class="navbar-right"> <a href="{$config->urls->root}{$lang}user/login">$signin_text</a> </div> _OUT; } ?> </nav> <div class="header"> <ul class="nav nav-pills"> <?php $homepage = $pages->get('/'); foreach($homepage->and($homepage->children) as $item) { if($item->id == $page->rootParent->id) echo "<li class='current'>"; else echo "<li>"; echo "<a href='$item->url'>$item->title</a></li>"; } ?> </ul> <ul class="languages"> <?php $currentLanguage = $user->language; // remember language foreach($languages as $language) { if(!$page->viewable($language)) continue; // is page viewable in this language? $user->language = $language; if($language->id == $currentLanguage->id) { echo "<li class='current'>"; } else { echo "<li>"; } echo "<a href='$page->url'>$language->title</a></li>"; } $user->language = $currentLanguage; // restore language ?> </ul> </div> <div class="content"> <?php echo $page->body; ?> </div> <?php $lang = ($user->language->name == 'default') ? '' : $user->language->name . '/'; // echo $lang; ?> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script> <script>window.jQuery || document.write('<script src="<?php echo $config->urls->templates?>assets/js/vendor/jquery-1.10.2.min.js"><\/script>')</script> <script src="<?php echo $config->urls->templates?>assets/js/plugins.js"></script> <script src="<?php echo $config->urls->templates?>assets/js/main.js"></script> <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. --> <script> (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]= function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date; e=o.createElement(i);r=o.getElementsByTagName(i)[0]; e.src='//www.google-analytics.com/analytics.js'; r.parentNode.insertBefore(e,r)}(window,document,'script','ga')); ga('create','UA-XXXXX-X');ga('send','pageview'); </script> </body> </html> What's wrong with that line in my main.php ?
  15. This is my code for frontend user login <?php $lang = ($user->language->name == 'default') ? '' : $user->language->name . '/'; if ($user->isLoggedin()) { $session->redirect($config->urls->root . $lang); } if ($input->post->user && $input->post->pass) { $user = $sanitizer->username($input->post->user); $pass = $input->post->pass; if ($session->login($user, $pass)) { $session->redirect($config->urls->root . $lang); //$template = $page->template; //echo "Login successful. You are in $template->name template"; } } $form_title = __("Sign In"); $form_user = __("User"); $form_pass = __("Password"); $form_submit_btn = __("Sign in"); $form_error = __("Login failed"); //if($input->post->user) echo "<h2 class='error'>$form_error</h2>"; $page->title = "User Login"; $page->body .= " <div class='container'> <div class='col-md-12'> <div class='login-box'> <div class='panel panel-default'> <div class='panel-heading'> <h3 class='panel-title'><span class='lock-icon'></span><strong>$form_title</strong></h3> </div> <div class='panel-body'> <form role='form' action='./' method='post'> <div class='form-group'> <label for='user'>$form_user</label> <input type='text' name='user' id='user' class='form-control' placeholder=$form_user /> </div> <div class='form-group'> <label for='pass'>$form_pass</label> <input type='password' name='pass' id='pass' class='form-control' placeholder=$form_pass /> </div> <button type='submit' class='btn btn-sm btn-default'>$form_submit_btn</button> </form> </div> </div> </div> </div> </div> "; include('./main.php'); ?> The login page show properly. However, when login with a wrong username or password, it returned internal server error Anything wrong with my code?
  16. <?php //$template = $page->template; //echo "Your are in $template->name template"; if ($user->isLoggedin()) { $session->logout(); } else { $session->redirect("/pw1"); } $logoutText = __("<h1>You have logged out</h1><p>You will be redirect to homepage in 3 seconds</p>"); ?> <html> <head> <title>Logout</title> <meta http-equiv="refresh" content="3;url=/pw1"> </head> <body> <?php echo $logoutText; ?> </body> </html>
  17. i want to translate a string with html tag like $error = __("<h2 class='error'>this is a string</h2>"); After translated, the echoed string is <h2 class='error'>a translated string</h2>. however, when the text show up on website, the html tag in the translated string won't work.
  18. My pw is installed under a sub-folder i.e http://localhost/pwtest i just created a frontend user login page. The url path is /user/login in the main template I have hard-coded a login link <a href="user/login">Sign in</a> At the homepage, the login url look good, it will show http://localhost/pwtest/user/login However when I go to another page say a contact page http://localhost/pwtest/contact When hover the login link, it changed to http://localhost/pwtest/contact/user/login and it is not a correct link
  19. when enter pw api variables, how to auto code completion in sublime text ?
  20. is there any pw api get current url path ? I'm thinking of config path for user login, logoff let say /user/login /user/logoff /user <---- check if isloggedin redirect to user profile, otherwiese redirect to /user/login
×
×
  • Create New...