Yii Confirm password before deleting model - php

my system (built in Yii 1.1.19), I have several instances where I delete a record, and I have a confirm request to bring an alert before it continues to delete - all works fine, see below;
$this->menu = array(
array('label' => 'Delete User', 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => "Are you sure you want to delete this user?",
'params' => array(Yii::app()->getRequest()->csrfTokenName => Yii::app()->getRequest()->csrfToken))),
);
Pretty standard Yii - however, I want the user to confirm their password before they delete specific records, as an extra security measure. Not necessarily within its own user model either, i.e. I might want to check the user's password before I delete a specific setting from a different model.
I understand what I need to do once I have an input - how to check the existing password, but I can't figure out how to actually alter the confirm to get the input form instead of standard confirm.
Can anyone help? Sounds like a straightforward request, but I can't seem to much online

Have you tried using "prompt" instead of confirm? or using a JS function and then calling prompt? https://www.w3schools.com/jsref/met_win_prompt.asp
That should allow you to get an input for the password. However, i don't think that's the best way since passwords are expected to be masked (prompt doesn't mask the input) so, what i would propose instead is to use an ajax loaded html form (could be modal) so you could properly handle the the password

Related

How to to implement a forgot password feature using the Google Identity Toolkit in php

I am trying to add google identity toolkit in php. Signin option is working correctly but when i am clicking on problem in sign in link it is showing capthca after submitting captcha it is not navigating to any url.
email.php
<?php
include "identity-toolkit-php-client-master/src/GitkitClient.php";
$gitkitClient=new Gitkit_Client();
$oob_response = $gitkitClient->getOobResults($_POST);
$oob_link = $oob_response['oobLink'];
echo json_encode($oob_response);
?>
email.php is the oobactionurl file. when i am using this code I am getting this error .image
You need to create a php file to retrieve and send the reset link to the user. Make sure the oobActionUrl widget option points to this file. Within the file, you'll get the generated link and additional information by calling $gitkitClient->getOobResults($_POST). It should also work if you exclude $_POST, as the function will check the post contents if no arguments are passed. Then, you can get the link itself like this:
$oob_response = $gitkitClient->getOobResults($_POST);
$oob_link = $oob_response['oobLink'];
From there, you can use your email function of choice to send it to the user. The returned array should contain the following.
'email' => email of the user,
'oldEmail' => old email (for ChangeEmail only),
'newEmail' => new email (for ChangeEmail only),
'oobLink' => url for user click to finish the operation,
'action' => 'RESET_PASSWORD', or 'CHANGE_EMAIL',
'response_body' => http response to be sent back to Gitkit widget
Let me know if you have any further questions.

CakePHP / PHP If Statement User Login Error / Issue - Both conditions are set true?

I am using CakePHP 2.2.2 and building session information with it, to store all the users login details, so that I can access them though out my whole site. The code I have written is below:
if (($GetPass == $this->data['Menu']['password'] && $GetUsers == $this->data['Menu']['username'])) {
$this->Session->write('LoginData', array(
'FristName' => $SQL[$key]['User']['fristname'],
'SurName' => $SQL[$key]['User']['surname'],
'UserName' => $SQL[$key]['User']['username'],
'AccessLevel' => $SQL[$key]['Role']['title'],
'Email' => $SQL[$key]['User']['email']
));
} else {
$this->Session->setFlash('Sorry Login Details Do Not Match Our Records', array('element' => 'failure'));
}
The issue I have with this is driving me up the wall, both conditions are always true. So even if the username & password are within the database, it is still setting the flash message? I just can not see why? The 'else' part of a if statement should only run if the conditions set within the if statement are false, right? So why is my flash message always being set?
There might be two reasons, first the password field you get from CakePHP Model might be encrypted. Use debug($GetPass); and check if it is encrypted or not. Second you are trying to use $this->data in controller which should be $this->request->data. Standard way to do what you are trying to do is given here: http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html

HtmlEntities and Zend TextArea

I'm fairly new to ZF.
I've been building a website on Zend Framework.
Everything looks good.
But I can't figure out how to resolve 1 problem, that actually is essential when developing article management module.
I've got form that has ZEND_TextArea that looks like this:
$full_text = new Zend_Form_Element_TextArea('full_text');
$full_text->setLabel('Description:')
->setOptions(array('rows' => '28','cols' => '40'))
->setRequired(true)
->addValidator('NotEmpty', true)
->addFilter('HTMLEntities')
->addFilter('StringTrim');
It work great, it has filter HTMLEntities that is really essential for filtering TextArea.
When displaying the saved data on the website I'm using html_entity_decode($item['full_text']) and it's fine.
But as soon as I try to edit it, it loads encoded text into my textarea, after editing it encodes my already encoded text - and on the front page I get terrible things like:
p;quot;color: #ff0000;&amp;amp;quot;&amp;amp;gt;asdasda&amp;amp;lt;/
span&amp;amp;gt;sdas &amp;amp;lt;strong&amp;amp;gt;sdfsdf&amp;amp;
lt;/strong&amp;amp;gt;&
Maybe someone can help me figure out how to handle this problem, particularly load decoded data into Edit form of TextArea, so that my string doesn't get encoded twice, and when editing it was show in human manner and not into encoded one.
If you can provide code example - will be really AWESOME!!
thanks!!
Do not use HtmlEntities filter in edit form, if you use it in create form.
Create form :
$elements[] = $this->createElement('text','name',array(
'label' => 'test',
'filters' => array('HtmlEntities'),
));
Edit Form :
$elements[] = $this->createElement('text','name',array(
'label' => 'test',
'value' => html_entity_decode($value)
));
Your doing html_entity_decode() to set value, to show right 'name' to user..
When UPDATING data in model, you use htmlEntities filter again:
$data['name'] = $HtmlEntities->filter($data['name']);

SugarCRM - How to set the default homepage for all users

I am using SugarCRM Version 5.2.0k (Build 5837). I would like to be able to set a default home page (with dashlets I've created myself) that will be the same for all users, can anyone advice on best way to do this?
Thanks in advance for your help
I'd like to know how to do this too... see here for some ideas, but it's clear that it's not a supported feature.
I wonder if you can write a module that installs a hook for post user creation (assuming that this hook is provided) and then populate the appropriate part of the user preferences table when the hook is invoked. Of course, your module will probably break with each upgrade of SurgarCRM, so this might be more trouble than it i worth.
Edit:
I had a look at the Dash Manager module that is referenced in the thread I linked to above. It's approach is to copy the preferences of the admin user to all other users when the administrator clicks a link in the admin page. So, the admin user is used as a sort of template for other users. Rudimentary solution, but not a bad start - using a template user and treating the preferences (as stored in the DB table) as opaque seems like the way to go.
It's quite easy to do it.
I have done it in SugarCRM 6.5.23.
Here I have mentioned steps to do it:
Just copy sugarcrm_root/modules/Home/index.php and paste it in SugarCRM_root/custom/modules/Home/index.php.
Now you can customize it's behavior as you want.
You can remove default dashlets and add your own dashlets by creating one file at SugarCRM_root/custom/modules/Home/dashlets.php and add this code in it:
<?php
unset($defaultDashlets);
$defaultDashlets = array(
'CustomDashlet' => 'ModuleName',
'UpcomingAppointmentsDashlet' => 'Meetings', //Example
);
Once you do this thing still you have 3 dashlets left in your hook code you can remove it if it's needed code for that hook is like this:
$dashlets[create_guid()] = array(
'className' => 'iFrameDashlet',
'module' => 'Home',
'forceColumn' => 0,
'fileLocation' => $dashletsFiles['iFrameDashlet']['file'],
'options' => array('titleLabel' => 'LBL_DASHLET_DISCOVER_SUGAR_PRO',
'url' => '...',
'height' => 315,
));
Hope this will help you. :)

Drupal - Automate a Content Form Submission

I would like to programatically (using php) fill out an existing drupal form to create a content type that is included in a contributed module.
Details: The module is SimpleFeed and the content type is Feed. I would like to call the module's functions to accomplish this. The method I am interested in is hook_insert which appears to require vid and nid which I am unsure what these are.
Any help is appreciated.
can you provide a bit more information (which modules?). generally, i'd probably suggest calling the modules functions to create the content type, instead of trying to pass it through a form programatically. this way you don't have to worry about implementation, and can trust that if the module works, it'll work for your script too :)
of course this does tie your module to theirs, so any changes in their functions could affect yours. (but then again, you run that risk if they update their database structure too)
ex.
// your file.php
function mymodule_do_stuff() {
cck_create_field('something'); // as an example, i doubt this
// is a real CCK function :)
}
edit: vid and nid are node ID's, vid is the revision id, and nid is the primary key of a particular node. because this is an actual node, you may have to do two operations.
programatically create a node
you'll have to reference the database for all the exact fields (tables node and node_revisions), but this should get you a basic working node:
$node = (object) array(
'nid' => '', // empty nid will force a new node to be created
'vid' => '',
'type' => 'simplefeed'. // or whatever this node is actually called
'title' => 'title of node',
'uid' => 1, // your user id
'status' => 1, // make it active
'body' => 'actual content',
'format' => 1,
// these next 3 fields are the simplefeed ones
'url' => 'simplefeed url',
'expires' => 'whatever value',
'refresh' => 'ditto',
);
node_save($node);
now i think it should automatically call simplefeed's hook_insert() at this point. if not, then go on to 2. but i'd check to see if it worked out already.
call it yourself!
simplefeed_insert($node);
edit2: drupal_execute() isn't a bad idea either, as you can get back some validation, but this way you don't have to deal with the forms API if you're not comfortable with it. i'm pretty sure node_save() invokes all hooks anyhow, so you should really only have to do step 1 under this method.
The drupal api provides drupal_execute() to do exactly this. I would suggest you avoid calling the functions directly to create the node (unless there is a performance reason). By using drupal_execute() all the proper hooks in other modules will be called and your code is far more likely to continue to work through future versions of drupal.
Note that a classic bug in using this method is not first calling something like
module_load_include('inc', 'node', 'node.pages')
which will load the code for your node creation form.
Calling node_save directly is generally considered deprecated and could leave you with broken code in future versions of drupal.
There is a nice example at this lullabot post

Categories