Skip to content

Commit

Permalink
Yii Port: GCI task #7243213 by yaxar maxson
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@11666 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
dionet committed Dec 16, 2011
1 parent 19b365b commit fe1f019
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 41 deletions.
2 changes: 1 addition & 1 deletion application/config/email.php
Expand Up @@ -8,7 +8,7 @@
$config['siteadminbounce'] = 'your-email@example.net'; // The default email address used for error notification of sent messages for the site administrator (Return-Path)
$config['siteadminname'] = 'Your Name'; // The name of the site administrator

$config['emailmethod'] = 'mail'; // The following values can be used:
$config['emailmethod'] = 'sendmail'; // The following values can be used:
$config['protocol'] = $config['emailmethod'];
// mail - use internal PHP Mailer
// sendmail - use Sendmail Mailer
Expand Down
69 changes: 36 additions & 33 deletions application/controllers/admin/authentication.php
Expand Up @@ -22,6 +22,7 @@
* @package LimeSurvey
* @subpackage Backend
*/

class Authentication extends CAction
{
/**
Expand All @@ -36,6 +37,8 @@ public function run()
$this->login();
elseif (isset($_GET['logout']))
$this->logout();
elseif (isset($_GET['forgotpassword']))
$this->forgotpassword();
else
$this->index();
}
Expand Down Expand Up @@ -127,74 +130,74 @@ public function logout()
*/
public function forgotpassword()
{
$clang = $this->getController()->lang;
if(!$this->input->post("action"))

$clang = Yii::app()->lang;
if(!(isset($_POST["action"])))
{
$data['clang'] = $this->limesurvey_lang;
parent::_getAdminHeader();
$this->load->view('admin/authentication/forgotpassword', $data);
parent::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual"));
$data['clang'] = Yii::app()->lang;
$this->getController()->_getAdminHeader();
$this->getController()->render("/admin/authentication/forgotpassword", $data);
$this->getController()->_getAdminFooter("http://docs.limesurvey.org", Yii::app()->lang->gT("LimeSurvey online manual"));
}
else
{
$postuser = $this->input->post("user");
$emailaddr = $this->input->post("email");

$postuser = $_POST["user"];
$emailaddr = $_POST["email"];

//$query = "SELECT users_name, password, uid FROM ".db_table_name('users')." WHERE users_name=".$connect->qstr($postuser)." AND email=".$connect->qstr($emailaddr);
//$result = db_select_limit_assoc($query, 1) or safe_die ($query."<br />".$connect->ErrorMsg()); // Checked
$this->load->model("Users_model");
$query = $this->Users_model->getSomeRecords(array("users_name, password, uid"),array("users_name"=>$postuser,"email"=>$emailaddr));
$query = User::model()->getSomeRecords(array("users_name, password, uid"),array("users_name"=>$postuser,"email"=>$emailaddr));

if ($query->num_rows() < 1)
if (count($query) < 1)
{
// wrong or unknown username and/or email
$data['errormsg']=$this->limesurvey_lang->gT("User name and/or email not found!");
$data['errormsg']=Yii::app()->lang->gT("User name and/or email not found!");
$data['maxattempts']="";
$data['clang']=$this->limesurvey_lang;
$data['clang']=Yii::app()->lang;

parent::_getAdminHeader();
$this->load->view('admin/authentication/error', $data);
parent::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual"));
$this->getController()->_getAdminHeader();
$this->getController()->render("/admin/authentication/error", $data);
$this->getController()->_getAdminFooter("http://docs.limesurvey.org", Yii::app()->lang->gT("LimeSurvey online manual"));

}
else
{
//$fields = $result->FetchRow();
$fields = $query->row_array();
$fields = $query;

// send Mail
$new_pass = createPassword();
$body = sprintf($clang->gT("Your user data for accessing %s"),$this->config->item("sitename")). "<br />\n";;
$body .= $clang->gT("Username") . ": " . $fields['users_name'] . "<br />\n";
$body = sprintf($clang->gT("Your user data for accessing %s"),Yii::app()->getConfig("sitename")). "<br />\n";;
$body .= $clang->gT("Username") . ": " . $fields[0]['users_name'] . "<br />\n";
$body .= $clang->gT("New password") . ": " . $new_pass . "<br />\n";

$this->load->config("email");
// $this->load->config("email");
$subject = $clang->gT("User data","unescaped");
$to = $emailaddr;
$from = $this->config->item("siteadminemail");
$sitename = $this->config->item("siteadminname");

if(SendEmailMessage($body, $subject, $to, $from, $this->config->item("sitename"), false,$this->config->item("siteadminbounce")))
$from = Yii::app()->getConfig("siteadminemail");
$sitename = Yii::app()->getConfig("siteadminname");
if(SendEmailMessage($body, $subject, $to, $from, Yii::app()->getConfig("sitename"), false,Yii::app()->getConfig("siteadminbounce")))
{
//$query = "UPDATE ".db_table_name('users')." SET password='".SHA256::hashing($new_pass)."' WHERE uid={$fields['uid']}";
//$connect->Execute($query); //Checked
$this->Users_model->updatePassword($fields['uid'], $this->sha256->hashing($new_pass));

User::model()->updatePassword($fields[0]['uid'], hash('sha256', $new_pass));
$data['clang'] = $clang;
$data['message'] = "<br />".$clang->gT("Username").": {$fields['users_name']}<br />".$clang->gT("Email").": {$emailaddr}<br />
$data['message'] = "<br />".$clang->gT("Username").": {$fields[0]['users_name']}<br />".$clang->gT("Email").": {$emailaddr}<br />
<br />".$clang->gT("An email with your login data was sent to you.");
parent::_getAdminHeader();
$this->load->view('admin/authentication/message', $data);
parent::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual"));
$this->getController()->_getAdminHeader();
$this->getController()->render('/admin/authentication/message', $data);
$this->getController()->_getAdminFooter("http://docs.limesurvey.org", Yii::app()->lang->gT("LimeSurvey online manual"));
}
else
{
$tmp = str_replace("{NAME}", "<strong>".$fields['users_name']."</strong>", $clang->gT("Email to {NAME} ({EMAIL}) failed."));
$tmp = str_replace("{NAME}", "<strong>".$fields[0]['users_name']."</strong>", $clang->gT("Email to {NAME} ({EMAIL}) failed."));
$data['clang'] = $clang;
$data['message'] = "<br />".str_replace("{EMAIL}", $emailaddr, $tmp) . "<br />";

$this->getController()->_getAdminHeader();
$this->load->view('admin/authentication/message', $data);
parent::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual"));
$this->getController()->render('/admin/authentication/message', $data);
$this->getController()->_getAdminFooter("http://docs.limesurvey.org", Yii::app()->lang->gT("LimeSurvey online manual"));
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions application/models/User.php
Expand Up @@ -77,7 +77,7 @@ public function getAllRecords($condition=FALSE)
{
foreach ($condition as $item => $value)
{
$criteria->addCondition($item.'="'.$value.'"');
$criteria->addCondition($item.'='.Yii::app()->db->quoteValue($value));
}
}

Expand All @@ -104,13 +104,14 @@ function parentAndUser($postuserid)
*/
public function getSomeRecords($fields,$condition=FALSE)
{

$criteria = new CDbCriteria;

if ($condition != FALSE)
{
foreach ($condition as $item => $value)
{
$criteria->addCondition($item.'="'.$value.'"');
$criteria->addCondition($item.'='.Yii::app()->db->quoteValue($value));
}
}

Expand Down Expand Up @@ -245,8 +246,10 @@ public function getID($fullname)
public function updatePassword($uid,$password)
{
$data = array('password' => $password);
$this->db->where(array("uid"=>$uid));
$this->db->update('users',$data);
//$this->db->where(array("uid"=>$uid));
//$this->db->update('users',$data);
$this->updateByPk($uid, $data);

}

/**
Expand Down
4 changes: 2 additions & 2 deletions application/views/admin/authentication/forgotpassword.php
@@ -1,11 +1,11 @@
<form class="form44" name="forgotpassword" id="forgotpassword" method="post" action="<?php echo current_url();?>" >
<form class="form44" name="forgotpassword" id="forgotpassword" method="post" action="<?php echo $this->createUrl("admin/authentication/forgotpassword");?>" >
<p><strong><?php echo $clang->gT('You have to enter user name and email.');?></strong></p>

<ul>
<li><label for="user"><?php echo $clang->gT('Username');?></label><input name="user" id="user" type="text" size="60" maxlength="60" value="" /></li>
<li><label for="email"><?php echo $clang->gT('Email');?></label><input name="email" id="email" type="text" size="60" maxlength="60" value="" /></li>
<p><input type="hidden" name="action" value="forgotpass" />
<input class="action" type="submit" value="<?php echo $clang->gT('Check Data');?>" />
<p><a href="<?php echo site_url("admin");?>"><?php echo $clang->gT('Main Admin Screen');?></a>
<p><a href="<?php echo $this->createUrl("admin");?>"><?php echo $clang->gT('Main Admin Screen');?></a>
</form>
<p>&nbsp;</p>
2 changes: 1 addition & 1 deletion application/views/admin/authentication/message.php
@@ -1,2 +1,2 @@
<?php echo $message; ?>
<br /><a href='<?php echo current_url();?>'><?php echo $clang->gT("Continue");?></a><br />
<br /><a href='<?php echo Yii::app()->request->requestUri;?>'><?php echo $clang->gT("Continue");?></a><br />

0 comments on commit fe1f019

Please sign in to comment.