Reset pass

This commit is contained in:
2023-03-04 10:01:59 -05:00
parent 85a20fc52a
commit 02e9eee332
8 changed files with 242 additions and 44 deletions
+3 -3
View File
@@ -34,7 +34,7 @@ class Email extends BaseConfig
* @var string
*/
//public $protocol = 'mail';
public $protocol = 'smtp';
public $protocol = 'mail';
/**
* The server path to Sendmail.
*
@@ -72,7 +72,7 @@ class Email extends BaseConfig
* @var int
*/
//public $SMTPPort = 25;
public $SMTPPort = 465; // 993; //465;
public $SMTPPort = 465; // 993; //465;587; //
/**
* SMTP Timeout (in seconds)
@@ -94,7 +94,7 @@ class Email extends BaseConfig
* @var string
*/
//public $SMTPCrypto = 'tls';
public $SMTPCrypto = 'tls';
public $SMTPCrypto = 'ssl'; // 'tls';
/**
* Enable word-wrap
*
+7
View File
@@ -61,6 +61,9 @@ $routes->post('/en/desktop/api/v2/myfituser/account', 'Myfitauth::users');
$routes->post('/en/desktop/api/v2/myfituser/signup-code', 'Myfitauth::users');
$routes->post('/en/desktop/api/v2/myfituser/resetpass-code', 'Myfitauth::users');
$routes->post('/en/desktop/api/v2/myfituser/test-email', 'Myfitauth::users'); // just atest
$routes->get('/en/desktop/api/v2/myfituser/profile', 'Myfituser::users');
$routes->get('/en/desktop/api/v2/myfituser/myfeed', 'Myfituser::users');
@@ -81,6 +84,10 @@ $routes->get('/en/desktop/api/v2/myfituser/loginhx', 'Myfituser::users');
$routes->get('/en/desktop/api/v2/myfituser/stats', 'Myfituser::users');
$routes->get('/en/desktop/api/v2/myfituser/resources', 'Myfituser::users');
$routes->post('/en/desktop/api/v2/myfituser/resetpass-profile', 'Myfituser::users'); // resetpass-profile
$routes->get('/en/desktop/api/v2/myfituser/home-stats', 'Myfituser::users');
//MYFIT DESKTOP USERS
+29 -4
View File
@@ -41,9 +41,14 @@ class Myfitauth extends BaseController
'login' => ['POST'],
'resetpass' => ['POST'],
'signup-code' => ['POST'],
'resetpass-code' => ['POST']
'resetpass-code' => ['POST'],
'test-email' => ['POST'],
];
// foreach (getallheaders() as $name => $value) {
// log_message('critical', "HEADER $name: $value" );
// }
$res1 = [];
if (array_key_exists($endpoint, $endpoints)) {
} else {
@@ -81,6 +86,10 @@ class Myfitauth extends BaseController
$res1 = $passReset->tempCodes();
break;
case 'test-email':
$res1 = $this->push();
break;
}
return $this->response->setJson($res1);
@@ -88,23 +97,39 @@ class Myfitauth extends BaseController
public function push()
{
$data =[];
$to = 'ameye@chiefsoft.com';//Type here the mail address where you want to send
$subject = 'myFit Signup';//Write here Subject of Email
$message='Conngrats ! You did it.';//Write the message you want to send
$email = \Config\Services::email();
$message='Conngrats ! You did it. -- '.rand(1000,9999);//Write the message you want to send
$email = \Config\Services::email();
$config['protocol'] = 'sendmail';
$config['mailPath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordWrap'] = true;
//$email->initialize($config);
$email->setTo($to);
$email->setFrom('works@chiefsoft.com', 'Just testing the emsil function');//set From
$email->setFrom('support@chiefsoft.com', 'Just testing the emsil function');//set From
$email->setSubject($subject);
$email->setMessage($message);
if($email->send())
{
//echo 'Email has been Sent.';
log_message('critical', "Email has been Sent" );
$data['msg'] ='All good '.rand(100,9999);
}
else{
// echo 'Something went wrong !';
$data['error'] = $email->printDebugger(['headers']);
log_message('critical', "Something went wrong" );
//log_message('critical',$data );
//print_r($data);
}
return $data;
}
//this is dummy function to establish the endpoints before real implementations
private function dummyData($raw_array)
+14 -2
View File
@@ -43,6 +43,7 @@ class Myfituser extends BaseController
$psc = count($pieces);
$endpoint = $psc > 0 ? $pieces[$psc - 1] : '';
log_message('critical', "Enpoint-> ".$endpoint );
$endpoints = [
'account' => ['POST'],
@@ -60,7 +61,9 @@ class Myfituser extends BaseController
'trackcategory' => ['GET'],
'resetpass' => ['POST'],
'tracking' => ['POST'],
'trackinghx' => ['GET']
'trackinghx' => ['GET'],
'resetpass-profile' => ['POST'],
'home-stats' => ['GET']
];
$res1 = [];
@@ -83,7 +86,7 @@ class Myfituser extends BaseController
}
// $raw_array['fff'] = json_decode($this->request->getJSON(), true);
log_message('critical', "Enpoint LOC2-> ".$endpoint );
switch ($endpoint) {
case 'login':
//$userAccess = new \App\Models\userAccess();
@@ -143,6 +146,15 @@ class Myfituser extends BaseController
$myfitTracking = new \App\Models\myfitTracking();
$res1 = $myfitTracking->readTracking($raw_array);
break;
case 'resetpass-profile':
// $res1 = $this->dummyData($raw_array);
$res1 = ( new \App\Models\myfitUserProfile() )->resetPassword($raw_array);
break;
case 'home-stats':
$res1 = ( new \App\Models\userStats() )->homeStats($raw_array);
break;
}
return $this->response->setJson($res1);
+7 -5
View File
@@ -83,7 +83,7 @@ class baseModel extends Model
return 0;
}
public function select_db($UupdateDataArray,$whereAray, $updateTable)
public function select_db($selectItems,$whereAray, $updateTable)
{
$ic = 0;
$UP_part = '';
@@ -93,10 +93,10 @@ public function select_db($UupdateDataArray,$whereAray, $updateTable)
$error_msg = '';
$record_count = -1;
$result =[];
$fields = array_keys($UupdateDataArray);
foreach ($fields as $field) {
//$fields = array_keys($UupdateDataArray);
foreach ($selectItems as $item) {
$UP_part .= $ic > 0 ? ',' : '';
$UP_part .= $UupdateDataArray[$field];
$UP_part .= $item;
$ic++;
}
@@ -107,9 +107,11 @@ public function select_db($UupdateDataArray,$whereAray, $updateTable)
$val_part .= $field."='" . $whereAray[$field] . "'";
$ic++;
}
$sqlQ = "SELECT $UP_part FROM $updateTable $val_part";
$sqlQ = "SELECT $UP_part FROM $updateTable $val_part";
log_message('critical', "SQL:: ". $sqlQ );
$query = $this->db->query($sqlQ);
if($query){
$status = 1;
$result = $query->getResultArray();
$record_count = count($result);
}
+55
View File
@@ -23,4 +23,59 @@ class myfitUserProfile extends baseModel
{
return ['msg' => 'Profile Information'];
}
public function resetPassword($in){
$session_token= trim($in['session_token']);
$member_uuid= trim($in['member_uuid']);
$prev_pass= trim($in['prev_pass']);
$new_pass= trim($in['new_pass']);
/*
mermsemr_dev=> SELECT * FROM members_session WHERE session ='50534367713329088500408985849250550352404565459882532533221349071826496812546205397231940227378';
id | member_id | session | loc | created | updated | uuid
------+-----------+-------------------------------------------------------------------------------------------------+----------------+----------------------------+----------------------------+--------------------------------------
1317 | 48 | 50534367713329088500408985849250550352404565459882532533221349071826496812546205397231940227378 | 197.210.79.221 | 2023-03-02 08:29:48.075624 | 2023-03-02 08:29:48.075624 | 01d55db5-baff-4f7f-b9e1-266f655facb1
mermsemr_dev=> SELECT id, uuid FROM members limit 2;
id | uuid
----+--------------------------------------
16 | d274dcd9-7f5d-4919-b284-2a0cf137302e
5 | d59e61db-cc3f-4e80-9f0a-dff324f1a1a0
(2 rows)
mermsemr_dev=> SELECT id, uuid,password FROM members limit 2;
id | uuid | password
----+--------------------------------------+----------------------------------
16 | d274dcd9-7f5d-4919-b284-2a0cf137302e | 1adf598f793670bc7d1d83cbcbb70342
5 | d59e61db-cc3f-4e80-9f0a-dff324f1a1a0 | 1adf598f793670bc7d1d83cbcbb70342
(2 rows)
mermsemr_dev=>
*/
return [
'status' => '-1',
'error_msg' => 'Not implemented yet',
'raw_data' => $in,
];
}
}
/*
member_id' => string '16
' (length=3)
'session_token' => string '67367112985210631610322406189043063617397600780394987864623852303749094839082445465537892414487
' (length=96)
'member_uuid' => string 'd274dcd9-7f5d-4919-b284-2a0cf137302e' (length=36)
'sessionid' => string '67367112985210631610322406189043063617397600780394987864623852303749094839082445465537892414487
' (length=96)
'' => string 'previouspassword' (length=16)
*/
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class userStats extends baseModel
{
public function __construct()
{
parent::__construct();
}
public function homeStats($in){
$data = [];
return $inx = [
'stats' => $data,
'status' => 1,
'raw_data' => $in,
];
}
public function readLoginHx($in)
{
// $in['member_id'] = 16;
$member_id2 =
isset($in['member_id']) &&
$in['member_id'] > 0 &&
is_int($in['member_id'])
? $in['member_id']
: 0;
$member_id = isset($in["member_id"]) ? (int) $in["member_id"]: 0 ;
$member_id = 13;
$sqlQ =
'SELECT * FROM members_login_hx WHERE member_id=' .
$member_id .
' ORDER BY id DESC LIMIT 15';
log_message('critical', "readLoginHx=>".$sqlQ );
$query = $this->db->query($sqlQ);
$data['loginhx_data'] = $query->getResultArray();
return $inx = [
'loginhx' => $data['loginhx_data'],
'status' => 1,
'raw_data' => $in,
];
}
}
+76 -30
View File
@@ -11,25 +11,7 @@ class usersResetPass extends baseModel
{
parent::__construct();
}
/*
$res1 = [
'email' => $raw_array['email'],
'status' => 1,
];
CREATE TABLE members_pending (
id SERIAL,
uuid UUID DEFAULT (gen_random_uuid()),
username VARCHAR(50) NOT NULL,
firstname VARCHAR(50),
lastname VARCHAR(50),
email VARCHAR(50),
password VARCHAR(100) NOT NULL,
random_text VARCHAR(15),
status INT DEFAULT 0,
updated timestamp without time zone DEFAULT now(),
added timestamp without time zone DEFAULT now()
);
*/
public function resetPass($in)
{
$change_state = $in['stage'];
@@ -44,27 +26,91 @@ public function resetPass($in)
break;
case CONFIRM_PASS_CHANGE:
return $this->completePassReset($in);
break;
}
return ['error_mode'=>-1];
return
[
'error_mode'=>-1
];
}
private function verifyPassReset($in){
private function completePassReset($in){
$username = isset($inx['username'])?$inx['username']:'';
$reset_uuid = isset($inx['reset_uuid'])?$inx['usereset_uuidrname']:'';
$random_text = isset($inx['random_text'])?$inx['random_text']:'';
// $random_text = isset($inx['random_text'])?$inx['random_text']:'';
$status = -1;
$error_msg= '';
$msg = '';
$username = isset($in['username'])? $in['username']: '';
$reset_uuid = isset($in['reset_uuid'])? $in['reset_uuid']: '';
$random_text = isset($in['random_text'])?$in['random_text']:'';
$member_uid = isset($in['member_uid'])? $in['member_uid']: '';
$selectData=['*'];
$whereAray=[
'uuid'=>$reset_uuid ,
'username' =>$username,
'random_text'=>$random_text,
'member_uid'=> $member_uid
];
$first_check = $this->select_db($selectData,$whereAray, 'members_password_reset');
if ($first_check['status']> 0 && $first_check['record_count']> 0){
$status = 1;
$msg='Ready to reset password';
} else{
$error_msg ="Unable to continue";
$status = 0;
}
return $inx = [
'username' => '999999',
'reset_uuid' => '999999',
'uuid' => '00000',
'member_uid' => '00000',
'error_msg' => '',
'username' => $username,
'reset_uuid' => $reset_uuid ,
'member_uid' => $member_uid,
'status' => $status,
'msg' => $msg,
'error_msg' => $error_msg,
'raw_data' => $in,
];
/* return 0;*/
}
private function verifyPassReset($in){
$member_uid = '';
$error_msg='';
$status = -1;
$username = isset($in['username'])?$in['username']:'';
$reset_uuid = isset($in['reset_uuid'])?$in['reset_uuid']:'';
$random_text = isset($in['random_text'])?$in['random_text']:'';
// $random_text = isset($inx['random_text'])?$inx['random_text']:'';
$selectData=['*'];
$whereAray=[
'uuid'=>$reset_uuid ,
'username' =>$username,
'random_text'=>$random_text,
];
$first_check = $this->select_db($selectData,$whereAray, 'members_password_reset');
if ($first_check['status']> 0 && $first_check['record_count']> 0){
$member_uid = $first_check['result'][0]['member_uid'];
$status = 1;
}
else{
$error_msg ="Unable to continue";
$status = 0;
}
return $inx = [
'username' => $username,
'reset_uuid' => $reset_uuid ,
'member_uid' => $member_uid,
'status' => $status,
'error_msg' => $error_msg,
'raw_data' => $in,
];
}