Jump to content

Raj

Members
  • Posts

    18
  • Joined

  • Last visited

Everything posted by Raj

  1. Agree with you mate. I have already started going through the doc section once again, hopefully this time I will get the right essence. ?
  2. I can understand Soma, but thank you for your guidance...probably I missed to read through the Docs section properly, let me redo ?
  3. Sure Soma, let me try that ? with re to "You can't call a .php in templates folder, it would have to be somewhere in the webroot." not sure if I am doing it the correct way...all my PHP files are actually residing in site/templates folder, after saving them in this folder I add them as template using the Admin page and access them...and most of my validation pages are called by ajax method defined in custom JS files... I am actually very new to CMS and PHP; learning on my own with abundant help from this forum and Google ? If it doesn't take much time or there is already a page on this, can you help me understand the best way to build a custom site in processwire with custom styles and JS...mainly around where do I place my custom php files...how to utilize processwire to it's capactiy.
  4. Hello Soma, Input field is there in the html form...here is the code , please see after <span> field in the below code -> Could you help guide what you meant by "Why don't you just do it using a real page?" please? <label class="w3-button w3-blue-gray w3-border w3-border-green w3-round-large w3-wide w3-bar uploadimg" style="font-weight:bolder;"><span><i class="fa fa-cloud-upload fa-lg w3-left">&nbsp;|</i></span>Upload Avatar<input type="file" id="upload" accept="image/*" class="avatar"></label>
  5. This is the code that is responsible for invoking the AJAX call. <?php namespace ProcessWire; $session = wire('session'); ?> <span class="w3-col m5"> <div id="upload_img" class="w3-margin w3-border-teal w3-round w3-opacity-min w3-display-container" style="border-style: groove;"> <!--<i class="fa fa-edit w3-xxxlarge w3-hover-red w3-round-large w3-display-bottomright" style="font-weight:bolder;"></i>--> </div> <div class="w3-margin"> <label class="w3-button w3-blue-gray w3-border w3-border-green w3-round-large w3-wide w3-bar uploadimg" style="font-weight:bolder;"><span><i class="fa fa-cloud-upload fa-lg w3-left">&nbsp;|</i></span>Upload Avatar<input type="file" id="upload" accept="image/*" class="avatar"></label> <!--<a class="w3-button w3-blue-gray w3-border w3-border-green w3-round-large w3-wide w3-bar actionUpload"><span><i class="fa fa-cloud-upload fa-lg w3-left">&nbsp;|</i>Change Avatar</span><input type="file" id="upload" value="Choose Image" accept="image/*"></a>--> <button class="w3-button w3-blue-gray w3-border w3-border-green w3-round-large w3-wide w3-bar actionDone" style="font-weight:bolder;"><i class="fa fa-check-circle-o fa-lg w3-left">&nbsp;|</i>Done</button> </div> </span> and this is the AJAX query which is responsible for calling the upload.php page $('#upload').on('change', function () { var reader = new FileReader(); reader.onload = function (e) { $uploadCrop.croppie('bind', { url: e.target.result }).then(function(){ console.log('jQuery bind complete'); }); $('.actionDone').toggle(); $('.uploadimg').toggle(); } reader.readAsDataURL(this.files[0]); }); $('.actionDone').on('click', function (ev) { $('.actionDone').toggle(); $('.uploadimg').toggle(); $uploadCrop.croppie('result', { type: 'canvas', size: 'viewport' }).then(function (response) { $.ajax({ url: '/site/templates/upload.php', type: "POST", data: {"image":response}, success: function (data) { if (data == 'Cropped image uploaded successfully') { html = '<img src="' + response + '" id="img_resp" />'; $("#upload_img").html(html); } else { $("body").append("<div class='upload-error'>" + data + "</div>"); } } }); }); }); Finally this is code in upload.php file that is responsible for uploading the image. <?php namespace ProcessWire; error_reporting(E_ALL); ini_set('display_errors', 1); ob_start(); require_once('/var/www/rajibde/index.php'); ob_end_clean(); $input = wire('input'); $sanitizer = wire('sanitizer'); $config = wire('config'); $session = wire('session'); $upload_path = $config->paths->assets . 'avatar/'; chmod($upload_path, 0777); if ($input->post && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { $user = $session->get('memberName'); $img = $input->post->image; $log->message("image ->" . $img); list($type, $img) = explode(';', $img); list(, $img) = explode(',', $img); list($type,) = explode('/',$type); $img = base64_decode($img); //$img = implode($img,'.',$type); $img = $img . '.' . $type; $log->message("IMG TYPE ->" . $img); $f = new WireUpload($img); $f->setMaxFiles(1); $f->setMaxFileSize(2*1024*1024); $f->setOverwrite(true); $f->setDestinationPath($upload_path); $f->setValidExtensions(array('jpg', 'jpeg', 'png', 'gif')); if(!is_dir($upload_path)) { if(!wireMkdir($upload_path)) throw new WireException("No upload path!"); } $files = $f->execute(); if ($f->getErrors()) { foreach($files as $filename) unlink($upload_path . $filename); foreach($f->getErrors() as $e) echo $e; } else { $log->message("1 ->" . $_FILES); //Save the photo to the avatar field $u = $users->get($user->id); $log->message("2 ->" . $u); $u->of(false); $u->avatar = $upload_path . $files[0]; $log->message("3 ->" . $u->avatar); $u->save(); $u->of(true); unlink($upload_path . $files[0]); print 'Cropped image uploaded successfully'; } } else { echo '<div class="w3-row-padding w3-wide w3-text-red w3-text-jumbo"><strong>Unauthorised access. Your access to this site might be permanently blocked if tresspassing continues</strong></div>'; die(); } ?>
  6. @ryan could please help me on this. I am stuck here and not able to move forward even after spending hours together to understand what and where it is going wrong.
  7. Path is getting populated and stored in DB but the file name and extension is missing in DB. Even the image file doesn't get stored in the upload location -> site/assets/avatar. ? And I am not able to figure out why it is not saving the image
  8. Yes, only with the upload location but the file name and extension is missing.... In other words "echo files[0]" doesn't yield any value.
  9. Can someone please help me, I am using the same code as mentioned above with some additional security check; even though the result is successful the image file is not being stored in the avatar folder within site/asset. <?php namespace ProcessWire; error_reporting(E_ALL); ini_set('display_errors', 1); ob_start(); require_once('/var/www/rajibde/index.php'); ob_end_clean(); $input = wire('input'); $sanitizer = wire('sanitizer'); $config = wire('config'); $session = wire('session'); $upload_path = $config->paths->assets . 'avatar/'; chmod($upload_path, 0777); if ($input->post && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { $user = $session->get('memberName'); $img = $input->post->image; list($type, $img) = explode(';', $img); list(, $img) = explode(',', $img); list($type,) = explode('/',$type); $img = base64_decode($img); //$img = implode($img,'.',$type); $img = $img . '.' . $type; //print_r('Successful' . $img); $f = new WireUpload($img); $f->setMaxFiles(1); $f->setMaxFileSize(1*1024*1024); $f->setOverwrite(true); $f->setDestinationPath($upload_path); $f->setValidExtensions(array('jpg', 'jpeg', 'png', 'gif')); if(!is_dir($upload_path)) { if(!wireMkdir($upload_path)) throw new WireException("No upload path!"); } $files = $f->execute(); echo $files[0]; if ($f->getErrors()) { foreach($files as $filename) @unlink($upload_path . $filename); foreach($f->getErrors() as $e) echo $e; } else { //Save the photo to the avatar field $u = $users->get($user->id); $u->of(false); $u->avatar = $upload_path . $files[0]; //echo $u->avatar; $u->save(); $u->of(true); @unlink($upload_path . $files[0]); print_r('Successful' . $img . $files[0]); echo 'Cropped image uploaded successfully.'; } } else { echo '<div class="w3-row-padding w3-wide w3-text-red w3-text-jumbo"><strong>Unauthorised access. Your access to this site might be permanently blocked if tresspassing continues</strong></div>'; die(); } ?>
  10. Dear All, Request your assistance on building the Sign In form, my query might be very silly but I am trying from past few days to get this working. Basically, I am calling the LoginPersist module to log the user in, to utilize the persistent cookie setting; however, once logged in I want to check the user role and redirect them to respective page accordingly. I am stuck in referring the $user instance from LoginPersist module to perform this check. Please help... Login page ------------------------ <?php namespace ProcessWire; ob_start(); require_once('/var/www/bluemine/index.php'); require("./ip.php"); ob_end_clean(); if($session->CSRF->hasValidToken()) { $input = wire('input'); $sanitizer = wire('sanitizer'); $config = wire('config'); $session = wire('session'); $ip = ip2long($ipaddress); if ($input->post && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { $rte = array(); $remme = $input->post->rememberme; if($remme == 'rememberme'){ $persist = wire('modules')->get('LoginPersist')->persist(); $uname = $persist->$session->$name; $rte['msg4'] = 'persistent'; if ($uname->hasRole('superuser')) { $rte['msg'] = 'admin'; $rte['route'] = '/admin/access/users/'; } elseif ($uname->hasRole('mine')) { $rte['msg'] = 'member'; $rte['route'] = '/phpconf/'; } else { $rte['msg'] = 'Not Activated'; } } else { if(!$user->isLoggedin()) { $uname = $sanitizer->username($input->post->lname); $pass = $input->post->lpswd; $rte['msg4'] = 'non_persistent'; try { $u = $session->login($uname, $pass); if($u && $u->id) { if ($u->hasRole('superuser')) { //$session->redirect('/admin/access/users/'); $rte['msg'] = 'admin'; $rte['route'] = '/admin/access/users/'; } elseif ($u->hasRole('mine')) { //$session->redirect('/profile/'); $rte['msg'] = 'member'; $rte['route'] = '/phpconf/'; } else { $rte['msg'] = 'Not Activated'; } } else { $rte['msg'] = 'Login Failed'; $errors .= "Login failed."; } echo json_encode($rte); } catch(WireException $e){ // in case of multiple false login (throttle login) $errors .= $e->getMessage(); // get the error message } } else { $rte['msg'] = 'You are already logged in.'; echo json_encode($rte); die(); } } } else { echo "<font color=red><strong>Unauthorised access. Your access to this site might be permanently blocked if tresspassing continues</strong></font>"; die(); } } else { //throw new WireException('CSRF check failed!'); $rte['msg'] = 'Tresspassing'; $rte['msg1'] = '<div class="w3-panel w3-red w3-card-4 w3-display-middle"><p class="w3-jumbo w3-red"><strong><h1>Forgery Attempt:</h1> <h3>The site has closed the connection. This occurs due to abrupt network disruption or in an event of hackers trying to steal information.</h3> <h2><small>Return to <a href="./">Homepage</a></small></h2></strong></p>'; echo json_encode($rte); die(); } ?> AJAX post from Login Page... $.ajax({ type: 'POST', url: url, data: postData, dataType: 'json', success: function (data) { if(data.msg == "member") { window.location.href = data.route; } else if(data.msg == "admin") { window.location.href = data.route; } else if(data.msg == "Not Activated") { $('#errmsg').css('display','block'); $('#loginerror').html('You are yet to activate the account. Please follow the link sent via email during registration for activation.'); document.getElementById('limgcaptcha').src="/site/templates/lcaptcha.php?id=" +((new Date()).getTime()); $('#loginform :input').attr('disabled', false); $('#show_pswd').attr('disabled',false); document.getElementById('lname').value = ""; document.getElementById('lpswd').value = ""; document.getElementById('lsec').value = ""; $("#cookie").prop('checked',false ); } else if(data.msg == "Login Failed") { $('#errmsg').css('display','block'); $('#loginerror').html('Login Failed. Please try again, or use the forgot password link below.'); document.getElementById('limgcaptcha').src="/site/templates/lcaptcha.php?id=" +((new Date()).getTime()); $('#loginform :input').attr('disabled', false); $('#show_pswd').attr('disabled',false); document.getElementById('lname').value = ""; document.getElementById('lpswd').value = ""; document.getElementById('lsec').value = ""; $("#cookie").prop('checked',false ); } else if(data.msg == "Tresspassing") { $('#main').html(data.msg1); //$('#errmsg').css('display','block'); //$('#loginerror').html(data.msg1); } } }); }); I know this code if lot more repetitive and can be cut short but I am learning this whole thing (PHP Language -> Processwire, CSS and JavaScript) of my own, hence Site Moderator / Members valuable feedback, above and beyond the exact issue is very much welcomed.
  11. Thank you guys....sorry for the late response, was held up with some stuffs. require_once('...') did the trick finally...had to key in the complete URL - probably miss-configuration of php.ini file.... Now while I have changed to WireMail I am getting the error "Error: Uncaught exception 'ProcessWire\WireException' with message 'Method WireMailSmtp::IsHTML does not exist or is not callable in this context" What does this mean?
  12. Thank you 3fingers for the response, my file is placed under site/templates folder...I even tried adding the require once statement but it did not work.
  13. When I do this , "$input = wire('input');" I get the error - Call to undefined function ProcessWire\wire()... What am I missing? I completely agree with you Kongondo and I am doing that simultaneously...actually I am a no coder, long ago I did my software engg. but could not get any job in this line....so forgot all those concepts, trying to recall mystic memories....The site that I am trying to setup now is just out of my passion for networking and coding...hope I can make something good for my family and friends...
  14. I changed this "$input = wire('input');" to "$input = $this->wire('input');"; however, still get the error "Using $this when not in object context...."
  15. Thank you Kongondo. I am still stuck with this...not able to get my head around, not sure where I am failing. Would you mind helping my out here with the code mentioned initially. How do I make those variables an instance of wire?
  16. Thank you Kongondo. Let me find out how to use these - best way to learn ....meanwhile can you point me to the PW core email thing that you mentioned... On thing to mention - At the very first instance I am awed by the response time and helpful attitude of the members... Thumbs Up Guys...
  17. Thank you fbg13 for pointing me to the appropriate instruction. In that case could you suggest how should I make this work please? $input = wire('input'); $sanitizer = wire('sanitizer'); $roles = wire('roles');
  18. Hello, Hope I am in the right place. For quite sometime now I have been trying to setup a personal website and as part of this process I am trying to setup 'User Registration Page'. I am very new to ProcessWire and still on the learning curve; after going through multiple tutorials I somewhat was able to setup the page. However, facing issue while registering the user...basically I have a custom code that get's called via java script code, if the validations passes. While on the other page I try to reference the wire () function, I am encountering 'Using $this when not in object context' error. Here is the complete code... Any help in resolving this is much appreciated. <?php namespace ProcessWire; // Register Page // +-------------------------------------------+ // | Copyright (C) 2016, http://bluemine.co.in | // +-------------------------------------------+ // +-------------------------------------------+ // | Author: Rajib Dey | // +-------------------------------------------+ session_start(); error_reporting(E_ALL); include('func.php'); require('/usr/share/php/libphp-phpmailer/class.phpmailer.php'); $wire = $this->wire(); $input = wire('input'); // $sanitizer = wire('sanitizer'); // $roles = wire('roles'); $security = $_SESSION['vercode']; print_r($_SESSION); $errors = ""; // check if the form content has been submitted if($input->post->submit) { echo $security; //instantiate variables taking in the form data $full_name = $sanitizer->text($input->post->name); $email = $sanitizer->email($input->post->email); $uname = $sanitizer->username($input->post->username); $pswd = $input->post->password; $cpswd = $input->post->passwordConfirm; $sec = $sanitizer->text($input->post->sec); if($pswd!=$cpswd) $errorMessage = "<br><p class='alert alert-danger alert-error'><strong>Error!</strong> Passwords doesn't match!.</p>"; // create activation code $activation = md5($uname); $activation_code = $config->httpHost."/activation/?user=".$uname."&hash=".$activation; // echo $activation_code; // username vaidation if(strlen($uname) != 0){ if(username_validation($uname) == 0) { $username->error = " "; // $out .= "Sorry that username is already taken!"; ?> <div class="alert alert-warning alert-dismissable fade in"> <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a> <strong>Warning!</strong><?php echo " Sorry that username is already taken. Please retry with a different ID.";?> </div> <?php } else { $out = "Thank you for registering!<br><br>"; $out .= "An email has just been sent to " . $email . " with the url to activate your account"; /* * In this example I am using phpmailer to send the email * I prefer this, but you can also use the mail() function */ $mail = new PHPMailer(); $mail->IsHTML(true); $mail->From = "admin@bluemine.co.in"; $mail->FromName = "Register @ BlueMine"; $mail->AddAddress($email); $mail->AddReplyTo("admin@bluemine.co.in","Register @ BlueMine"); $mail->Subject = "Registration"; $mail->Body = " Hello " . $full_name. ", <br>" . "Thanks for registering at BlueMine - Your Digital Library. To activate your account click the link below! <br><br>" . "Activation Link: <a href='http://".$activation_code."'>".$activation_code."</a>"; $mail->send(); print 'success'; } } }
×
×
  • Create New...